Export pre-configure hook output to ENV for config ERB - #1926
Open
rience wants to merge 1 commit into
Open
Conversation
The pre-configure hook can already rewrite the destination and pass data to subsequent hooks, but its output was invisible to the ERB in the config file itself. Export non-reserved keys into ENV before the config is created, so a hook can compute dynamic values (hosts, per-branch settings, etc.) that deploy.yml reads via ENV. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
11 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Exports non-reserved pre-configure hook output to ENV for configuration ERB rendering.
Changes:
- Exports hook output except reserved keys.
- Documents ERB access in the sample hook.
- Adds integration coverage and configurable test YAML.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
lib/kamal/cli/base.rb |
Exports non-reserved hook output to ENV. |
lib/kamal/cli/templates/sample_hooks/pre-configure.sample |
Documents configuration ERB usage. |
test/cli/pre_configure_test.rb |
Tests export behavior and extends test setup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+60
to
+66
| test "pre-configure hook does not export reserved keys to ENV" do | ||
| with_pre_configure_hook({ "KAMAL_MESSAGE" => "Deploying to beta2" }) do | ||
| run_command("exec", "date", "-c", config_file_path("deploy_with_accessories")) | ||
|
|
||
| assert_nil ENV["KAMAL_MESSAGE"] | ||
| end | ||
| end |
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.
Summary
Builds on #1783. The
pre-configurehook can already rewrite the destination and pass data to subsequent hooks via$KAMAL_OUTPUT, but its output is invisible to the ERB in the config file itself — the one consumer that runs immediately after it.This exports every non-reserved key from the hook's output into
ENVbeforeConfiguration.create_fromruns, so a hook can compute dynamic values thatdeploy.ymlreads with plain<%= ENV["..."] %>:KAMAL_DESTINATIONandKAMAL_MESSAGEkeep their existing special semantics and are not exported.Motivation
We deploy a monorepo (~20 apps) where every generated
deploy.*.ymlcurrently starts with an ERB line that loads an internal library and mutatesENVin-process — it even re-parses-dout ofARGV— so the rest of the YAML can read<%= ENV[...] %>. It works only because Kamal renders ERB in-process, and it's exactly the kind of thingpre-configureshould replace. Since config-file ERB has access to nothing butENV, this back-channel is the missing link for feeding hook-computed values into the config.Test plan
servers: - <%= ENV["PRE_CONFIGURE_HOST"] %>resolves)KAMAL_DESTINATION,KAMAL_MESSAGE) are not exported🤖 Generated with Claude Code