fix(docker-publish): explicit builder setup and daemon-side GC verification

Replace the chained inspect||create||inspect with explicit steps:
register builder metadata without --bootstrap (create errors fail the
job), bootstrap with a single logged retry for concurrent creation, and
verify the GC policy reported by the running BuildKit daemon. A builder
created by this job without the expected policy fails the job; an
existing unmigrated builder gets a warning pointing to the manual
migration. The temporary buildkitd config is removed on exit. Existing
containers and state volumes are never recreated or removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dresberandClaude Opus 5.5 committed 2026-10-24 12:42:55 +00:00
1 parent 4535438a1c
commit de2e6fd3bd
2 files changed
+77 -24

No files matched your search

+31 -13
View File
@@ -23,7 +23,8 @@ target the host daemon that runs the production containers.
- The `reservedSpace`/`maxUsedSpace`/`minFreeSpace` keys need **BuildKit >= v0.17**. Older daemons
only understand `gckeepstorage`. `moby/buildkit:buildx-stable-1` is far newer than v0.17. Check
the deployed version anyway (section 3).
- Sizes are decimal: `20GB` = 20·10⁹ bytes. `buildx inspect` shows it as `18.63GiB`.
- BuildKit parses the sizes with go-units. Depending on the version, `docker buildx inspect`
shows `20GB` as `20GiB` (binary) or `18.63GiB` (decimal). The workflow check accepts both.
- `maxUsedSpace` is a **GC threshold, not a quota**. GC runs after builds and periodically, so the
cache can briefly exceed 20 GB during a large build. GC removes the least recently used records
first, so hot base and dependency layers survive.
@@ -38,14 +39,25 @@ The file is in the container's filesystem, so it survives `docker restart` and D
restarts. It is lost only if the container is removed.
When the container already exists, the workflow **reuses it unchanged**. It never removes,
recreates, restarts or reconfigures a builder, so concurrent jobs cannot race on that. The only
race left is two jobs creating a *missing* builder at the same time. That race existed before
this change. The losing job now falls back to `docker buildx inspect --bootstrap multiarch`,
which never recreates anything.
recreates, restarts or reconfigures a builder, so concurrent jobs cannot race on that.
If the running builder has no managed config, every publish job prints a non-fatal warning
(`::warning::BuildKit builder 'multiarch' has no managed GC config`). The job log also shows the
daemon's GC policy.
The setup step runs these steps in order, and none of them hides an error:
1. If this job has no buildx metadata for `multiarch`, run `docker buildx create
--buildkitd-config` without `--bootstrap`. If that fails, the job fails.
2. Run `docker buildx inspect --bootstrap multiarch`. This starts the existing container, or
creates it if it is missing. If it fails, the step retries once after 10 seconds. That retry
covers two jobs creating a missing builder at the same moment. A second failure fails the
job with buildx's own error.
3. Check the GC policy that the **running daemon** reports (`docker buildx inspect multiarch`;
the job log shows the "GC Policy" section):
- all three limits match: logs `BuildKit GC config is active`;
- this job created the container from the config, but the limits do not match: **job
fails** (`::error::`);
- the builder already existed without the config: **non-fatal warning** that the managed GC
limits are not active and the one-time migration below is required. The build continues
unchanged.
4. Delete the temporary config file when the step exits.
## 2. One-time migration of the existing `multiarch` builder (manual)
@@ -88,7 +100,11 @@ docker exec gitea-dind docker restart buildx_buildkit_multiarch0
docker exec gitea-dind rm -rf /tmp/bk
```
The config is not active until the restart. Verify it (section 3) before releasing the runner.
The config is not active until the restart. Verify it (section 3) before you release the runner.
If the daemon does not report the expected policy, or the container does not come back up,
delete the file again and restart the container (see Rollback in section 5). The cache volume
is not affected either way. Once the runner is back in service, the next v1.11.5 publish job
should log `BuildKit GC config is active` instead of the migration warning.
### Option B (fallback): remove only the container and let CI recreate it
@@ -100,7 +116,9 @@ docker exec gitea-dind docker rm -f buildx_buildkit_multiarch0
The next publish job runs `buildx create --buildkitd-config`. That creates a new container,
which mounts the **existing** named volume `buildx_buildkit_multiarch0_state`, so the cache is
kept. Start a single publish job first, so that parallel jobs do not race to create the
container. Use this option only if Option A cannot be verified.
container. That first job **must use `@v1.11.5` or later**. A consumer still on v1.11.4 or older
recreates the container *without* the config. Use this option only if Option A cannot be
verified.
## 3. Verification
@@ -110,9 +128,9 @@ Of the commands below, only the running daemon's GC policy proves that GC is con
```bash
# Authoritative: the GC policy the running buildkitd uses
docker exec gitea-dind docker exec buildx_buildkit_multiarch0 buildctl debug workers -v
# expected: GC Policy rules showing Reserved Space 10GB / Max Used Space 20GB / Min Free Space 50GB
# (some versions print these as 9.313GiB / 18.63GiB / 46.57GiB). Without the config you see
# percentage-derived defaults instead.
# expected: GC Policy rules with Reserved Space / Max Used Space / Min Free Space of
# 10GiB / 20GiB / 50GiB (or 9.313GiB / 18.63GiB / 46.57GiB, depending on the version).
# Without the config you see percentage-derived defaults instead.
# The same data appears in every publish job log ("GC Policy" section of `docker buildx inspect multiarch`).
# The file that buildkitd loads at startup (shows it exists, not that it is active)