Skip to content

feat: add preflight hook to run commands before dip compose#188

Merged
bibendi merged 2 commits into
bibendi:masterfrom
LeipeLeon:feature/add-preflight-checks
May 23, 2026
Merged

feat: add preflight hook to run commands before dip compose#188
bibendi merged 2 commits into
bibendi:masterfrom
LeipeLeon:feature/add-preflight-checks

Conversation

@LeipeLeon

Copy link
Copy Markdown
Contributor

Summary

  • Adds a new top-level preflight: key to dip.yml — an array of shell commands run before any dip compose ... subcommand (including dip up). A non-zero exit aborts before Docker Compose runs.
  • Mirrors the existing provision pattern: sequential exec_subprocess calls with panic: true, env interpolation, default [].
  • Use cases: verifying credentials are present, required files exist, env vars are set, etc.

Example

preflight:
  - ./bin/check-credentials
  - test -f .env

Test plan

  • New specs in spec/lib/dip/commands/preflight_spec.rb cover no-op, sequential execution, and env interpolation
  • config_spec.rb asserts the preflight accessor exists and defaults sanely
  • Schema validation: preflight is a typed array of strings in schema.json
  • README updated with a usage example

🤖 Generated with Claude Code

New top-level `preflight:` key in dip.yml — an array of shell commands run before any `dip compose ...` subcommand (including `dip up`). A non-zero exit aborts before docker ompose is invoked, making it suitable for verifying credentials, required files, env vars, etc.

Mirrors the existing `provision` pattern: sequential execution via `exec_subprocess` with `panic: true`, env interpolation, and `[]` as the default.
@bibendi bibendi self-requested a review May 21, 2026 19:49
@bibendi

bibendi commented May 22, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR! The feature is well implemented — clean code, good tests, and the Provision-like pattern fits right in.

One architectural concern:

Preflight currently only runs in Commands::Compose#execute, which means it doesn't cover:

  • dip ktl <cmd> — direct kubectl path
  • dip run <cmd> with KubectlRunner or LocalRunner

DockerComposeRunner gets preflight transitively (it calls Compose#execute), but that's implicit and fragile.

I'd suggest moving preflight up to three entry points instead:

  1. Remove the preflight call from Commands::Compose#execute
  2. Add it to Dip::CLI#compose — covers dip compose, dip up, dip build, dip stop, dip down
  3. Add it to Dip::CLI#ktl — covers dip ktl
  4. Add it to Dip::Commands::Run#execute — covers all runners (DockerComposeRunner, KubectlRunner, LocalRunner)

This avoids double execution while covering every code path cleanly. Dip.env is available at all three points — config is already loaded by the time they run.

What do you think?

@LeipeLeon LeipeLeon marked this pull request as draft May 22, 2026 08:25
- Move the preflight call from `Commands::Compose#execute` to `Dip::CLI#compose`
  covers `dip compose`, `dip up`, `dip build`, `dip stop`, `dip down`
- Add to `Dip::CLI#ktl`
  covers `dip ktl`
- Add to Dip::Commands::Run#execute
  covers all runners `dip run ...`
@LeipeLeon LeipeLeon force-pushed the feature/add-preflight-checks branch from f5bee18 to 88cf98e Compare May 22, 2026 08:54
@LeipeLeon

Copy link
Copy Markdown
Contributor Author

addressed your feedback, good call!

entry point for checking is a lot cleaner now.

btw: thnx for this great tool!

@LeipeLeon LeipeLeon marked this pull request as ready for review May 22, 2026 08:59
@bibendi

bibendi commented May 22, 2026

Copy link
Copy Markdown
Owner

Looks good to me! Thank you!
I'll merge it tomorrow

@bibendi bibendi merged commit 6fb50ca into bibendi:master May 23, 2026
9 checks passed
@LeipeLeon LeipeLeon deleted the feature/add-preflight-checks branch May 26, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants