Skip to content

Commit

Permalink
Merge pull request #598 from basecamp/fix-duplicate-role-env-vars
Browse files Browse the repository at this point in the history
Fix duplicate role env vars
  • Loading branch information
djmb authored Nov 29, 2023
2 parents a155b7b + 7fa53d9 commit 457f06d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/kamal/configuration/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def merged_env_with_secrets
clear_app_env = config.env["secret"] ? Array(config.env["clear"]) : Array(config.env["clear"] || config.env)
clear_role_env = specialized_env["secret"] ? Array(specialized_env["clear"]) : Array(specialized_env["clear"] || specialized_env)

new_env["clear"] = (clear_app_env + clear_role_env).uniq
new_env["clear"] = clear_app_env.to_h.merge(clear_role_env.to_h)
end
end

Expand Down
28 changes: 28 additions & 0 deletions test/configuration/role_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,34 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
ENV["REDIS_PASSWORD"] = nil
end

test "env overwritten by role with secrets" do
@deploy_with_roles[:env] = {
"clear" => {
"REDIS_URL" => "redis://a/b"
},
"secret" => [
"REDIS_PASSWORD"
]
}

@deploy_with_roles[:servers]["workers"]["env"] = {
"clear" => {
"REDIS_URL" => "redis://c/d",
},
}

ENV["REDIS_PASSWORD"] = "secret456"

expected = <<~ENV
REDIS_PASSWORD=secret456
REDIS_URL=redis://c/d
ENV

assert_equal expected, @config_with_roles.role(:workers).env_file.to_s
ensure
ENV["REDIS_PASSWORD"] = nil
end

test "host_env_directory" do
assert_equal ".kamal/env/roles", @config_with_roles.role(:workers).host_env_directory
end
Expand Down

0 comments on commit 457f06d

Please sign in to comment.