1
0
Fork 0
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:
Florian Schwab 2015-11-12 23:27:52 +01:00
parent 6b4017c60b
commit 3debb2fc57
5 changed files with 20 additions and 45 deletions

View file

@ -1,6 +1,10 @@
# Change Log
## 1.0.0 (2015-11-12)
## Unreleased
### Changed
- switched connection part to _capistrano-interactive_
## 1.0.1 (2015-11-12)
### Fixed
- setting ssh hostname through `ssh_options`
- use login shell

View file

@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']
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 'rake'

View file

@ -1 +1,3 @@
require 'capistrano/interactive'
load File.expand_path('../tasks/remote.cap', __FILE__)

View file

@ -1,55 +1,23 @@
namespace :load 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)
# Default values
set :console_env, -> { fetch(:rails_env, fetch(:stage, 'production')) }
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
args = []
args << '--sandbox' if ENV.key?('sandbox') || ENV.key?('s')
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[: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)
on primary(:app) do
within current_path do
interact(:rails, :console, fetch(:console_env), *args)
end
end
end
end

View file

@ -4,8 +4,8 @@ module Capistrano
module Rails
# Console
module Console
# gem version
VERSION = '1.0.1'
# Gem version
VERSION = '1.1.0'
end
end
end