Skip to content

Commit

Permalink
Fix #528 - Allow roles to have volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
samcraigjohnson committed Dec 17, 2023
1 parent 457f06d commit 909a365
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/kamal/commands/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions lib/kamal/configuration/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
5 changes: 5 additions & 0 deletions test/configuration/role_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down

0 comments on commit 909a365

Please sign in to comment.