Skip to content

Commit

Permalink
adding support for keys set in ssh_options
Browse files Browse the repository at this point in the history
  • Loading branch information
tyraeltong committed May 22, 2015
1 parent a65a469 commit 0f9d7bb
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions lib/capistrano/rails/console/tasks/remote.cap
@@ -1,37 +1,42 @@
namespace :load do
task :defaults do
# add rails to rvm_map_bins
set :rvm_map_bins, fetch(:rvm_map_bins, []).push(:rails)
end
task :defaults do
# add rails to rvm_map_bins
set :rvm_map_bins, fetch(:rvm_map_bins, []).push(:rails)
end
end

namespace :rails do
desc "Interact with a remote rails console"
task :console do
on primary :app do |host|
test(:true) # initialize ssh_options on host
desc "Interact with a remote rails console"
task :console do
on primary :app do |host|
test(:true) # initialize ssh_options on host

ssh_cmd_args = []
rails_console_args = []
ssh_cmd_args = []
rails_console_args = []

if host.ssh_options && host.ssh_options[:proxy]
template = host.ssh_options[:proxy].command_line_template
ssh_cmd_args << "-o ProxyCommand=\"#{template}\""
end
if host.ssh_options && host.ssh_options[:proxy]
template = host.ssh_options[:proxy].command_line_template
ssh_cmd_args << "-o ProxyCommand=\"#{template}\""
end

rails_console_args << '--sandbox' if ENV.key?('sandbox') || ENV.key?('s')
rails_console_args << '--sandbox' if ENV.key?('sandbox') || ENV.key?('s')

rails_env = fetch(:rails_env, fetch(:stage, 'production'))
rails_env = fetch(:rails_env, fetch(:stage, 'production'))

cmd = SSHKit::Command.new(:rails, :console, rails_env, *rails_console_args, host: host)
SSHKit.config.output << cmd
cmd = SSHKit::Command.new(:rails, :console, rails_env, *rails_console_args, host: host)
SSHKit.config.output << cmd

port = host.port || (host.ssh_options || {})[:port]
ssh_cmd_args << "-p #{port}" if port
port = host.port || (host.ssh_options || {})[:port]
ssh_cmd_args << "-p #{port}" if port

ssh_cmd_args << [host.user, host.hostname].compact.join('@')
ssh_cmd_args << [host.user, host.hostname].compact.join('@')

exec(%Q(ssh #{ssh_cmd_args.join(' ')} -t "cd #{current_path} && (#{cmd.environment_string} #{cmd})"))
end
end
if hosts.ssh_options && hosts.ssh_options[:keys]
identity = hosts.ssh_options[:keys][0]
ssh_cmd_args << "-i #{identity}"
end

exec(%Q(ssh #{ssh_cmd_args.join(' ')} -t "cd #{current_path} && (#{cmd.environment_string} #{cmd})"))
end
end
end

0 comments on commit 0f9d7bb

Please sign in to comment.