Capistrano Migrations Deploy

2019-04-14 09:05发布

问题:

I have a question about Ruby on Rails and Capistrano deploys. The first thing I do is deploy my Rails App using:

cap deploy:update

When I have migration, I try to run the Capistrano command:

cap deploy:migrations

I get the error:

Could not find rake-0.9.2 in any of the sources

I have to SSH into the current folder of the server and manually run

rake RAILS_ENV=production db:migrate

Which is obviously a huge pain to run every deploy with a migration.

What am I doing wrong? Thanks for the help.

回答1:

You might need to uncomment and adjust the following lines in your config/deploy.rb:

# default_environment['PATH']='<your paths>:/usr/local/bin:/usr/bin:/bin'
# default_environment['GEM_PATH']='<your paths>:/usr/lib/ruby/gems/1.8'

Additionally, if you are using RVM, you might need to add a few lines:

# adjust if you are using RVM, remove if you are not
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
set :rvm_ruby_string, '1.9.2'
set :rvm_type, :user


回答2:

it sounds like the deploy:migrations task isn't getting the right bash environment. Can you see the full command that's being run on the server? Is it using sudo? Is it using bundler? Get the whole command and try running that from your SSH session.



回答3:

you have a newer version of rake gem on local, but the remote server has the older one which works correctly with Rails version you use.

Can you check it with "gem list |grep rake" local and remotely. you can specify rake gem version in your Gemfile and redeploy the application

#Gemfile
gem 'rake',  '0.8.7' # or '0.9.2'


回答4:

To pull in the Bundler Cap task, just add this to your deploy.rb file:

require "bundler/capistrano"

Running cap deploy will now automatically run bundle install on the remote server with deployment-friendly options, and rake will be available for the following steps of the deployment.

A list of options that can be changed is available in the help for the cap task. To see it, run cap -e bundle:install.