diff --git a/lib/kamal/commands/app.rb b/lib/kamal/commands/app.rb index b58861ca..825fe55f 100644 --- a/lib/kamal/commands/app.rb +++ b/lib/kamal/commands/app.rb @@ -21,7 +21,7 @@ class Kamal::Commands::App < Kamal::Commands::Base "-e", "KAMAL_VERSION=\"#{config.version}\"", *role_config.env_args, *role_config.health_check_args, - *config.logging_args, + *role_config.logging_args, *config.volume_args, *role_config.asset_volume_args, *role_config.label_args, diff --git a/lib/kamal/configuration.rb b/lib/kamal/configuration.rb index c171631b..a57d8b3b 100644 --- a/lib/kamal/configuration.rb +++ b/lib/kamal/configuration.rb @@ -6,7 +6,7 @@ require "erb" require "net/ssh/proxy/jump" class Kamal::Configuration - delegate :service, :image, :servers, :env, :labels, :registry, :stop_wait_time, :hooks_path, to: :raw_config, allow_nil: true + delegate :service, :image, :servers, :env, :labels, :registry, :stop_wait_time, :hooks_path, :logging, to: :raw_config, allow_nil: true delegate :argumentize, :optionize, to: Kamal::Utils attr_reader :destination, :raw_config @@ -141,9 +141,9 @@ class Kamal::Configuration end def logging_args - if raw_config.logging.present? - optionize({ "log-driver" => raw_config.logging["driver"] }.compact) + - argumentize("--log-opt", raw_config.logging["options"]) + if logging.present? + optionize({ "log-driver" => logging["driver"] }.compact) + + argumentize("--log-opt", logging["options"]) else argumentize("--log-opt", { "max-size" => "10m" }) end diff --git a/lib/kamal/configuration/role.rb b/lib/kamal/configuration/role.rb index 84787a2f..82c28181 100644 --- a/lib/kamal/configuration/role.rb +++ b/lib/kamal/configuration/role.rb @@ -36,6 +36,18 @@ class Kamal::Configuration::Role argumentize "--label", labels end + def logging_args + args = config.logging || {} + args.deep_merge!(specializations["logging"]) if specializations["logging"].present? + + if args.any? + optionize({ "log-driver" => args["driver"] }.compact) + + argumentize("--log-opt", args["options"]) + else + config.logging_args + end + end + def env if config.env && config.env["secret"] diff --git a/test/commands/app_test.rb b/test/commands/app_test.rb index c2e335a3..c318dc61 100644 --- a/test/commands/app_test.rb +++ b/test/commands/app_test.rb @@ -71,6 +71,15 @@ class CommandsAppTest < ActiveSupport::TestCase new_command.run.join(" ") end + test "run with role logging config" do + @config[:logging] = { "driver" => "local", "options" => { "max-size" => "10m", "max-file" => "3" } } + @config[:servers] = { "web" => { "hosts" => [ "1.1.1.1" ], "logging" => { "driver" => "local", "options" => { "max-size" => "100m" } } } } + + assert_equal \ + "docker run --detach --restart unless-stopped --name app-web-999 -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e KAMAL_VERSION=\"999\" --env-file .kamal/env/roles/app-web.env --health-cmd \"(curl -f http://localhost:3000/up || exit 1) && (stat /tmp/kamal-cord/cord > /dev/null || exit 1)\" --health-interval \"1s\" --volume $(pwd)/.kamal/cords/app-web-12345678901234567890123456789012:/tmp/kamal-cord --log-driver \"local\" --log-opt max-size=\"100m\" --log-opt max-file=\"3\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.routers.app-web.priority=\"2\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999", + new_command.run.join(" ") + end + test "start" do assert_equal \ "docker start app-web-999",