From 9c27ead21fd936f5d0005efbb3297d419c8d9058 Mon Sep 17 00:00:00 2001 From: Samuel Sieg Date: Fri, 24 Mar 2023 09:38:02 +0100 Subject: [PATCH] Ensure it also works when configuring just log options without setting a driver --- lib/mrsk/configuration.rb | 4 ++-- test/commands/accessory_test.rb | 2 +- test/commands/app_test.rb | 2 +- test/commands/traefik_test.rb | 2 +- test/configuration_test.rb | 9 +++++++-- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/mrsk/configuration.rb b/lib/mrsk/configuration.rb index 02bdf088..cf4f672c 100644 --- a/lib/mrsk/configuration.rb +++ b/lib/mrsk/configuration.rb @@ -7,7 +7,7 @@ require "net/ssh/proxy/jump" class Mrsk::Configuration delegate :service, :image, :servers, :env, :labels, :registry, :builder, :logging, to: :raw_config, allow_nil: true - delegate :argumentize, :argumentize_env_with_secrets, to: Mrsk::Utils + delegate :argumentize, :argumentize_env_with_secrets, :optionize, to: Mrsk::Utils attr_accessor :destination attr_accessor :raw_config @@ -125,7 +125,7 @@ class Mrsk::Configuration def logging_args if raw_config.logging.present? - [ "--log-driver", raw_config.logging["driver"] ] + + optionize({ "log-driver" => raw_config.logging["driver"] }.compact) + argumentize("--log-opt", raw_config.logging["options"]) else argumentize("--log-opt", { "max-size" => MAX_LOG_SIZE }) diff --git a/test/commands/accessory_test.rb b/test/commands/accessory_test.rb index 84590d56..71a3058b 100644 --- a/test/commands/accessory_test.rb +++ b/test/commands/accessory_test.rb @@ -65,7 +65,7 @@ class CommandsAccessoryTest < ActiveSupport::TestCase @config[:logging] = { "driver" => "local", "options" => { "max-size" => "100m", "max-file" => "3" } } assert_equal \ - "docker run --name app-busybox --detach --restart unless-stopped --log-driver local --log-opt max-size=\"100m\" --log-opt max-file=\"3\" --label service=\"app-busybox\" busybox:latest", + "docker run --name app-busybox --detach --restart unless-stopped --log-driver \"local\" --log-opt max-size=\"100m\" --log-opt max-file=\"3\" --label service=\"app-busybox\" busybox:latest", new_command(:busybox).run.join(" ") end diff --git a/test/commands/app_test.rb b/test/commands/app_test.rb index 65185636..2904e7dc 100644 --- a/test/commands/app_test.rb +++ b/test/commands/app_test.rb @@ -45,7 +45,7 @@ class CommandsAppTest < ActiveSupport::TestCase @config[:logging] = { "driver" => "local", "options" => { "max-size" => "100m", "max-file" => "3" } } assert_equal \ - "docker run --detach --restart unless-stopped --name app-999 -e MRSK_CONTAINER_NAME=\"app-999\" -e RAILS_MASTER_KEY=\"456\" --log-driver local --log-opt max-size=\"100m\" --log-opt max-file=\"3\" --label service=\"app\" --label role=\"web\" --label traefik.http.routers.app.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.services.app.loadbalancer.healthcheck.path=\"/up\" --label traefik.http.services.app.loadbalancer.healthcheck.interval=\"1s\" --label traefik.http.middlewares.app-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app.middlewares=\"app-retry@docker\" dhh/app:999", + "docker run --detach --restart unless-stopped --name app-999 -e MRSK_CONTAINER_NAME=\"app-999\" -e RAILS_MASTER_KEY=\"456\" --log-driver \"local\" --log-opt max-size=\"100m\" --log-opt max-file=\"3\" --label service=\"app\" --label role=\"web\" --label traefik.http.routers.app.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.services.app.loadbalancer.healthcheck.path=\"/up\" --label traefik.http.services.app.loadbalancer.healthcheck.interval=\"1s\" --label traefik.http.middlewares.app-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app.middlewares=\"app-retry@docker\" dhh/app:999", new_command.run.join(" ") end diff --git a/test/commands/traefik_test.rb b/test/commands/traefik_test.rb index a0d1b8ae..3f6084d1 100644 --- a/test/commands/traefik_test.rb +++ b/test/commands/traefik_test.rb @@ -64,7 +64,7 @@ class CommandsTraefikTest < ActiveSupport::TestCase @config[:logging] = { "driver" => "local", "options" => { "max-size" => "100m", "max-file" => "3" } } assert_equal \ - "docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --log-driver local --log-opt max-size=\"100m\" --log-opt max-file=\"3\" traefik --providers.docker --log.level=DEBUG --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"", + "docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --log-driver \"local\" --log-opt max-size=\"100m\" --log-opt max-file=\"3\" traefik --providers.docker --log.level=DEBUG --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"", new_command.run.join(" ") end diff --git a/test/configuration_test.rb b/test/configuration_test.rb index 75b9de14..74739bc7 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -213,9 +213,14 @@ class ConfigurationTest < ActiveSupport::TestCase assert_equal ["--log-opt", "max-size=\"10m\""], @config.logging_args end - test "logging args with custom config" do + test "logging args with configured options" do + config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(logging: { "options" => { "max-size" => "100m", "max-file" => 5 } }) }) + assert_equal ["--log-opt", "max-size=\"100m\"", "--log-opt", "max-file=\"5\""], @config.logging_args + end + + test "logging args with configured driver and options" do config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(logging: { "driver" => "local", "options" => { "max-size" => "100m", "max-file" => 5 } }) }) - assert_equal ["--log-driver", "local", "--log-opt", "max-size=\"100m\"", "--log-opt", "max-file=\"5\""], @config.logging_args + assert_equal ["--log-driver", "\"local\"", "--log-opt", "max-size=\"100m\"", "--log-opt", "max-file=\"5\""], @config.logging_args end test "erb evaluation of yml config" do