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 duplicate role env vars #598

Merged
merged 1 commit into from
Nov 29, 2023
Merged

Fix duplicate role env vars #598

merged 1 commit into from
Nov 29, 2023

Conversation

mdkent
Copy link
Member

@mdkent mdkent commented Nov 29, 2023

Noted this while doing some role based overrides mixed with secrets:

app@foo:~$ rg REDIS_SHARED_HOST .kamal/env/roles/foo-web-staging.env
26:REDIS_SHARED_HOST=foo-staging-redis-shared-primary
35:REDIS_SHARED_HOST=foo-staging-redis-shared-local

oddly enough if does work as they're loaded in the right order, but it's certainly confusing.

The simplest fix seems to be to convert things to hashes and merge them instead of adding the array.

I've added a test and verified the current behaviour

$ bin/test test/configuration/role_test.rb
Run options: --seed 2085

# Running:

.......................F

Failure:
ConfigurationRoleTest#test_env_overwritten_by_role_with_secrets [/Users/mkent/Work/basecamp/kamal/test/configuration/role_test.rb:202]:
--- expected
+++ actual
@@ -1,3 +1,4 @@
 "REDIS_PASSWORD=secret456
+REDIS_URL=redis://a/b
 REDIS_URL=redis://c/d
 "

bin/test Users/mkent/Work/basecamp/kamal/test/configuration/role_test.rb:179

Finished in 0.009148s, 2623.5243 runs/s, 5902.9296 assertions/s.
24 runs, 54 assertions, 1 failures, 0 errors, 0 skips

and the new fix.

This is better then adding them together which confusingly results in
both ENV vars in the same file, though based on the load order, they
worked anyway.
@mdkent mdkent requested a review from djmb November 29, 2023 00:11
@djmb djmb merged commit 457f06d into main Nov 29, 2023
6 checks passed
@djmb djmb deleted the fix-duplicate-role-env-vars branch November 29, 2023 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants