Deploying a bundled merb app (merb 0.9.7+)

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 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.

Similar Posts

, , , , ,

  1. #1 by Peter - September 23rd, 2008 at 16:14

    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?

  2. #2 by Matt Aimonetti - September 23rd, 2008 at 16:36

    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 > merb.thor

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


  3. #3 by admin - September 23rd, 2008 at 17:01

    @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.


  4. #4 by Botanicus - September 24th, 2008 at 01:47

    Matt, thank for your cap recipe, very useful!

  5. #5 by Gabriel Wilkins - September 24th, 2008 at 07:31

    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’
    require ‘rubygems’
    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.

  6. #6 by Sander van Zoest - September 24th, 2008 at 11:31

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

  7. #7 by Mike - September 24th, 2008 at 13:19

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

  8. #8 by Michael Klishin - September 24th, 2008 at 23:18

    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.

  1. No trackbacks yet.

Comments are closed.