From 8c5e74c50a816a9d8fb7ce39f178c069ab6860a9 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Sat, 16 Dec 2023 18:01:24 -0800 Subject: [PATCH] Fix #528 - Allow roles to have volumes --- lib/kamal/commands/app.rb | 1 + lib/kamal/configuration/role.rb | 7 +++++++ test/configuration/role_test.rb | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/lib/kamal/commands/app.rb b/lib/kamal/commands/app.rb index b58861ca7..799f0c685 100644 --- a/lib/kamal/commands/app.rb +++ b/lib/kamal/commands/app.rb @@ -23,6 +23,7 @@ def run(hostname: nil) *role_config.health_check_args, *config.logging_args, *config.volume_args, + *role_config.volume_args, *role_config.asset_volume_args, *role_config.label_args, *role_config.option_args, diff --git a/lib/kamal/configuration/role.rb b/lib/kamal/configuration/role.rb index 84787a2f6..d47da1c1e 100644 --- a/lib/kamal/configuration/role.rb +++ b/lib/kamal/configuration/role.rb @@ -36,6 +36,13 @@ def label_args argumentize "--label", labels end + def volume_args + if specializations["volumes"].present? + argumentize "--volume", specializations["volumes"] + else + [] + end + end def env if config.env && config.env["secret"] diff --git a/test/configuration/role_test.rb b/test/configuration/role_test.rb index 9c1afc56c..104f0a78b 100644 --- a/test/configuration/role_test.rb +++ b/test/configuration/role_test.rb @@ -15,6 +15,7 @@ class ConfigurationRoleTest < ActiveSupport::TestCase "web" => [ "1.1.1.1", "1.1.1.2" ], "workers" => { "hosts" => [ "1.1.1.3", "1.1.1.4" ], + "volumes" => [ "/tmp/test:/tmp/test" ], "cmd" => "bin/jobs", "env" => { "REDIS_URL" => "redis://a/b", @@ -41,6 +42,10 @@ class ConfigurationRoleTest < ActiveSupport::TestCase assert_equal [ "--label", "service=\"app\"", "--label", "role=\"workers\"" ], @config_with_roles.role(:workers).label_args end + test "volume args" do + assert_equal [ "--volume", "/tmp/test:/tmp/test" ], @config_with_roles.role(:workers).volume_args + end + test "special label args for web" do assert_equal [ "--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\"" ], @config.role(:web).label_args end