"I pushed the new code" can mean several things. Splitting delivery into build, release and deploy makes it clear what happened and what to undo.
Three stages
- Build: turn source code into an artifact, such as a binary, a package or a container image.
- Release: pick a specific artifact, give it a version and combine it with the settings for a target.
- Deploy: put that release onto servers and start it.
Teams use these words a little differently. Some call publishing a download a "release". Agree on the meaning in your own project.
A small example
Here is the idea using only shell tools. Build once:
mkdir -p app releases
printf '#!/bin/sh\necho "Hello from $APP_ENV"\n' > app/hello.sh
tar -czf releases/hello-1.0.0.tar.gz appDeploy by unpacking into its own directory and pointing a link at it:
mkdir -p deploy/1.0.0
tar -xzf releases/hello-1.0.0.tar.gz -C deploy/1.0.0
ln -sfn 1.0.0 deploy/current
APP_ENV=staging sh deploy/current/app/hello.shHello from stagingThe archive stays the same. Only the setting APP_ENV changes per environment.
Build once, deploy many
Rebuilding for each environment risks getting a different result, for instance because a dependency changed in between. Build one artifact, test it, then promote that same artifact onward. Keep configuration and secrets outside it, supplied by the environment at run time.
With containers
The same stages in Docker terms:
docker build -t registry.example.com/shop:1.4.0 .
docker push registry.example.com/shop:1.4.0
docker run -d --name shop -e APP_ENV=production registry.example.com/shop:1.4.0The first command builds, the second publishes the image to a registry, and the third runs it with settings for this environment. These need a Dockerfile and a registry you can reach, so replace the example name.
Delivery and deployment
Continuous delivery keeps every good change ready to deploy, with a person often choosing when. Continuous deployment goes further and deploys each change that passes the checks automatically.
Try it
Run the shell example. Make a version 1.0.1 with a different message, deploy it beside 1.0.0 and move the current link. Then move the link back. Run ls -l deploy after each step. The files and links lab explains symbolic links.
Check your understanding
Build, Release, and Deploy
All 3 sections · no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.