B. Blue Green a software delivery tutorial
Vol. I § Zero-downtime series § A series for junior developers
Zero-downtime delivery · 6 / 10 ·

The playbook only touches the idle slot

This is the longest chapter of the series — rightly so, because the playbook is where every previous chapter meets. It never stops the live slot. It reads state.json, picks the opposite of live, and renders compose for that slot only.

Six taught steps

  1. Read state. The first deploy pretends the other slot is live so the first step stays deterministic.
  2. Check the target port. If another process holds it, stop.
  3. Pull the image and start the idle slot.
  4. Run the health check.
  5. Patch the Caddy route.
  6. Stop the old slot and write the new state.
Slot playground · idle-deploy
readerCaddy :8080blue :18080 · upgreen :18081 · down
Blue is serving. Green is empty.
  1. Blue is serving. Green is empty.
  2. The playbook pulls the image onto the idle slot. Blue still answers.
  3. Green is healthy and still hidden from readers.
diff · compose
services:
  titikterang:
    image: registry.titikterang.local:5000/titikterang:v1.2.3
    ports:
      - "8080:3000"
services:
  titikterang-green:
    image: registry.titikterang.local:5000/titikterang:v1.2.4-dev
    ports:
      - "127.0.0.1:18081:3000"
explainer · compose
Explanation

This is the green slot. Caddy may still point at blue until the check passes.

Quick recap

  • The playbook works only on the idle slot; the live slot is untouched until the health check passes.
  • A port the playbook does not own means the deploy stops — never a force kill.
  • After compose down, always verify with docker ps.
  • state.json is read at the start and rewritten at the end — never halfway.

The playbook sketch lives in examples/titikterang/ansible.

Reader notes

Chapter discussion appears once Giscus is connected to the site repository.