Your pipeline builds the service image in the staging job, runs the integration suite against it, then builds the image again in the production job from the same commit SHA and deploys that. Both builds pass. Why would I still reject this design?
- Two builds of the same commit are not guaranteed to be identical (floating base-image tags, dependency ranges resolved at build time, timestamps), so what was tested in staging is not provably what ships; build once, push by digest, and promote that digest. The artifact, not the source commit, is the unit of promotion; only an immutable digest carries the test evidence forward.
- Rebuilding is fine because the commit SHA pins everything the build depends on. A source SHA pins your code, not an unpinned FROM tag, a
^1.2dependency range, or whatever the package mirror serves that minute. - Rebuilding is required because production needs different environment variables baked into the image. Environment-specific configuration belongs at runtime (env, config maps, secrets), precisely so one artifact can run everywhere.
- The only problem is cost: the second build wastes CI minutes. The cost is real but incidental; the design flaw is provenance — the production artifact has no test evidence attached to it.
Two builds of the same commit can differ, so build the image once and promote the same digest to production.
Promotion means the bytes that passed tests are the bytes that serve traffic. A container build is not a pure function of the source commit: FROM node:20 resolves to whatever that tag points at today, npm install without a lockfile resolves ranges, and some tools embed build timestamps. Building once, pushing by digest (repo@sha256:…), and passing that digest to every later stage turns "we tested this commit" into "we tested this artifact". Environment differences are injected at deploy time, never baked in.
Answering 'cost' or 'time'. The waste is incidental; the flaw is provenance: production runs bytes that carry no test evidence, and 'roll back to the previous prod image' has no exact answer.