Jaap Haagmans The all-round IT guy

2Feb/110

How to update your bundle after every deploy

Rails 3 depends on Bundler for its gem management. It's a blessing for everyone on shared hosting plans, because gems don't need to be installed by the server administrator anymore. You can simply include them into your bundle, by adding them to your Gemfile. However, if you use Capistrano and you decide to add a new gem to your app, you will need to run the following command from your app root:

bundle install

The beauty of using Capistrano is that you can automate almost anything using your deploy script. Where in Rails 2, you might have used Capistrano to run a rake task to install gems, in Rails 3 you can do the same using Bundler. The following code did it for me:

1
2
3
4
5
6
7
8
9
10
after "deploy:update_code", "deploy:bundle_install"
 
namespace :deploy do
 
  desc "update your bundle"
  task :bundle_install, :roles => :app do
    run "cd #{release_path} && /opt/ruby/bin/bundle install --deployment --path ~/.bundler"
  end
 
end

The reason I specifically tell Bundler to keep the bundle in the home directory is that this way your bundle will properly work across all your releases. You might want to change the path to the bundle executable though.

Do note that, if you have included a new gem, your deploy will take significantly more time to finish from now. Though if the bundle hasn't changed, it will be updated in nearly no time at all.