fix(docker-publish): configure BuildKit cache GC for new multiarch builders

Pass a buildkitd config (reservedSpace 10GB, maxUsedSpace 20GB,
minFreeSpace 50GB) via --buildkitd-config when the multiarch builder is
created. Existing builders are reused unchanged and never recreated; a
non-fatal warning flags builders without the managed config. Document
the one-time manual migration, verification, DinD image retention
proposal and rollback in docs/buildkit-gc.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dresberandClaude Opus 5.5 committed 2026-10-24 11:53:17 +00:00
1 parent 602ff49f7b
commit 4535438a1c
2 files changed
+222 -1

No files matched your search

+25 -1
View File
@@ -131,10 +131,34 @@ jobs:
# A docker-container builder is required for multi-platform output (the default docker
# driver builds a single platform only). Idempotent across re-runs on a warm runner.
#
# BuildKit cache GC (v1.11.5+): the config is copied into the BuildKit container only
# when buildx *creates* it. An existing buildx_buildkit_multiarch0 container (and its
# persistent state volume) is reused as-is and never recreated or restarted here, so
# concurrent jobs cannot race on reconfiguration. Existing builders are migrated once,
# manually: see docs/buildkit-gc.md. maxUsedSpace is a GC threshold, not a hard quota.
BUILDKITD_CONFIG="$(mktemp)"
cat > "${BUILDKITD_CONFIG}" <<'EOF'
[worker.oci]
gc = true
reservedSpace = "10GB"
maxUsedSpace = "20GB"
minFreeSpace = "50GB"
EOF
docker buildx inspect multiarch >/dev/null 2>&1 || \
docker buildx create --name multiarch --driver docker-container --bootstrap
docker buildx create --name multiarch --driver docker-container \
--buildkitd-config "${BUILDKITD_CONFIG}" --bootstrap || \
docker buildx inspect --bootstrap multiarch
docker buildx use multiarch
# Non-fatal: flag builders that predate the GC config. Authoritative check of the
# running daemon is the "GC Policy" section of `docker buildx inspect multiarch`.
if ! docker exec buildx_buildkit_multiarch0 \
grep -q 'maxUsedSpace = "20GB"' /etc/buildkit/buildkitd.toml 2>/dev/null; then
echo "::warning::BuildKit builder 'multiarch' has no managed GC config; cache may grow unbounded. See docs/buildkit-gc.md in SharedWorkflows."
fi
docker buildx inspect multiarch | sed -n '/GC Policy/,$p' || true
- name: Build image for vulnerability scan
if: ${{ inputs.run_image_scan }}
shell: bash