From b411356409928753744eeaa1b45a1d3262d54ed5 Mon Sep 17 00:00:00 2001 From: Krzysztof Adamski Date: Thu, 15 Feb 2024 11:12:18 +0100 Subject: [PATCH] Allow for Custom Accessory Service Name --- lib/kamal/configuration/accessory.rb | 2 +- test/commands/accessory_test.rb | 5 +++-- test/configuration/accessory_test.rb | 2 ++ test/integration/docker/deployer/app/config/deploy.yml | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/kamal/configuration/accessory.rb b/lib/kamal/configuration/accessory.rb index 8fdcd227..d26c6c85 100644 --- a/lib/kamal/configuration/accessory.rb +++ b/lib/kamal/configuration/accessory.rb @@ -8,7 +8,7 @@ class Kamal::Configuration::Accessory end def service_name - "#{config.service}-#{name}" + specifics["service"] || "#{config.service}-#{name}" end def image diff --git a/test/commands/accessory_test.rb b/test/commands/accessory_test.rb index 687c7fe5..92ed1211 100644 --- a/test/commands/accessory_test.rb +++ b/test/commands/accessory_test.rb @@ -34,6 +34,7 @@ class CommandsAccessoryTest < ActiveSupport::TestCase ] }, "busybox" => { + "service" => "custom-busybox", "image" => "busybox:latest", "host" => "1.1.1.7" } @@ -57,7 +58,7 @@ class CommandsAccessoryTest < ActiveSupport::TestCase new_command(:redis).run.join(" ") assert_equal \ - "docker run --name app-busybox --detach --restart unless-stopped --log-opt max-size=\"10m\" --env-file .kamal/env/accessories/app-busybox.env --label service=\"app-busybox\" busybox:latest", + "docker run --name custom-busybox --detach --restart unless-stopped --log-opt max-size=\"10m\" --env-file .kamal/env/accessories/custom-busybox.env --label service=\"custom-busybox\" busybox:latest", new_command(:busybox).run.join(" ") end @@ -65,7 +66,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\" --env-file .kamal/env/accessories/app-busybox.env --label service=\"app-busybox\" busybox:latest", + "docker run --name custom-busybox --detach --restart unless-stopped --log-driver \"local\" --log-opt max-size=\"100m\" --log-opt max-file=\"3\" --env-file .kamal/env/accessories/custom-busybox.env --label service=\"custom-busybox\" busybox:latest", new_command(:busybox).run.join(" ") end diff --git a/test/configuration/accessory_test.rb b/test/configuration/accessory_test.rb index 522dc631..4b56be51 100644 --- a/test/configuration/accessory_test.rb +++ b/test/configuration/accessory_test.rb @@ -49,6 +49,7 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase } }, "monitoring" => { + "service" => "custom-monitoring", "image" => "monitoring:latest", "roles" => [ "web" ], "port" => "4321:4321", @@ -72,6 +73,7 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase test "service name" do assert_equal "app-mysql", @config.accessory(:mysql).service_name assert_equal "app-redis", @config.accessory(:redis).service_name + assert_equal "custom-monitoring", @config.accessory(:monitoring).service_name end test "port" do diff --git a/test/integration/docker/deployer/app/config/deploy.yml b/test/integration/docker/deployer/app/config/deploy.yml index ec070f6c..c1f6f7c5 100644 --- a/test/integration/docker/deployer/app/config/deploy.yml +++ b/test/integration/docker/deployer/app/config/deploy.yml @@ -27,6 +27,7 @@ traefik: image: registry:4443/traefik:v2.9 accessories: busybox: + service: custom-busybox image: registry:4443/busybox:1.36.0 cmd: sh -c 'echo "Starting busybox..."; trap exit term; while true; do sleep 1; done' roles: