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 <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]
system
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
Should it not be using user
instead of system
because I've specified the rvm_type
?
When I run cap production rails:console
then 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.
I don't think you understand how capistrano-rvm works.
Here's the relevant code
capistrano-rvm works by figuring out the location of your RVM installation, and then prefixing your capistrano commands with the relevant mapped commands. The command-map is part of SSHKit.
Capistrano-rvm by default maps gem rake ruby bundle to an rvm-prefixed version. What this means is that whenever capistrano encounters a command, e.g. in the form of execute :bundle
it will replace it with, e.g. ~/.rvm/bin/rvm 2.1.1 do bundle
You've completely side-stepped that entire mechanism in your contrived execute_interactively
command that specifies the command in-line. In fact, you've completely side-stepped the beauty of capistrano as a whole by setting up your own SSH session!
Also the whole set :default_env, { rvm_bin_path: '~/.rvm/bin' }
is not at all needed, that's the reason you're using the capistrano-rvm gem.
As for why cap production rvm:check
is displaying system
is because the term system
is overloaded in this case. What you think it means in this context is "what kind of rvm setup scheme is this, a /usr/local/rvm
installation or a ~/.rvm
installation"
What it actually means is from this code, i.e. it checks the ruby version that's listed in RVM as the current ruby, which the default installation of ruby on a server is known as the system ruby
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With