Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Automating Bundler In Your Deploy

Chad Woolley
Thursday, March 25, 2010

If you are using Bundler to lock and package your gem dependencies in your app (which you should), here’s some tips on making everything automatic in your Capistrano deploy.

Refer to the Bundler Documentation for instructions on how to use Bundler to properly package your gems and check everything in.

Once this is done, however, you still must ensure that two things are done on every machine to which you will deploy:

  1. Bundler is installed
  2. You run ‘bundle install’ on every deploy to install the packaged gems on the local machine (and compile any gems with native dependencies)

Here’s the Capistrano magic to accomplish these two tasks automatically on every deploy:

before "deploy:bundle_install", "deploy:install_bundler"
after "deploy:update_code", "deploy:bundle_install"

namespace :deploy do
  desc "installs Bundler if it is not already installed"
  task :install_bundler, :roles => :app do
    sudo "sh -c 'if [ -z `which bundle` ]; then echo Installing Bundler; sudo gem install bundler; fi'"
  end

  desc "run 'bundle install' to install Bundler's packaged gems for the current deploy"
  task :bundle_install, :roles => :app do
    run "cd #{release_path} && bundle install"
  end
end

Oh, and for you GemInstaller users out there – here’s an easy way to generate a Bundler Gemfile from your geminstaller.yml config:

geminstaller --bundler-export > Gemfile

You’ll probably still need some tweaks, but this will get you started. Just make sure you upgrade to GemInstaller 0.5.5 first (0.5.4 forgot to put the ‘source’ line in the Gemfile).

Happy Bundling!
– Chad

P.S. There is a similar article here, which includes tasks to symlink your .bundle dir into the Capistrano shared directory, but my deploy was pretty fast anyway, so I didn’t worry about it. YMMV.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

2 Comments

  1. szimek says:

    It’s probably better to run “bundle install” after deploy:update_code using
    run “cd #{release_path} && bundle install”

    If you deploy using “deploy:migrations”, it runs “deploy:migrate” task before running “deploy:symlink”, so it will try to run “rake db:migrate” first and then “bundle install”. This can cause problems if you want to run migrations and deploy modified Gemfile at the same time.

    March 27, 2010 at 4:53 am

  2. Chad Woolley says:

    @szimek,

    Thanks for the tips. I’ve tested it and updated the article.

    March 27, 2010 at 2:20 pm

Add New Comment Cancel reply

Your email address will not be published.

Chad Woolley

Chad Woolley
Denver

Recent Posts

  • [ANN] GemInstaller 0.5.3 Released
  • The Great Ruby IDE Smackdown of '09
  • "open_gem" Gem Plugin
Subscribe to Chad's Feed

Author Topics

bundler (1)
geminstaller (2)
open source (5)
rubygems (4)
ide (1)
ruby on rails (5)
gogaruco (19)
government (1)
agile (18)
pivotaltracker (1)
testing (2)
mac (2)
remote (1)
rant (1)
mtnwestrubyconf (1)
dependency injection (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >