How to get Capistrano 3 to use RVM ruby?

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 }

When I run cap production rvm:check, the output is:

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]

If he does not use userinstead system, because I indicated rvm_type?

When I run cap production rails:console, I get:

INFO Connecting to 255.255.255.255
/usr/bin/env: ruby: No such file or directory
Connection to 255.255.255.255 closed.
+4
source share
1 answer

I don’t think you understand how capistrano-rvm works.

Here is the corresponding code

capistrano-rvm works by finding out the location of your RVM installation, and then prefixing your capistrano commands with the appropriate displayed commands. The command card is part of SSHKit.

Capistrano-rvm gem rake ruby ​​bundle rvm. , , capistrano , . execute :bundle , . ~/.rvm/bin/rvm 2.1.1 do bundle

execute_interactively, . , capistrano , SSH!

set :default_env, { rvm_bin_path: '~/.rvm/bin' }, , capistrano-rvm.


, cap production rvm:check system, , system . , , , : " rvm - /usr/local/rvm ~/.rvm"

, , RVM, , ruby ​​

+9

Source: https://habr.com/ru/post/1532467/


All Articles