Add pre-configure hook for destination rewriting#1783
Add pre-configure hook for destination rewriting#1783jeremy wants to merge 1 commit intohook-outputfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 61414304cd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR introduces a new post-configure hook that fires before configuration is created, allowing hooks to inject or rewrite deployment destinations dynamically. This builds on the hook output mechanism from PR #1782.
Changes:
- Added
before_configcallback mechanism inCommanderfor lazy hook execution - Implemented
post-configurehook that can rewriteKAMAL_DESTINATIONbefore config validation - Enhanced command/subcommand methods with nil-safety to handle hook execution context
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| lib/kamal/commander.rb | Added before_config callback mechanism and lazy config evaluation to support pre-configuration hooks |
| lib/kamal/cli/base.rb | Implemented run_post_configure_hook method with destination-aware hooks_path resolution; improved nil-safety in command/subcommand methods |
| lib/kamal/cli/templates/sample_hooks/post-configure.sample | New sample hook demonstrating destination rewriting with clear documentation |
| test/cli/post_configure_test.rb | Comprehensive test coverage including destination rewriting, require_destination interaction, error handling, and cleanup |
| test/cli/main_test.rb | Changed from rigid .expects().times(4) to flexible .stubs() to accommodate variable Pathname.exist? calls during initialization |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ba0be65 to
41c4687
Compare
Destination is locked in at first config access — before any hook fires. A pre-configure hook lets you redirect before anything acts on it. Lifecycle: configure(destination: "beta") → pre-configure hook fires → hook writes KAMAL_DESTINATION=beta2 → reconfigure(destination: "beta2") → config loads with deploy.beta2.yml → specific_hosts/roles applied The hook fires whenever its file exists, not gated on -d. It can inject a destination for plain `kamal deploy`, not just rewrite an explicit one. Skipped when the config file doesn't exist (e.g. `kamal init`, `kamal version`). Commander gains `before_config` which preserves config_file and version while resetting config, commands cache, and specifics. command/subcommand made nil-safe since pre-configure fires before Thor has fully initialized invocations.
41c4687 to
33bff99
Compare
Summary
Adds a
pre-configurehook that fires before configuration is created, allowing hooks to inject or rewrite the deployment destination dynamically.Lifecycle
The hook fires whenever
.kamal/hooks/pre-configureexists, not gated on-d. It can inject a destination for plainkamal deploy, not just rewrite an explicit one. Skipped when the config file doesn't exist (e.g.kamal init,kamal version).Implementation
before_configcallback in Commander fires before firstconfigaccessKAMAL_DESTINATION=<new>to$KAMAL_OUTPUTto rewritecommand/subcommandmade nil-safe since the hook fires before Thor has fully initialized invocationsDepends on #1782 for the
KAMAL_OUTPUTmechanism.Test plan
pre-configurehook rewrites destinationrequire_destinationis setKAMAL_MESSAGEdisplayed after hook runsHookError--skip-hookskamal version)KAMAL_DESTINATIONenv var when no-dflag