2014-03-19 32 views
4

的Gemfile:如何让Capistrano 3使用RVM红宝石?

gem 'capistrano', '~> 3.0.0' 
gem 'capistrano-rails' 
gem 'capistrano-bundler' 
gem 'capistrano-rvm' 
gem 'capistrano3-puma' 

Deploy.rb:

​​

Production.rb

namespace :rails do 
    desc "Open the rails console on primary app server" 
    task :console do 
    on roles(:app), primary: true do 
     execute_interactively "#{current_path}/script/rails console RAILS_ENV=production" 
    end 
    end 

    def execute_interactively(command) 
    cmd = "ssh -l deploy 255.255.255.255 -p 21 -t 'cd #{deploy_to}/current && #{command}'" 
    info "Connecting to 255.255.255.255" 
    exec cmd 
    end 
end 

Capfile:

require 'capistrano/setup' 
require 'capistrano/deploy' 
require 'capistrano/rvm' 
require 'capistrano/bundler' 
require 'capistrano/rails/assets' 
require 'capistrano/rails/migrations' 
require 'capistrano/puma' 
require 'whenever/capistrano' 
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r } 

当我运行cap production rvm:check输出为:

rvm 1.25.19 (master) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/] 
system 
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux] 

如果它不使用user代替system因为我指定的rvm_type

当我运行cap production rails:console然后我得到:

INFO Connecting to 255.255.255.255 
/usr/bin/env: ruby: No such file or directory 
Connection to 255.255.255.255 closed. 

回答

9

我不认为你了解如何Capistrano的-RVM作品。

Here's the relevant code

Capistrano的-RVM的工作原理是搞清楚你的​​RVM安装的位置,然后与相关mapped commands前缀您Capistrano的命令。该命令映射是SSHKit的一部分。

Capistrano-rvm默认将gem rake ruby bundle映射到rvm前缀版本。这意味着每当capistrano遇到命令时,例如以execute :bundle的形式,它将用例如~/.rvm/bin/rvm 2.1.1 do bundle

您已完全侧重于您设计的execute_interactively命令中的整个机制,该命令指定内联命令。事实上,通过设置您自己的SSH会话,您完全可以将整个卡皮斯特拉诺的美丽完美展现出来!

此外整个set :default_env, { rvm_bin_path: '~/.rvm/bin' }根本不需要,这就是您使用capistrano-rvm gem的原因。


至于为什么cap production rvm:check正在显示system是因为这个词system在这种情况下,过载。什么认为这意味着在这方面是“什么样的RVM设置方案是这样的,一个/usr/local/rvm安装或~/.rvm安装”

这实际意味着从this code,也就是说,它会检查在列出的红宝石版本RVM作为当前红宝石,其中红宝石的服务器上的默认安装是被称为系统红宝石

+0

谢谢,这个回答让我去调查CAP3多一点。我已经到了我的命令都工作的地步,但控制台切换到检查模式(https://gist.github.com/pawel2105/9706550) – Simpleton

+0

“相关代码”是一个救星! 如果您将安装RVM的路径放在您自己的位置而不是默认位置,您可以通过将其放置在您的deploy.rb文件中来告诉rvm capistrano插件:'set:rvm_custom_path',/ my/custom/path /到/ rvm'' – Del