Bootstrapping a build cache that needs its own output
The DNS image for our private PGWs is two lines:
FROM coredns/coredns:1.11.1
EXPOSE 11915/tcp
That is the whole Dockerfile — upstream CoreDNS, pinned (1.11.1, no local patches), on a port of our own choosing (11915, clear of anything else on the host), built so the gateways have a DNS service that exposes metrics the way the rest of the estate does. That is the only reason the image exists. Nothing in it is clever and nothing in it should be. The interesting part was moving it off Jenkins.
The circular dependency
GitHub Actions builds faster when it can pull a previous image as a cache source, and the
cache-from reference points at a tag in the registry (the development tag, red, in our
Makefile). For a repository that has only ever been built by Jenkins, under a different tag
convention, that image is not there — and the job that would create it is the job that is
failing. The build needs its own output to exist before it can run the first time.
What did not work
The first attempt restructured the image to give the cache something to bite on: a multi-stage Dockerfile, then a prod stage alias so the cache lookup had a named target to resolve against. Two commits (multi-stage Dockerfile for GHA build cache bootstrap, then add prod stage alias), both reverted the same afternoon.
Wrong layer. The registry was empty, and no amount of staging inside a two-line image creates an artefact that was never pushed. Adding stages to satisfy a cache lookup is the kind of fix that works once (exactly once) and then confuses everyone who reads it.
What worked
Put Jenkins back, briefly, and let it do the one thing it was still able to do: push.
A Jenkinsfile went back into the repository (tagged red, the development tag the Makefile
already used), pushed exactly one image, and was deleted the same day. With that image
present the cache source resolved, the build succeeded, and the Dockerfile returned to its
two lines. Four commits to break the cycle (bootstrap, revert, revert, delete); the artefact
left behind is a repository with no Jenkinsfile in it.
What it cost
One afternoon (11 February), and a Makefile shorter than it started. Promotion to production followed the next day, so an image that passes in development is promoted instead of rebuilt — which matters more than it sounds, because a rebuilt image is a different image (same Dockerfile, different digest).
The lesson is narrow and worth keeping. A build cache is an optimisation that can block a first build; when it does, seed the registry by whatever means still works (Jenkins, a manual push, anything at all) and take the scaffolding out afterwards. Do not reshape the image to satisfy the cache.