Build once, promote through environments
Build an artifact once, then move those exact bytes from test to staging to production, with configuration supplied by each environment rather than baked in.
Build artifacts and artifact repositoriesContinuous delivery vs continuous deployment
Build once, promote through environments
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Rebuilding for each environment means production runs bytes that were never tested, because builds pull in new dependency versions, timestamps and toolchain changes.
- Build once in the pipeline, store the artifact, and promote that same artifact through each environment, checking its digest at every step.
- Keep environment-specific configuration, such as database URLs, feature settings and secrets, outside the artifact, and inject it at deploy time.
- Promotion should be gated: an artifact moves to production only if the same digest passed the earlier environments.
- Environments differ in data, scale and configuration. Build once removes one source of difference, which makes the others easier to find.
You tested one thing and shipped another
A common pipeline looks like this. On merge, build and test. To deploy to staging, check out the commit and build again with staging settings. To deploy to production, check out the commit and build again with production settings. It feels tidy. Each environment gets its own build.
It means production runs an artifact nobody tested. Between the staging build on Monday and the production build on Thursday:
- A transitive dependency published a patch release, and your lockfile allowed it, or you had no lockfile.
- The CI runner image was updated with a new compiler.
- The build embedded a different timestamp, path or random ordering.
The artifacts lesson showed that even packing the same two files twice gave different sha256 digests. Usually the differences are harmless. When they aren’t, you get a bug that staging could never have caught, and the investigation starts by assuming the code is the same when it isn’t.
Build once, promote the bytes
The fix is a rule from Continuous Delivery: build the artifact once, and promote that exact artifact through every environment.
- The commit stage builds the artifact, tags it with version and commit, records its digest, and stores it in the artifact repository.
- Deploying to test, then staging, then production fetches the stored artifact. Nothing is compiled after step 1.
- Each promotion checks that the digest is the one that passed the previous environment.
Think of a shipping container. It is sealed at the factory, and each port checks the seal number against the manifest. Nobody unpacks it and repacks it at each port.
Configuration comes from the environment
The objection is “but production needs different settings”. It does. It needs a different database URL, different credentials, perhaps a different log level. Those must not be baked into the artifact, or you are back to one artifact per environment.
The twelve-factor app answer is to read configuration from the environment at start-up: environment variables, a mounted config file, or a secret store. The artifact is identical everywhere. The environment around it is what differs. Environment variables and secrets across layers covers the practical side, including frontend builds, where configuration is often compiled in and needs extra care.
A promotion you can run
I built a tiny app once: an app.py that prints its version, environment and database URL, packed with its VERSION file into repo/shop-1.5.0.tgz. Each environment had only an env file:
# envs/staging/env
APP_ENV=staging
DATABASE_URL=postgres://db.staging.internal/shop
The core of promote.sh checks the digest, unpacks the stored artifact, and runs it with that environment’s settings:
digest=$(shasum -a 256 "$art" | cut -c1-12)
if [[ $env == production ]] && ! grep -q "^$digest passed$" envs/staging/verified 2>/dev/null; then
echo "refused: sha256:$digest has not passed staging"; exit 1
fi
rm -rf "envs/$env/app" && mkdir "envs/$env/app" && tar -xzf "$art" -C "envs/$env/app"
( cd "envs/$env/app" && set -a && . ../env && set +a && python3 app.py )
Trying production first, then staging, then recording that staging passed, then production again:
$ ./promote.sh 1.5.0 production
refused: sha256:4f41586d6e64 has not passed staging
exit=1
$ ./promote.sh 1.5.0 staging
shop 1.5.0 env=staging db=postgres://db.staging.internal/shop
staging now runs sha256:4f41586d6e64
$ ./promote.sh 1.5.0 production
shop 1.5.0 env=production db=postgres://db.prod.internal/shop
production now runs sha256:4f41586d6e64
Same digest in both environments, different configuration. Then I did what the rebuild-per-environment pipeline does. I touched app.py without changing its content and rebuilt shop-1.5.0.tgz in place:
$ ./promote.sh 1.5.0 production
refused: sha256:4c2ecd45fa7d has not passed staging
exit=1
The version still said 1.5.0, but the bytes were different, because macOS tar records each file’s modification time, and the gate caught it. That is why the gate checks the digest, not the version string. In a real system the “passed” record would live in the pipeline or the artifact repository’s metadata, not a text file, and the repository would refuse to overwrite 1.5.0 at all.
Environments still differ
Build once removes one difference between staging and production: the code. Others remain, and they are where production-only bugs now come from:
- Configuration values, such as a timeout set differently in production.
- Data: production has ten million rows and odd legacy records, staging has a tidy sample.
- Scale and traffic: concurrency bugs that only appear under load.
- Infrastructure versions: a database or kernel a minor version apart.
Keeping environments as alike as possible, with infrastructure defined as code, narrows this further. Environments, domains and TLS shows one app’s set of environments.
Container images make build once natural. You build the image once, push it to a registry, and deploy it by digest. Registries, tags and image provenance covers that in the containers group.
About the video
The embed is a 10-minute clip from Thetips4you’s “Build Once, Deploy Many: The Artifact Rule” (September 2026, 29 minutes in full). By its chapters, the clip covers “The rebuild trap”, “Demo 2: promote the exact same bytes”, and “Digests, provenance, and attestations”. Its description says rebuilding between staging and production can quietly replace the exact bytes you already verified, which is this lesson’s argument. The earlier chapters on what an artifact is overlap the previous lesson and are skipped. I had no transcript, so this is from the title, description and chapters. YouTube lists the video’s original audio as English. Krish Dinesh’s 12-minute talk on the same rule, from an enterprise QA-to-UAT-to-production angle, is under deeper.
Where this fits
You can now put a known artifact into production. The next lesson is about how it replaces the old version without downtime: deployment strategies: rolling, blue-green and canary.
Check yourself
Your pipeline runs npm install and builds separately for staging and production from the same commit. What could go wrong?
A dependency could publish a new version between the two builds, or the build could pick up a different toolchain, so production gets different code from what staging tested. Bugs then appear in production that staging could never have caught.
Where should a production database URL live, and why not in the artifact?
In the production environment's configuration or secret store, injected at deploy time. If it were baked in, you would need a different artifact per environment, which breaks build once, and the secret would be in every copy of the artifact.
How does a promotion gate know the artifact going to production is the one that passed staging?
It compares the content digest, such as sha256, of the artifact being deployed with the digest recorded when staging passed. A version number alone is not enough, because a rebuilt artifact can carry the same version.
Build once is in place, but a bug still appears only in production. Where do you look?
At what still differs: configuration values, data volume and shape, traffic, infrastructure versions and integrations with third-party services. The code is ruled out, which narrows the search.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.