Deployment of Rails 3 App using Bundler and Capistrano
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.
When should I invoke the
sudo bundle install
command in the deployment process - i mean after which capistrano task ?For running
sudo
commands using capistrano, what declarations I should specify i开发者_如何学编程n my cap file ? Note - i already have pushed my public key as authorized keys in my server.How should the bundle install hook be written in the
cap
file ?
Please help.
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?
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.
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.
精彩评论