If a pipeline runs docker build again on the way to production, then the
thing you tested in staging and the thing customers get are two different
builds that you are hoping are identical. Usually they are. The interesting
days are the ones where a base image moved, or a dependency was republished
under the same version, and now production is running code that never passed
a test.
This repo is a working pipeline built around the opposite rule: an image is produced exactly once, and every environment after that receives that image.
The problem it solves
Two habits cause most of the trouble, and they are both about who decides to ship.
The first is rebuilding per environment, which breaks the chain of evidence
between “tested” and “deployed”. The second is treating a merge to main as
a deployment — which means a routine code review becomes a release decision,
and nobody can answer “what is in production?” without reading commit history.
How it works
Walking the path:
- Merging to
mainruns tests and nothing else. No image, no rollout. - A draft release accumulates instead, with the next semantic version worked out from the labels on the pull requests that were merged.
- Publishing that draft is the decision to ship. It is a person clicking a button, and it is what cuts the version tag.
- The image is built once, from the tag itself rather than from
main— by the time a release is published,mainmay have moved on. - Staging gets it automatically, through a reusable deploy workflow that every environment shares, so there is one rollout path to read instead of six.
- Production promotes. It dispatches that same deploy workflow with the image reference that already exists, behind a GitHub Environment with a required reviewer. There is no build step on this arrow at all.
Steps 4 and 6 are the point. Because the build workflow returns the image reference as an output, promotion can pass the exact artefact forward rather than reconstructing a name and hoping it matches.
The design, stated in the repo’s own words
The clearest expression of it is a comment at the top of the workflow:
# Production is deliberately not here. It promotes an image this workflow
# already built and staging already ran, so it dispatches deploy.yml directly
# with no build at all.
The approval is not a conditional somebody can forget — it is the environment itself, so the job simply waits:
# Production has a required reviewer on its GitHub environment, so the job
# waits here for approval. Dev and staging have no protection rules.
environment:
name: ${{ inputs.environment }}
What the repo is honest about
There is no cluster behind this repository, so the Argo CD sync calls print
what they would do rather than doing it, and the deploy job resolves a
nonprod/prod runner pool without a self-hosted pool to route to. What is
real is everything the design rests on: the reusable workflows, the
environment gate holding production until someone approves, and the image
reference being handed from build to deploy untouched.
All six workflows are in the repo.