Deploying gems using Capistrano

Thought I’d share this because I had a lot of trouble figuring out how and where to run the “rake gems:install” when deploying with Capistrano. I wanted it to automatically deploy the gems when I call “cap deploy:migrations” – this is done by installing the gems right after update_code, like this:

# config/deploy.rb
after "deploy:update_code", "gems:install"

namespace :gems do
  desc "Install gems"
  task :install, :roles => :app do
    run "cd #{current_release} && #{sudo} rake gems:install"
  end
end

Some of the examples I’ve seen use “cd #{current_path}” but I don’t think this would work as the “current” symlink hasn’t been updated at the time the “update_code” task is run. That’s why I use “current_release”.

Also others use “rake RAILS_ENV=production gems:install” but I can’t see why you should have to use RAILS_ENV here. If I’m wrong, please correct me.

Some of the links I found when trying to get this to work:

Andre indlæg:

Tags: , , ,

6 comments

  1. Hey mate, thanks for posting this – it was the only snippet I could find for installing gems that actually works!

    Cheers

  2. FYI – I just implemented this, and I inserted RAILS_ENV=production into mine, simply because I have gems that are used on my deployment machines that I do not want installed in my production machines (ie ruby-debug). I only have those gems required in my production environment.

  3. @Justin: Thanks for telling – could be useful for others too.

  4. Worked perfectly first try. Thank you so much!

  5. @Tommy: Nice – good thing you could use it :-)

  6. my favorite gemstone is none other than diamond. the most expensive and priceless gemstone ever.`.,

Leave a comment


Fork me on GitHub