Skip to content

ansible: cap Docker BuildKit cache at 3GB after every build#88

Open
magent-cryptograss wants to merge 1 commit into
cryptograss:productionfrom
magent-cryptograss:cap-docker-build-cache
Open

ansible: cap Docker BuildKit cache at 3GB after every build#88
magent-cryptograss wants to merge 1 commit into
cryptograss:productionfrom
magent-cryptograss:cap-docker-build-cache

Conversation

@magent-cryptograss

Copy link
Copy Markdown
Contributor

Why

delivery-kid's BuildKit cache grew to 28 GB across 337 entries on 2026-05-30 and took the host to 100% disk, killing the next deploy at the Install required packages task with the unhelpful `Failed to update apt cache: unknown reason`.

Root cause: every `--rebuild` deploy runs `docker compose build --no-cache`, and `--no-cache` bypasses cache use but still creates new BuildKit cache entries. With no prune step in the playbook, those entries accumulate forever. The same pattern existed in hunter's base-image rebuild and pickipedia-vps's wiki build — both would have hit this eventually.

What

A new `docker builder prune -f --keep-storage 3GB` task right after every build site:

Location Insertion point
`delivery-kid/ansible/playbook.yml` After Start services
`hunter/ansible/roles/build-image/tasks/main.yml` After Verify image was built
`pickipedia-vps/ansible/roles/docker-wiki/tasks/main.yml` After Build wiki Docker image
`pickipedia-vps/ansible/roles/docker-wiki/handlers/main.yml` Chained inline in Rebuild wiki container

Flag choices

  • `-f` (force, no `-a`) — prunes dangling cache only. Active layers (i.e. cache entries reusable by the current image) stay so the next cached build is still fast.
  • `--keep-storage 3GB` — hard ceiling on total cache, regardless of dangling status. Even if every entry were "active" by Docker's reckoning, this caps growth.
  • No `when:` gate — runs on every deploy. When cache is already under 3GB the task is essentially a no-op.

Test plan

  • Deploy delivery-kid with `--rebuild` — confirm task runs and `/var/lib/docker` doesn't grow unbounded
  • Deploy hunter — confirm build cache stays bounded across rebuilds
  • Re-deploy pickipedia-vps — confirm the after-build prune runs
  • Verify `docker system df` on each host after a clean deploy: build cache should be ≤ 3GB

Followup (out of scope here)

The dedup check in `pickipedia_client.py` is dead code due to `snapshot_at` always changing — flagged in #87 review. Worth a separate small PR.

delivery-kid's BuildKit cache grew to 28GB across 337 entries (2026-05-30)
and took the host to 100% disk, killing the next deploy at the
"Install required packages" task with an unhelpful "Failed to update
apt cache: unknown reason".

Root cause: every --rebuild deploy runs `docker compose build --no-cache`,
and --no-cache bypasses cache *use* but still adds new BuildKit cache
entries. With no prune step, those entries accumulate forever. The
same pattern existed in hunter's base-image rebuild and pickipedia-vps's
wiki build.

Add a `docker builder prune -f --keep-storage 3GB` task right after
each build site:
- delivery-kid playbook: after Start services
- hunter build-image role: after Verify image was built
- pickipedia-vps docker-wiki tasks: after Build wiki Docker image
- pickipedia-vps docker-wiki handlers (Rebuild wiki): chained inline

-f (no -a) prunes dangling cache only, so active layers stay reusable
for the next deploy. --keep-storage caps total cache at 3GB regardless
of dangling status — a hard ceiling that can't be defeated by however
many builds run between deploys.

Idempotent: when cache is already under 3GB, the task is essentially
a no-op (returns quickly with nothing to prune).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants