加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何让Capistrano 3使用RVM ruby???

发布时间:2020-12-17 03:48:58 所属栏目:百科 来源:网络整理
导读:的Gemfile: gem 'capistrano','~ 3.0.0'gem 'capistrano-rails'gem 'capistrano-bundler'gem 'capistrano-rvm'gem 'capistrano3-puma' Deploy.rb: set :rvm_type,:userset :rvm_ruby_version,'2.1.1'set :default_env,{ rvm_bin_path: '~/.rvm/bin' } Prod
的Gemfile:

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

Deploy.rb:

set :rvm_type,:user
set :rvm_ruby_version,'2.1.1'
set :default_env,{ rvm_bin_path: '~/.rvm/bin' }

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生产rvm:检查输出是:

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

它是否应该使用用户而不是系统,因为我已经指定了rvm_type?

当我运行cap生产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.

解决方法

我不认为您了解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做捆绑

你已经在你设计的execute_interactively命令中完全支持整个机制,该命令用于指定内联命令.事实上,通过建立自己的SSH会话,你已经完全支持了整个capistrano的美丽!

整个集合:default_env,{rvm_bin_path:’?/ .rvm / bin’}根本不需要,这就是你使用capistrano-rvm gem的原因.

至于为什么cap生产rvm:check是显示系统是因为在这种情况下术语系统过载.您认为在这种情况下意味着“这是什么样的rvm设置方案,/usr/local/rvm安装或?/ .rvm安装”

它的实际含义是从this code开始,即它将RVM中列出的ruby版本检查为当前的ruby,服务器上默认安装的ruby称为系统ruby

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读