forked from ydkn/capistrano-rails-console
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding support for keys set in ssh_options
- Loading branch information
1 parent
a65a469
commit 0f9d7bb
Showing
1 changed file
with
29 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |