Why you need it
The tests passed on one build of the app. Then, for production, someone built it again. The new build looked the same but was not: one piece inside had changed. Nobody tested it, and it broke.
Think of it like this
A food inspector checks one sealed jar and puts a sticker on it. The shop must sell that jar, not cook a fresh batch from the same recipe and hope it tastes the same.
Where you’ll find it
- Docker: Every image has a digest, a fingerprint of its exact contents, so you can ship exactly the image you tested.
- GitHub: GitHub Actions saves the built files from one step so later steps use them instead of building again.
- JFrog: Artifactory stores builds and moves the same one from test to production.
What to know first
Continuous integration. Every change is tested with main before it goes in. See Continuous integration.
Build. Turning code into the thing that actually runs: a program, a bundle of files, an image.
Same code, different build. Two builds from the same code can differ, because a build fetches other pieces, and those can change between builds.
How it works
- Building twice is the bug. Build 1 was tested. Production got build 2, made later. Inside it,
chartswas 2.1 instead of 2.0. This is the red tile in the animation. - Build once, and seal it. Build one time and store the result where nobody can change it. That sealed result is an artifact. Give it a name that never moves, like a version number or a fingerprint of its contents.
- Test that artifact. The tests run on the artifact itself, not on a fresh build of the same code. This is the tick sticker in the animation.
- Ship that same artifact. Test, staging and production all take the same artifact by its name. What was tested is what runs.
- Settings stay outside. Production needs different addresses and passwords than test. Those are given to the artifact when it starts, never built into it, so one artifact fits every place.
An example
Monday 10:00: build 1 is made, tested for 20 minutes and passes. It is stored as app-1.
Monday 15:00: a new charts 2.1 comes out. Building again now would quietly pick it up.
Tuesday: production is given app-1, the exact files that passed. The new charts never gets in by accident.
Further reading
- Build, release, run, The Twelve-Factor App. One page on keeping the build apart from the settings and the run. Start with this one.
- Deployment Pipeline, Martin Fowler. How one build moves through stages of testing toward production.
- Automating safe, hands-off deployments, AWS Builders' Library. How Amazon builds once and moves that build through every stage.