mirror of
https://gitlab.com/ydkn/capistrano-rails-console.git
synced 2023-02-13 20:54:14 -05:00
use capistrano-interactive for connection stuff
This commit is contained in:
parent
6b4017c60b
commit
3debb2fc57
5 changed files with 20 additions and 45 deletions
|
@ -1,6 +1,10 @@
|
||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
## 1.0.0 (2015-11-12)
|
## Unreleased
|
||||||
|
### Changed
|
||||||
|
- switched connection part to _capistrano-interactive_
|
||||||
|
|
||||||
|
## 1.0.1 (2015-11-12)
|
||||||
### Fixed
|
### Fixed
|
||||||
- setting ssh hostname through `ssh_options`
|
- setting ssh hostname through `ssh_options`
|
||||||
- use login shell
|
- use login shell
|
||||||
|
|
|
@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
||||||
spec.require_paths = ['lib']
|
spec.require_paths = ['lib']
|
||||||
|
|
||||||
spec.add_dependency 'capistrano', '>= 3.1.0', '< 4.0.0'
|
spec.add_dependency 'capistrano', '>= 3.1.0', '< 4.0.0'
|
||||||
|
spec.add_dependency 'capistrano-interactive', '~> 0.2.0'
|
||||||
|
|
||||||
spec.add_development_dependency 'bundler'
|
spec.add_development_dependency 'bundler'
|
||||||
spec.add_development_dependency 'rake'
|
spec.add_development_dependency 'rake'
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
|
require 'capistrano/interactive'
|
||||||
|
|
||||||
load File.expand_path('../tasks/remote.cap', __FILE__)
|
load File.expand_path('../tasks/remote.cap', __FILE__)
|
||||||
|
|
|
@ -1,55 +1,23 @@
|
||||||
namespace :load do
|
namespace :load do
|
||||||
task :defaults do
|
task :defaults do
|
||||||
# add rails to rvm_map_bins
|
# Add rails to rvm_map_bins
|
||||||
set :rvm_map_bins, fetch(:rvm_map_bins, []).push(:rails)
|
set :rvm_map_bins, fetch(:rvm_map_bins, []).push(:rails)
|
||||||
|
|
||||||
|
# Default values
|
||||||
|
set :console_env, -> { fetch(:rails_env, fetch(:stage, 'production')) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :rails do
|
namespace :rails do
|
||||||
desc 'Interact with a remote rails console'
|
desc 'Interact with a remote rails console'
|
||||||
task :console do
|
task :console do
|
||||||
on primary :app do |host|
|
args = []
|
||||||
test(:true) # initialize ssh_options on host
|
args << '--sandbox' if ENV.key?('sandbox') || ENV.key?('s')
|
||||||
|
|
||||||
ssh_cmd_args = []
|
on primary(:app) do
|
||||||
rails_console_args = []
|
within current_path do
|
||||||
|
interact(:rails, :console, fetch(:console_env), *args)
|
||||||
if host.ssh_options && host.ssh_options[:proxy]
|
end
|
||||||
template = host.ssh_options[:proxy].command_line_template
|
|
||||||
ssh_cmd_args << "-o ProxyCommand=\"#{template}\""
|
|
||||||
end
|
|
||||||
|
|
||||||
if host.ssh_options && host.ssh_options[:host_name]
|
|
||||||
ssh_cmd_args << "-o HostName=\"#{host.ssh_options[:host_name]}\""
|
|
||||||
end
|
|
||||||
|
|
||||||
rails_console_args << '--sandbox' if ENV.key?('sandbox') || ENV.key?('s')
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
port = host.port || (host.ssh_options || {})[:port]
|
|
||||||
ssh_cmd_args << "-p #{port}" if port
|
|
||||||
|
|
||||||
ssh_user = if host.ssh_options && host.ssh_options[:user]
|
|
||||||
host.ssh_options[:user]
|
|
||||||
else
|
|
||||||
host.user
|
|
||||||
end
|
|
||||||
ssh_cmd_args << [ssh_user, host.hostname].compact.join('@')
|
|
||||||
|
|
||||||
if host.ssh_options && host.ssh_options[:keys] && host.ssh_options[:keys].length > 0
|
|
||||||
identity = host.ssh_options[:keys][0]
|
|
||||||
ssh_cmd_args << "-i #{identity}"
|
|
||||||
end
|
|
||||||
|
|
||||||
ssh_cmd = %Q(ssh #{ssh_cmd_args.join(' ')} -t '$SHELL -l -c "cd #{current_path} && (#{cmd.environment_string} #{cmd})"')
|
|
||||||
|
|
||||||
debug("Running #{ssh_cmd.yellow} on #{host.hostname.blue}")
|
|
||||||
|
|
||||||
exec(ssh_cmd)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,8 +4,8 @@ module Capistrano
|
||||||
module Rails
|
module Rails
|
||||||
# Console
|
# Console
|
||||||
module Console
|
module Console
|
||||||
# gem version
|
# Gem version
|
||||||
VERSION = '1.0.1'
|
VERSION = '1.1.0'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue