What you will learn in this TP
- Apply "build once, deploy many"
- Deploy blue/green with a smoke test
- Roll back instantly
Introduction #
What you will learn in this section
- Apply "build once, deploy many"
- Deploy blue/green with a smoke test
- Roll back instantly
Context. Releases cause ten minutes of downtime and a rollback takes an hour. You set up a scripted blue/green deployment that a pipeline can use as is.
Prerequisites: Docker and Git installed on your machine · Estimated time: 45 min
A zero-downtime switch and a rollback in seconds.Hands-on #
Guided steps, with their solution.
1. Build and version the image
Why? The image is built once and identified by the commit SHA; the version is never overwritten.
Create a small application that shows its version (read from an environment variable), build theshop:v1image and start a local registry to publish it.2. Set up the router
Why? The router is the only thing changed to switch: both versions run side by side.
Create a Docker network, start thebluecontainer and an nginx whoseupstream.conffile points to blue.3. Write the deployment script
Why? An idempotent script is what a pipeline will call: start the idle colour, test, switch, or abort.
Writedeploy.sh IMAGE VERSION: it starts the idle colour, smoke-tests/health, switches nginx withnginx -s reloadon success, or removes the new container and fails otherwise.4. Deploy v2 without downtime
Why? A request loop during the deployment proves there is no downtime.
In a second terminal, query the router in a loop. Deploy the image withVERSION=v2(same image, different configuration) and watch the switch.5. Block a faulty version
Why? The smoke test is the gate: a broken version never receives traffic.
Deploy a v3 whose health check fails (BROKEN=1). The script must fail with a non-zero code and v2 must stay live.6. Roll back
Why? With blue/green, the old version is still there: rolling back is a simple switch.
Manually switch the router back to the previous colour, check, then clean up.
Difficulty level : ●●●○○ (3/5)
My progress
Sign in to track your progress and take notes. Sign in
Recommended Articles
CI/CD de bout en bout (3/5) : artefacts, registres et environnements
Livrer en continu : artefacts immuables et versionnés, registres d'images et de paquets, promotio...
CI/CD de bout en bout (4/5) : stratégies de déploiement et retour arrière
Déployer sans interruption et sans risque : recreate, rolling update, blue/green, canary, feature...