Repository navigation
Recreate a local builder whose Docker context was removed - #1999
Open
viktorianer wants to merge 2 commits into
Open
viktorianer wants to merge 2 commits into
viktorianer wants to merge 2 commits into
Conversation
docker buildx inspect exits 0 for a builder whose node points at a removed Docker context, so the push kept the builder and every build failed with "no valid drivers found: unable to parse docker host". inspect_builder now fails when the node reports that error, with a message the existing rescue treats as a missing builder, so the builder is removed and created again. Only that error counts: a stopped engine also reports a node error, and recreating its builder would drop the build cache. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Executable coverage is still missing for stopped-engine and unrelated inspect-error paths, leaving the shell safety condition vulnerable to recreating builders and discarding caches.
2 open issues
What changed in this PR
This pull request updates local Buildx builder inspection to detect builders backed by removed Docker contexts and recreate them before builds fail.
Changes:
- Detects
unable to parse docker hostduring local builder inspection. - Preserves existing handling for other inspection failures.
- Updates command and CLI tests for the new inspection and recreation flow.
| File | Description |
|---|---|
| test/commands/builder_test.rb | Verifies the generated local builder inspection command. |
| test/cli/cli_test_case.rb | Updates shared SSHKit stubs for the revised builder inspection command. |
| test/cli/build_test.rb | Covers builder inspection expectations and recreation after a Docker context is removed. |
| lib/kamal/commands/builder/base.rb | Adds detection for local builders whose Docker context no longer exists. |
Review effort: Lite
The check ran docker buildx inspect twice, so a context on another host paid for two round trips before every build. It now keeps the output of one inspect, exits with its status when it fails, and looks for the removed-context error in that output. The new tests run the generated command through SSHKit's local backend against a fake docker, so they cover the shell control flow and SSHKit's command mapping, not only the command string: a removed context fails with the marker, a healthy builder and a stopped engine pass, and a missing builder or an unrelated failure keeps its own error. Each inspects once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

A local builder whose Docker context was removed is never recreated.
docker buildx inspectstill exits 0 for it, reporting the broken node only in its output, so Kamal keeps the builder and every build fails:This makes
inspect_builderfail when the builder's node reportsunable to parse docker host, with a message the existing rescue inKamal::Cli::Build#pushalready treats as a missing builder. Every other inspect failure keeps its own error, since the message is printed only after that match. Kamal removes the builder and creates it again.docker buildx rmexits 1 for such a builder even though it removes it, and the rescue already tolerates that forcontext not found.The check matches that one error, not any node error. A stopped engine also reports a node error (
failed to connect to the docker API), and recreating that builder would throw away its cache while the build fails anyway.Reproduction
Verification
The new
inspect_builderrunsdocker buildx inspectonce undersh -c, keeps its output and exits with its status when it fails. Executed through SSHKit's local backend against Docker 29.5.2:builder context not foundERROR: no builder "…" found, as beforefailed to connect to the docker API, so the builder is keptbin/kamal build push --output dockerfrom this branch, against a project whose builder sits on a removed context, warnsMissing compatible builder, so creating a new one first, recreates the builder and builds. Onmainthe same run fails withno valid drivers found. A second push keeps the recreated builder.The new tests run the generated command through SSHKit's local backend against a fake
docker, covering the same states and one inspect per check.Remote and hybrid builders keep their own
inspect_builder. A remote builder whose context was removed already fails its context check. The local node of a hybrid builder can go stale the same way and is not covered here.🤖 Generated with Claude Code