diff --git a/README.md b/README.md index 4174ba2c..8a8dd088 100644 --- a/README.md +++ b/README.md @@ -258,6 +258,14 @@ ssh: proxy_command: aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p' --region=us-east-1 ## ssh via aws ssm ``` +### Configuring the SSH log level + +```yaml +ssh: + log_level: debug +``` + +Valid levels are `debug`, `info`, `warn`, `error` and `fatal` (default). ### Using env variables You can inject env variables into the app containers using `env`: diff --git a/lib/mrsk/configuration.rb b/lib/mrsk/configuration.rb index f3e0a8cc..c35a9854 100644 --- a/lib/mrsk/configuration.rb +++ b/lib/mrsk/configuration.rb @@ -172,7 +172,7 @@ class Mrsk::Configuration service_with_version: service_with_version, env_args: env_args, volume_args: volume_args, - ssh_options: ssh.options, + ssh_options: ssh.to_h, sshkit: sshkit.to_h, builder: builder.to_h, accessories: raw_config.accessories, diff --git a/lib/mrsk/configuration/ssh.rb b/lib/mrsk/configuration/ssh.rb index d328a5fa..f8ad0a3d 100644 --- a/lib/mrsk/configuration/ssh.rb +++ b/lib/mrsk/configuration/ssh.rb @@ -1,4 +1,6 @@ class Mrsk::Configuration::Ssh + LOGGER = ::Logger.new(STDERR) + def initialize(config:) @config = config.raw_config.ssh || {} end @@ -16,9 +18,21 @@ class Mrsk::Configuration::Ssh end def options - { user: user, proxy: proxy, auth_methods: [ "publickey" ], keepalive: true, keepalive_interval: 30 }.compact + { user: user, proxy: proxy, auth_methods: [ "publickey" ], logger: logger, keepalive: true, keepalive_interval: 30 }.compact + end + + def to_h + options.except(:logger).merge(log_level: log_level) end private attr_accessor :config + + def logger + LOGGER.tap { |logger| logger.level = log_level } + end + + def log_level + config.fetch("log_level", :fatal) + end end diff --git a/test/configuration/ssh_test.rb b/test/configuration/ssh_test.rb index b958309e..d85abfd6 100644 --- a/test/configuration/ssh_test.rb +++ b/test/configuration/ssh_test.rb @@ -17,16 +17,20 @@ class ConfigurationSshTest < ActiveSupport::TestCase 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] + assert_equal "app", config.ssh.options[:user] + assert_equal 4, config.ssh.options[:logger].level + + config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "log_level" => "debug" }) }) + assert_equal 0, config.ssh.options[:logger].level 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 "root@1.2.3.4", @config.ssh.options[:proxy].jump_proxies + assert_equal "root@1.2.3.4", 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" => "app@1.2.3.4" }) }) - assert_equal "app@1.2.3.4", @config.ssh.options[:proxy].jump_proxies + assert_equal "app@1.2.3.4", config.ssh.options[:proxy].jump_proxies end end diff --git a/test/configuration_test.rb b/test/configuration_test.rb index fde98789..2167c043 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -258,7 +258,7 @@ class ConfigurationTest < ActiveSupport::TestCase :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 }, + :ssh_options=>{ :user=>"root", :auth_methods=>["publickey"], log_level: :fatal, keepalive: true, keepalive_interval: 30 }, :sshkit=>{}, :volume_args=>["--volume", "/local/path:/container/path"], :builder=>{}, diff --git a/test/integration/main_test.rb b/test/integration/main_test.rb index 521661bd..c215e057 100644 --- a/test/integration/main_test.rb +++ b/test/integration/main_test.rb @@ -51,7 +51,7 @@ class MainTest < IntegrationTest assert_equal "app-#{version}", config[:service_with_version] assert_equal [], config[:env_args] assert_equal [], config[:volume_args] - assert_equal({ user: "root", auth_methods: [ "publickey" ], keepalive: true, keepalive_interval: 30 }, config[:ssh_options]) + assert_equal({ user: "root", auth_methods: [ "publickey" ], keepalive: true, keepalive_interval: 30, log_level: :fatal }, config[:ssh_options]) assert_equal({ "multiarch" => false, "args" => { "COMMIT_SHA" => version } }, config[:builder]) assert_equal [ "--log-opt", "max-size=\"10m\"" ], config[:logging] assert_equal({ "path" => "/up", "port" => 3000, "max_attempts" => 7, "cmd" => "wget -qO- http://localhost > /dev/null" }, config[:healthcheck])