Configurable log levels
Allow ssh log_level to be set - this will help to debug connection issues.
This commit is contained in:
@@ -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`:
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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=>{},
|
||||
|
||||
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user