开发者

Capistrano deploying to system wide RVM not seeing installed Rubies

开发者 https://www.devze.com 2023-03-26 04:50 出处:网络
I\'m using a system wide Ruby install on my server, and trying to deploy to a RVM gemset (like rvm use 1.9.2@gemset_name)

I'm using a system wide Ruby install on my server, and trying to deploy to a RVM gemset (like rvm use 1.9.2@gemset_name)

When I run my Cap file, Cap pukes and says a Ruby is not installed.

However, in reality that Ruby is installed. (The deploying user is part of the rvm group and can rvm use on the command line manually.)

What might I be doing wrong?

Relevant parts of Capfile

$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load path.

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

set(:rvm_type)          { :system }
set(:ruby_version)      { '1.9.2' }
set(:rvm_ruby_string)   { "#{ruby_version}@#{application}" }
set(:rvm_path)         开发者_运维百科 { "/usr/local/rvm" }
#set(:rvm_bin_path)      { "#{rvm_path}/bin" }

before "deploy:setup",    "rvm:debug_gemset"
before "deploy:setup",    "bundle:install_gem"

namespace :rvm do
  desc "Creates gemset for application"
  task :debug_gemset do
    disable_rvm_shell do
      run "/usr/local/rvm/bin/rvm list rubies" do |ch, stream, data|
        if stream == :err
          logger.debug "capured output on STDERR: #{data}"
        else # stream == :out
          logger.debug "capured output on STDOUT: #{data}"
        end
      end
    end    
  end
end

# We need this so that we can install rvm first!
def disable_rvm_shell(&block)
  default_shell = self[:default_shell]
  self[:default_shell] = nil
  yield
  self[:default_shell] = default_shell
end

Cap output

* executing `deploy:setup'
  triggering before callbacks for `deploy:setup'
* executing `rvm:debug_gemset'
* executing "/usr/local/rvm/bin/rvm list rubies"  # <----- ran outside of rvm-shell
  servers: ["XX.XXX.XXX.XXX"]
Password: 
  [XX.XXX.XXX.XXX] executing command
* capured output on STDOUT:
* capured output on STDOUT: rvm rubies
* capured output on STDOUT:
* ruby-1.8.7-p352 [ x86_64 ]
* capured output on STDOUT:
* ree-1.8.7-2011.03 [ x86_64 ]
* capured output on STDOUT:
* ruby-1.9.2-p290 [ x86_64 ]
* 

Ok, awesome: 1.9.2 is installed. (This is to be expected - I installed 1.8.7, REE and 1.9.2 manually!)

But that's not all Capistrano says...

    command finished
  * executing `bundle:install_gem'
  * executing "gem install bundler"
    servers: ["XX.XXX.XXX.XXX"]
    [XX.XXX.XXX.XXX] executing command
 ** [out ::XX.XXX.XXX.XXX] WARN: ruby ruby-1.9.2-p290 is not installed.

That last line claims that 1.9.2 not installed?!!

 ** [out ::XX.XXX.XXX.XXX] To install do: 'rvm install ruby-1.9.2-p290'
*** [err ::XX.XXX.XXX.XXX] ERROR: Gemset 'MY_APP' does not exist, rvm gemset create 'MY_APP' first.
*** [err ::XX.XXX.XXX.XXX] Error: RVM was unable to use '1.9.2@MY_APP'
    command finished
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell '1.9.2@MY_APP' -c 'gem install bundler'" on XX.XXX.XXX.XXX

Debugging with cap shell

Jim Gay asks, "what about debugging with cap shell?"

rvm/capinstrano runs commands through rvm-shell, which immediately goes looking for the version and gemset essentially before the command can be executed. (Thus the disable_rvm_shell defined earlier that we used for doing the initial rvm list rubies.

For example:

cap> which rvm
[establishing connection(s) to XX.XXX.XXX.XX]
Password: 
** [out :: XX.XXX.XXX.XX] WARN: ruby ruby-1.9.2-p290 is not installed.
** [out :: XX.XXX.XXX.XX] To install do: 'rvm install ruby-1.9.2-p290'
*** [err :: XX.XXX.XXX.XX] ERROR: Gemset 'MY_APP' does not exist, rvm gemset create 'MY_APP' first.
*** [err :: XX.XXX.XXX.XX] Error: RVM was unable to use '1.9.2@MY_APP'
error: failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell '1.9.2@MY_APP' -c 'which rvm'" on XX.XXX.XXX.XX

Conclusion

I'm obviously doing something wrong, but what?

Setting 1.9.2 to be the default Ruby is not an option, as I'm also going to host a 1.8.7 app on this box (ideally). This is why I'm using RVM at the system level to begin with).

I also made sure that the deploy user is in the RVM group, per the RVM documentation.


This WARN about not installed ruby is a misleading msg, it should say could not find ruby@gemset pair. If you would use this command on server:

rvm use 1.9.2@MY_APP

You would see the messages in reverse order - first error that the gemset can not be found, to solve it please go to server and run:

rvm --create use 1.9.2@MY_APP

Which will create a gemset for you, if you need any more help with it please contact IRC channel #rvm on FreeNode servers.


ok, so i just had this bomb with a patch version of ruby different. server was running: ruby-1.8.7-p371 and the deploy (cap / rvm-capistrano, not sure which exactly) wanted rvm install ruby-1.8.7-p374.

I tried the gemset suggestion in @mpapis which was progress, but it was then that i noticed it asked me to p374.

so if in doubt, install the latest minor version of ruby.

0

精彩评论

暂无评论...
验证码 换一张
取 消