4
votes

During capistrano deployment of a Rails3 app, I want my server to install gems, using Gemfile.lock, every time I deploy. And since my server does not have rvm and all.. All gems should be installed as system gems.

To install system gems, we need to put sudo gem install anygem or for bunder, we need to give command sudo bundle install inside our current directory of capistrano deployment structure.

Everytime, I deploy, my deployment breaks at the gems installation process. I need sudo bundle install to run. For that, I need a deployment hook for capistrano. The prebuilt ones that are supplied by bundler gem itself is not working for me. My confusion boils down to these three questions.

  1. When should I invoke the sudo bundle install command in the deployment process - i mean after which capistrano task ?

  2. For running sudo commands using capistrano, what declarations I should specify in my cap file ? Note - i already have pushed my public key as authorized keys in my server.

  3. How should the bundle install hook be written in the cap file ?

Please help.

3
strongly recommend you use rvm in production, it removes all the sudo messSam Saffron
@SamSaffron, with gems - yes. But if you use god, you're back to sudo mess. :-)Sergio Tulentsev

3 Answers

5
votes

Adding require "bundler/capistrano" to your deploy.rb should just work. It should declare a folder to install gems to that do not require sudo access, regardless of rvm.

Is that still failing for you?

2
votes

If you run bundle install --deployment you shouldn't need sudo access as the gems should be installed to vendor/bundle in your app rather than to the system itself.

0
votes

i use that in my deploy.rb:

require "bundler/capistrano"
... deploy recipe

namespace :bundle do
  desc "Install bundles into application"
  task :install, :roles => [:app] do
    run "cd #{current_path} && LC_ALL='en_US.UTF-8' bundle install --deployment --without test"
  end
end

Then after normal deploy i run "cap bundle:install"

note: Using UTF-8 to prevent ruby1.9 ASCII chars problems.