Repository navigation
Set KAMAL_DESTINATION before rendering the config for an alias - #1968
Open
viktorianer wants to merge 1 commit into
Open
viktorianer wants to merge 1 commit into
viktorianer wants to merge 1 commit into
Conversation
An alias is resolved by loading the raw config before Configuration.create_from runs, so ERB in deploy.yml rendered without KAMAL_DESTINATION even when --destination was given. A config that picks its env file or values from the destination then resolved the alias against the wrong ones. Setting the variable in load_raw_config covers both paths.
Contributor
There was a problem hiding this comment.
🟢 Approved
The change addresses the alias rendering order while preserving existing configuration behavior and adding focused regression coverage.
0 open findings
What changed in this PR
Sets KAMAL_DESTINATION before rendering configuration, ensuring aliases use destination-specific ERB values.
Changes:
- Moves destination environment setup into
load_raw_config. - Adds an alias integration test and destination fixtures.
[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or rungh pr ready --undo.
Click "Ready for review" or rungh pr readyto reengage.
| File | Description |
|---|---|
lib/kamal/configuration.rb |
Sets the destination before ERB rendering. |
test/cli/main_test.rb |
Tests destination-aware alias rendering. |
test/fixtures/deploy_with_destination_aliases.yml |
Defines an ERB-based alias fixture. |
test/fixtures/deploy_with_destination_aliases.world.yml |
Supplies the destination-specific server fixture. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
kamal <alias> -d stagingresolves the alias throughCommander#resolve_alias, which callsConfiguration.load_raw_configbefore anyConfiguration.create_from. Onlycreate_fromsetsENV["KAMAL_DESTINATION"], so the ERB indeploy.ymlrenders without the destination the command was given.A config that reads the destination at render time then resolves the alias against the wrong values. A common shape is loading a per-destination env file:
With an alias, this loads
.env.productionfor-d staging. It raises when that file is absent, or silently renders production values before the real command runs with the staging config. The same command without an alias renders correctly.ENV["KAMAL_DESTINATION"]is now set inload_raw_config, which bothcreate_fromandresolve_aliascall.The new test in
test/cli/main_test.rbruns an alias whose command rendersKAMAL_DESTINATION. It fails without the change, because the command is rendered asbin/console, notbin/console world.