Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Use the default_env normally supplied to sshkit #3

Merged
merged 3 commits into from
Dec 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 6 additions & 27 deletions lib/capistrano/rails/console/tasks/remote.cap
Original file line number Diff line number Diff line change
@@ -1,34 +1,13 @@
def rvm_loaded?
Gem::Specification::find_all_by_name('capistrano-rvm').any?
end

def rbenv_loaded?
Gem::Specification::find_all_by_name('capistrano-rbenv').any?
end

def bundler_loaded?
Gem::Specification::find_all_by_name('capistrano-bundler').any?
end

namespace :rails do

desc 'Access a remote rails console'
desc "Interact with a remote rails console"
task console: ['deploy:set_rails_env'] do
app_server = roles(:app).first

# RVM support
if rvm_loaded?
Rake::Task['rvm:hook'].invoke
set :rvm_map_bins, ((fetch(:rvm_map_bins) || []) + ['rails'])
on primary :app do |host|
ssh_cmd = "ssh #{host.netssh_options[:user]}@#{host.hostname} -p #{host.port || 22}"
cmd = SSHKit::Command.new(:rails, "console #{fetch :rails_env}")
SSHKit.config.output << cmd
exec %Q(#{ssh_cmd} -t "cd #{current_path} && (#{cmd.environment_string} #{cmd})")
end

command = []
command << "#{fetch(:rvm_path)}/bin/rvm #{fetch(:rvm_ruby_version)} do" if rvm_loaded?
command << "#{ fetch :rbenv_prefix } " if rbenv_loaded?
command << "bundle exec" if bundler_loaded?
command << "rails console #{fetch(:rails_env)}"

exec %Q(ssh #{app_server.netssh_options[:user]}@#{app_server.hostname} -p #{app_server.port || 22} -t "cd #{current_path} && #{command.join(' ')}")
end

end
2 changes: 1 addition & 1 deletion lib/capistrano/rails/console/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Rails
# Console
module Console
# gem version
VERSION = '0.2.0'
VERSION = '0.3.0'
end
end
end