-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #399 from mrsked/manage-ssh-connection-starts
Manage SSH connection starts
- Loading branch information
Showing
13 changed files
with
201 additions
and
43 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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Mrsk::Configuration::Ssh | ||
def initialize(config:) | ||
@config = config.raw_config.ssh || {} | ||
end | ||
|
||
def user | ||
config.fetch("user", "root") | ||
end | ||
|
||
def proxy | ||
if (proxy = config["proxy"]) | ||
Net::SSH::Proxy::Jump.new(proxy.include?("@") ? proxy : "root@#{proxy}") | ||
elsif (proxy_command = config["proxy_command"]) | ||
Net::SSH::Proxy::Command.new(proxy_command) | ||
end | ||
end | ||
|
||
def options | ||
{ user: user, proxy: proxy, auth_methods: [ "publickey" ], keepalive: true, keepalive_interval: 30 }.compact | ||
end | ||
|
||
private | ||
attr_accessor :config | ||
end |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Mrsk::Configuration::Sshkit | ||
def initialize(config:) | ||
@options = config.raw_config.sshkit || {} | ||
end | ||
|
||
def max_concurrent_starts | ||
options.fetch("max_concurrent_starts", 30) | ||
end | ||
|
||
def pool_idle_timeout | ||
options.fetch("pool_idle_timeout", 900) | ||
end | ||
|
||
def to_h | ||
options | ||
end | ||
|
||
private | ||
attr_accessor :options | ||
end |
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
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require "test_helper" | ||
|
||
class ConfigurationSshTest < ActiveSupport::TestCase | ||
setup do | ||
@deploy = { | ||
service: "app", image: "dhh/app", | ||
registry: { "username" => "dhh", "password" => "secret" }, | ||
env: { "REDIS_URL" => "redis://x/y" }, | ||
servers: [ "1.1.1.1", "1.1.1.2" ], | ||
volumes: ["/local/path:/container/path"] | ||
} | ||
|
||
@config = Mrsk::Configuration.new(@deploy) | ||
end | ||
|
||
test "ssh options" do | ||
assert_equal "root", @config.ssh.options[:user] | ||
|
||
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "user" => "app" }) }) | ||
assert_equal "app", @config.ssh.options[:user] | ||
end | ||
|
||
test "ssh options with proxy host" do | ||
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "1.2.3.4" }) }) | ||
assert_equal "[email protected]", @config.ssh.options[:proxy].jump_proxies | ||
end | ||
|
||
test "ssh options with proxy host and user" do | ||
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "[email protected]" }) }) | ||
assert_equal "[email protected]", @config.ssh.options[:proxy].jump_proxies | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require "test_helper" | ||
|
||
class ConfigurationSshkitTest < ActiveSupport::TestCase | ||
setup do | ||
@deploy = { | ||
service: "app", image: "dhh/app", | ||
registry: { "username" => "dhh", "password" => "secret" }, | ||
env: { "REDIS_URL" => "redis://x/y" }, | ||
servers: [ "1.1.1.1", "1.1.1.2" ], | ||
volumes: ["/local/path:/container/path"] | ||
} | ||
|
||
@config = Mrsk::Configuration.new(@deploy) | ||
end | ||
|
||
test "sshkit max concurrent starts" do | ||
assert_equal 30, @config.sshkit.max_concurrent_starts | ||
@config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(sshkit: { "max_concurrent_starts" => 50 }) }) | ||
assert_equal 50, @config.sshkit.max_concurrent_starts | ||
end | ||
|
||
test "sshkit pool idle timeout" do | ||
assert_equal 900, @config.sshkit.pool_idle_timeout | ||
@config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(sshkit: { "pool_idle_timeout" => 600 }) }) | ||
assert_equal 600, @config.sshkit.pool_idle_timeout | ||
end | ||
end |
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 |
---|---|---|
|
@@ -207,23 +207,6 @@ class ConfigurationTest < ActiveSupport::TestCase | |
end | ||
end | ||
|
||
test "ssh options" do | ||
assert_equal "root", @config.ssh_options[:user] | ||
|
||
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "user" => "app" }) }) | ||
assert_equal "app", @config.ssh_options[:user] | ||
end | ||
|
||
test "ssh options with proxy host" do | ||
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "1.2.3.4" }) }) | ||
assert_equal "[email protected]", @config.ssh_options[:proxy].jump_proxies | ||
end | ||
|
||
test "ssh options with proxy host and user" do | ||
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "[email protected]" }) }) | ||
assert_equal "[email protected]", @config.ssh_options[:proxy].jump_proxies | ||
end | ||
|
||
test "volume_args" do | ||
assert_equal ["--volume", "/local/path:/container/path"], @config.volume_args | ||
end | ||
|
@@ -266,7 +249,23 @@ class ConfigurationTest < ActiveSupport::TestCase | |
end | ||
|
||
test "to_h" do | ||
assert_equal({ :roles=>["web"], :hosts=>["1.1.1.1", "1.1.1.2"], :primary_host=>"1.1.1.1", :version=>"missing", :repository=>"dhh/app", :absolute_image=>"dhh/app:missing", :service_with_version=>"app-missing", :env_args=>["-e", "REDIS_URL=\"redis://x/y\""], :ssh_options=>{:user=>"root", :auth_methods=>["publickey"]}, :volume_args=>["--volume", "/local/path:/container/path"], :builder=>{}, :logging=>["--log-opt", "max-size=\"10m\""], :healthcheck=>{"path"=>"/up", "port"=>3000, "max_attempts" => 7 }}, @config.to_h) | ||
expected_config = \ | ||
{ :roles=>["web"], | ||
:hosts=>["1.1.1.1", "1.1.1.2"], | ||
:primary_host=>"1.1.1.1", | ||
:version=>"missing", | ||
:repository=>"dhh/app", | ||
:absolute_image=>"dhh/app:missing", | ||
:service_with_version=>"app-missing", | ||
:env_args=>["-e", "REDIS_URL=\"redis://x/y\""], | ||
:ssh_options=>{ :user=>"root", :auth_methods=>["publickey"], keepalive: true, keepalive_interval: 30 }, | ||
:sshkit=>{}, | ||
:volume_args=>["--volume", "/local/path:/container/path"], | ||
:builder=>{}, | ||
:logging=>["--log-opt", "max-size=\"10m\""], | ||
:healthcheck=>{ "path"=>"/up", "port"=>3000, "max_attempts" => 7 }} | ||
|
||
assert_equal expected_config, @config.to_h | ||
end | ||
|
||
test "min version is lower" do | ||
|
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