The Merbist

Merb & Rails 3 news - consulting - training

Deploying a bundled merb app (merb 0.9.7+)

Posted on September - 23 - 2008

Since Merb 0.9.7 the Merb team decided to change the way you can bundle an app. Until 0.9.7 you would use the merb-freezer plugin which was supporting git submodules and gems. The only problem was that you still had to install merb-freezer on your server and it had to stay in sync with your app… kinda lame :(

Ginger

Ginger roots, great for deployment issues

Instead, after a lot of discussions, we decided to add this feature to merb-core and let you bundle all your dependencies in a bundled gem folder. No more support for git submodules as they are hard to keep track of and don’t handle dependencies very well (not at all).

The new freezing strategy is very well described in this merbunity article. However it doesn’t really explain how to deploy a bundled app.

So let’s imagine for a second that we bundle our app, generated the scripts needed to start merb/rake etc…

The key thing to do is to have a decent deployment recipe. Let’s look at my cap recipe:

As you can see there are few key elements:

  • recompile native gems for the web server
  • call bin/merb and not merb directly

One thing you need to be aware of is that your bundled gems need to be up to date and play well alone. When you test your bundled app locally, you might endup loading system wide gems available which you don’t have on your deployment server.

If when you deploy your app everything seems fine but you can’t access your app, check that you are recompiling native gems during your deployment and make sure you have bundled all the deps you need and that they work well alone.

One more advise, if you can’t figure out what’s going, try ssh’ing to your server, go to your current folder and try bin/merb -i  to see what’s going on.

Bookmark and Share

8 Responses

  1. Peter Said,

    Nice one Matt!! I just need this recipe to deploy my first Merb app too ;)

    Can’t you symlink your gems folder also so you don’t need transfer it in every deploy?

    Posted on September 23rd, 2008 at 4:14 pm

  2. Matt Aimonetti Said,

    Some people told me on IRC that they did not have the merb:gems:redeploy thor task. Make sure to update your local thor file:

    curl -L http://merbivore.com/merb.thor > merb.thor

    and don’t forget to add it to your SCM ;)

    -Matt

    Posted on September 23rd, 2008 at 4:36 pm

  3. admin Said,

    @peter Why would you want to symlink your gems folder?
    If you don’t want to have them bundled just install them system-wide.
    Otherwise you will have to always go to your gems folder and update it manually (which you can certainly do).

    Btw, if you use a cached deployment strategy like used in my recipe, your gems won’t be transferred every time.

    -Matt

    Posted on September 23rd, 2008 at 5:01 pm

  4. Botanicus Said,

    Matt, thank for your cap recipe, very useful!

    Posted on September 24th, 2008 at 1:47 am

  5. Gabriel Wilkins Said,

    we’ve been using a one-line hack since 093 to freeze gems, which also excludes the gems system path. if it ain’t in the app gems dir, merb can’t see it.
    just change
    require ‘rubygems’
    to
    require ‘rubygems’
    Gem.use_paths(”.”,[File.expand_path("#{File.dirname(__FILE__)}/..")]).pop
    in #{root}/gems/bin/merb
    and install your gems with
    gem install -i #{root}/gems #–no-rdoc –no-ri, if you’re so inclined
    and then of course, have to call merb as bin/merb

    working is subject to rubygems not changing that, or you having already changed it somewhere else, but it’s worked for me without a hitch on many different machines, linux & win32.

    so i’m sure that modifying this to exclude the system path properly wouldn’t be that hard.

    Posted on September 24th, 2008 at 7:31 am

  6. Sander van Zoest Said,

    Now it would be really great if we can integrate all this stuff with puppet.

    Posted on September 24th, 2008 at 11:31 am

  7. Mike Said,

    @Matt, I must be missing something. How exactly do you update without having to transfer the gems every time?

    Posted on September 24th, 2008 at 1:19 pm

  8. Michael Klishin Said,

    By the way, Merb 1.1 or so is gonna have a deployment recipe plugin. I’ve used 2 recipes in the wild with both ActiveRecord and DataMapper migration tasks, so we just need to add one for Sequel and document the whole thing.

    Turn key deployment is part of post 1.0 Merb picture: flexible tool with lots of plugins for very rapid prototyping.

    Posted on September 24th, 2008 at 11:18 pm

Add A Comment