2014-03-19 110 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