RousselTMLEARNING

TP · DevOps: From Discovery to Expertise

Lab: Image promotion and blue/green deployment

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. 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 the shop:v1 image and start a local registry to publish it.
  2. 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 the blue container and an nginx whose upstream.conf file points to blue.
  3. 3. Write the deployment script

    Why? An idempotent script is what a pipeline will call: start the idle colour, test, switch, or abort.

    Write deploy.sh IMAGE VERSION: it starts the idle colour, smoke-tests /health, switches nginx with nginx -s reload on success, or removes the new container and fails otherwise.
  4. 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 with VERSION=v2 (same image, different configuration) and watch the switch.
  5. 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. 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

  • ⏱ Estimated time : ≈ 45 min

Sign in to track your progress and take notes. Sign in

✉️ Ask a question

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...