Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #528 - Allow roles to have volumes #613

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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