简体   繁体   中英

how to use rake tasks in capistrano 3 + rvm

I saw the following questions here:

question 1

question 2

question 3

However, none of these helped me.

How can I define the correct rake to use in tasks on capistrano while using rvm? The code is simple:

task :precompile_production_assets do
  on roles(:all) do |host|    
   execute("cd #{fetch(:deploy_to)}/current && rake -T")
  end
end

This command returns me:

DEBUG [bae8f8f7] Command: cd /home/rails/current && rake -T
DEBUG [bae8f8f7] bash: /usr/local/bin/rake: /usr/bin/ruby1.8: bad interpreter: No such file or directory

My setup and some gems are:

  • rvm current: ruby-2.2.0@project
  • rails 4.2.0
  • gem capistrano 3.3.5
  • gem capistrano-rvm 0.1.2
  • gem capistrano-bundler 1.1.3
  • gem capistrano-rails 1.1.2

It seems like rake is being called from a different place but I don't know how to fix it.

On deploy.rb I set up set :rvm_ruby_version, '2.2.0project' as told in https://github.com/capistrano/rvm/ and on my Capfile I commented out

require 'capistrano/rvm'
require 'capistrano/bundler'

Tries:

1 - The commands below:

execute("cd #{fetch(:deploy_to)}/current && rake -T")
execute("cd #{fetch(:deploy_to)}/current && bundle exec rake -T")

returns me :

DEBUG [bae8f8f7] bash: /usr/local/bin/rake: /usr/bin/ruby1.8: bad interpreter: No such file or directory

2 - The command below

execute(:rake, 'assets:precompile', 'RAILS_ENV=production')

returns me :

DEBUG [b4457b08] Command: /usr/local/rvm/bin/rvm 2.2.0@project do bundle exec rake assets:precompile RAILS_ENV=production
DEBUG [b4457b08] Could not locate Gemfile or .bundle/ directory

In this mode rake is ok but is being executed in another place and I want it on /home/rails/current. With this different syntax I don't know how to cd location && rake sometask

I wanted to post this as a comment, but I can only post as an answer due to my low reputation. Also, my formatting isn't applied for some reason.

in deploy.rb do you really have:

set :rvm_ruby_version, '2.2.0project'

Or did you type that wrong here and have it correct in deploy.rb as:

set :rvm_ruby_version, '2.2.0@project'

Without seeing the contents of your deploy.rb file or knowing your system configuration, I can only provide the following possible fixes:

  1. You should not comment out "capistrano/rvm". The documentation you linked to says to include that in deploy.rb.
  2. Your system ruby is set to 1.8, as you can see from the output of "try 1". You could change the system ruby (if this is the only app you're running on this machine) to 2.2.0 with your preferred gemset.
  3. If all else fails, you could always try:

     set :rvm_custom_path '~/your/ruby/path' 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM