Bundle install error when deploying via capistrano

2019-09-06 14:55发布

问题:

Now I must admit that I'm stumbling around in the dark a little bit as far as this deployment lark is concerned. I'll try and explain the situation best I can; I have set up a test deployment server and am trying to deploy my app to it with capistrano, however, I am encountering some difficulties surrounding my gems and their dependencies, as the error below shoes.

[mike-test] executing command
[mike-test] rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.3' -c 'cd /home/deploy/myapp/releases/20120910081544 && bundle install --gemfile /home/deploy/myapp/releases/20120910081544/Gemfile --path /home/depoy/myapp/shared/bundle --deployment --quiet --without development test'
 ** [out :: mike-test] Some gems seem to be missing from your vendor/cache directory.
 ** [out :: mike-test] Could not find log4r-1.1.10 in any of the sources
command finished in 9134ms
*** [deploy:update_code] rolling back

log4r isn't in my gemfile so I can only assume it's a (perhaps production only?) dependency of another gem. I don't know why bundler isn't downloading the gem and installing it if it can't find it? I put the gem in my gemfile, ran bundle install locally, and then committed and deployed again and got the same error but with a different gem this time (spreadsheet), so that appeared to solve the error in that case only, but doesn't identify the problem.

Something else to muddy the water, I'm trying to use RVM on the production server and despite reading a lot about it I'm still not 100% sure I get how it works, so that might be a factor.

My deploy.rb:

require "bundler/capistrano"
require "rvm/capistrano"

# SCM Settings
set :rvm_ruby_string, '1.9.3' 
set :use_sudo, false

ssh_options[:forward_agent] = true
default_run_options[:pty] = true

set :branch, :mikedev
set :deploy_via, :remote_cache
set :copy_cache, true
set :git_enable_submodules, 0
set :repository, "our_git_repo.git"
set :scm, :git
set :user, :deploy
set :keep_releases, 1

set :application, "myapp"
set :deploy_to, "/home/deploy/myapp"
set :branch, "mikedev"

role :web, "mike-test"                          
role :app, "mike-test"                          
role :db,  "mike-test", :primary => true      

namespace :deploy do

  desc "Restarting mod_rails with restart.txt"
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "touch #{current_path}/tmp/restart.txt"
  end

  [:start, :stop].each do |t|
    desc "#{t} task is a no-op with mod_rails"
    task t, :roles => :app do ; end
  end

end

Any guidance would be much appreciated.

回答1:

bundle install --deployment ... will not download any gems if vendor/cache is present. It'll look for gems just there. There are two options:

  • remove vendor/cache directory (even if it's already empty) from your VCS
  • or run bundle package and add all new files under vendor/cache to your VCS

The latter seems to be better option. In this way you protect your deployment from outages of rubygems servers.