The DevOps and CI-CD Picture Book
plan code build test release deploy operate monitor DevOps shorten the loop · automate the boring parts · learn from production
PLATE 0 — Build, ship, watch, learn, repeat. The faster and safer the loop, the better the product.
A picture book for grown-ups · with pipelines

DevOps and CI/CD

Nine spreads on getting code from a laptop to production safely and often: pipelines, testing, releases, infrastructure as code, configuration, GitOps and monitoring.

Say it like a pro

"Every merge triggers a pipeline that tests, builds an immutable artifact, and promotes it through environments with automated checks and a rollback."

Use the tabs or the ← → keys.

Dev Ops shared ownership · "you build it, you run it" The four DORA metrics: speed and stability Deploy frequencyhow often you ship Lead timecommit → production Change failure ratedeploys that cause trouble Time to restorehow fast you recover elite teams do all four well: small changes ship faster and break less
PLATE 1 — Speed and stability aren't opposites. Small, frequent releases improve both.
Chapter 1 · The idea

Culture first, tools second

  • Shared ownership: the team that builds a service helps run it.
  • Automate repeatable work: builds, tests, deploys, provisioning.
  • Small batches: many tiny changes are easier to review, test and roll back than one giant release.
  • Fast feedback: tests in minutes, alerts in seconds.
  • Blameless learning: fix systems, not people.
CI
continuous integration: merge often, build and test every change automatically
CD
continuous delivery (always releasable) / deployment (every green change goes live)
IaC
infrastructure described in version-controlled code
SRE
reliability treated as an engineering discipline, with error budgets
toil
manual, repetitive work that should be automated
# a quick personal measure: lead time of the last 10 commits on main
$ git log main -10 --format='%h %ad %s' --date=short
$ gh run list --limit 10                 # recent pipeline runs: how often green? how long?
Say it like a pro

"We track deploy frequency, lead time, change failure rate and time to restore, and we aim to shrink batch size."

push / PR install+cache lint unit tests SAST/deps build artifact Good pipelines are… fast (under ~10 min): cache dependencies, run jobs in parallel, test only what changed deterministic: pinned versions, lockfiles, no "works on my machine" fail-fast: cheap checks (lint, types) before slow ones the same on your laptop and in CI (containers, make/just scripts) Build once, deploy many the artifact tested is the exact artifact promoted: never rebuild per environment config differs by environment · the code and image do not
PLATE 2 — Every change runs the same gauntlet before anyone trusts it.
Chapter 2 · Continuous integration

A pipeline in GitHub Actions

# .github/workflows/ci.yml
name: ci
on:
  push: { branches: [main] }
  pull_request:
permissions: { contents: read }
concurrency: { group: ci-${{ github.ref }}, cancel-in-progress: true }

jobs:
  test:
    runs-on: ubuntu-latest
    strategy: { matrix: { node: [20, 22] } }
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: "${{ matrix.node }}", cache: npm }
      - run: npm ci
      - run: npm run lint
      - run: npm test -- --coverage
      - run: npm run build
      - uses: actions/upload-artifact@v4
        with: { name: dist, path: dist }

  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm audit --audit-level=high
      - uses: gitleaks/gitleaks-action@v2
runner
the machine that executes jobs (hosted or self-hosted)
matrix
run the same job across versions or platforms
secrets
stored encrypted in the CI system; pin third-party actions to a commit SHA
other tools
GitLab CI · Jenkins · CircleCI · Azure Pipelines · Buildkite
Say it like a pro

"Cached, parallel, least-privilege pipelines that fail fast and produce one immutable artifact."

E2E · few integration · some unit · many, fast Gates before production tests ✔ · coverage floor ✔ · lint/types ✔ · dependency + secret scan ✔ · image scan ✔
PLATE 3 — Cheap checks first. Expensive checks only for what survives.
Chapter 3 · Quality gates

Automated confidence

  • Branch protection: require PRs, a review, and passing checks before merge to main.
  • Test in layers: many fast unit tests, fewer integration tests against real services (containers), a few end-to-end flows.
  • Kill flaky tests: a test that sometimes fails teaches people to ignore red builds.
  • Shift security left: dependency, secret, SAST and container scans in the pipeline.
  • Pre-merge environments: a preview deployment per pull request.
# integration tests against a real database in CI
services:
  postgres:
    image: postgres:16
    env: { POSTGRES_PASSWORD: test }
    ports: ["5432:5432"]
    options: >-
      --health-cmd "pg_isready" --health-interval 5s --health-retries 10
$ trivy image myapp:1.0 --severity HIGH,CRITICAL --exit-code 1   # fail the build on serious CVEs
$ trivy fs . ; gitleaks detect ; semgrep --config auto .
$ pre-commit install                      # run checks before each commit, locally
Say it like a pro

"Protected main, layered tests against real services, and security scans as required checks."

Blue-green blue v1 (live) green v2 flip the router, keep blue to roll back Canary v1 · 95%v2 5% watch errors, then grow Rolling new → new → old → old Make releases boring feature flags: deploy dark, release by switch, instant kill backward-compatible database migrations (expand → migrate → contract) automatic rollback on failed health checks or error-rate spikes
PLATE 4 — Never flip everything at once. Expose change gradually and watch.
Chapter 4 · Continuous delivery

Releasing without drama

# deploy job: runs only on main, uses an environment with approvals
deploy:
  needs: [test, scan]
  if: github.ref == 'refs/heads/main'
  runs-on: ubuntu-latest
  environment: production            # require a reviewer in repo settings
  permissions: { id-token: write, contents: read }    # OIDC: no long-lived cloud keys
  steps:
    - uses: actions/checkout@v4
    - uses: docker/login-action@v3
      with: { registry: ghcr.io, username: "${{ github.actor }}", password: "${{ secrets.GITHUB_TOKEN }}" }
    - uses: docker/build-push-action@v6
      with: { push: true, tags: "ghcr.io/${{ github.repository }}:${{ github.sha }}" }
    - run: kubectl set image deploy/web web=ghcr.io/${{ github.repository }}:${{ github.sha }}
    - run: kubectl rollout status deploy/web --timeout=120s || kubectl rollout undo deploy/web
immutable tags
deploy by commit SHA or digest, never latest
expand/contract
add the new column, ship code that uses both, backfill, then remove the old: no downtime
progressive delivery
Argo Rollouts / Flagger automate canaries with metric checks
Say it like a pro

"Immutable image by SHA, canary with automated analysis, feature flags, and one-command rollback."

git repo Terraformcreate resources Ansibleconfigure them Provision vs configure Terraform / OpenTofu / Pulumi: networks, VMs, databases, DNS (declarative) Ansible / cloud-init / Packer: packages, files, services, golden images Prefer immutable over patching in place bake an image (or container) and replace instances instead of SSHing in Secrets and config Vault / cloud secrets managers · SOPS for encrypted files in git · never plain text in repos 12-factor: config from the environment, the same artifact everywhere detect drift: `terraform plan` on a schedule should show no changes
PLATE 5 — If it isn't in code, it can't be reviewed, repeated, or restored.
Chapter 5 · Infrastructure & configuration as code

Servers you can rebuild from a repo

# ansible/site.yml
- hosts: web
  become: true
  tasks:
    - name: Install nginx
      ansible.builtin.apt: { name: nginx, state: present, update_cache: true }
    - name: Deploy config
      ansible.builtin.template: { src: nginx.conf.j2, dest: /etc/nginx/nginx.conf, mode: "0644" }
      notify: reload nginx
    - name: Ensure running
      ansible.builtin.service: { name: nginx, state: started, enabled: true }
  handlers:
    - name: reload nginx
      ansible.builtin.service: { name: nginx, state: reloaded }
$ ansible-playbook -i inventory.ini site.yml --check --diff    # dry run: what would change?
$ ansible-playbook -i inventory.ini site.yml
$ terraform fmt -check && terraform validate && terraform plan -out tf.plan
$ terraform apply tf.plan
$ packer build image.pkr.hcl                  # bake a machine image
idempotent
running it twice leaves the same result: the property that makes automation safe
state
Terraform's record of what exists; store remotely, with locking
policy as code
OPA / Sentinel / Checkov block risky changes in the pipeline
Say it like a pro

"Terraform for resources, baked images over in-place patching, idempotent playbooks, and a scheduled plan to detect drift."

app repo CI config repodesired state pull Argo CD / Fluxinside the cluster Kubernetes Git is the source of truth deploy = merge a PR · rollback = revert a commit · audit trail for free
PLATE 6 — The cluster pulls its state from git and keeps itself matching it.
Chapter 6 · Containers & GitOps

Deploy by pull request

# argocd Application: "keep this cluster path in sync with that git path"
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata: { name: web, namespace: argocd }
spec:
  project: default
  source: { repoURL: https://github.com/acme/deploy-config, targetRevision: main, path: apps/web/prod }
  destination: { server: https://kubernetes.default.svc, namespace: web }
  syncPolicy:
    automated: { prune: true, selfHeal: true }     # remove deleted resources, undo manual drift
    syncOptions: [CreateNamespace=true]
$ kubectl kustomize apps/web/prod | kubectl diff -f -    # preview a change
$ argocd app sync web ; argocd app history web ; argocd app rollback web 12
$ helm template web ./chart -f values-prod.yaml | kubectl apply --dry-run=server -f -
# CI's last step: bump the image tag in the config repo (a commit), instead of running kubectl directly
push vs pull
pipelines pushing with cluster credentials vs an in-cluster agent pulling: smaller attack surface
environments
one folder or branch per env (dev, staging, prod) with promotion by PR
Kustomize / Helm
reuse manifests with per-environment overlays or templates
Say it like a pro

"GitOps: CI updates the config repo, Argo reconciles the cluster, and a rollback is a git revert."

alert ack triage mitigate resolve review Error budget 99.9% SLO = 43 min/month allowed. Budget left → ship faster. Budget gone → focus on reliability. Page on symptoms, not causes alert: "5xx above 2% for 5 min" ✔ · "CPU 81%" ✘ (unless it hurts users) every page has a runbook · every incident has an owner and a timeline post-mortem asks "what let this happen?", never "who did this?"
PLATE 7 — Shipping fast is only safe if you notice trouble fast and recover faster.
Chapter 7 · Monitoring & incidents

See it, fix it, learn from it

# docker-compose.monitoring.yml (local stack: metrics + dashboards)
services:
  prometheus:
    image: prom/prometheus
    volumes: ["./prometheus.yml:/etc/prometheus/prometheus.yml"]
    ports: ["9090:9090"]
  grafana:
    image: grafana/grafana
    ports: ["3001:3000"]
# alert rule: users are seeing errors
- alert: HighErrorRate
  expr: sum(rate(http_requests_total{status=~"5.."}[5m])) / sum(rate(http_requests_total[5m])) > 0.02
  for: 5m
  labels: { severity: page }
  annotations: { runbook: "https://wiki.acme/runbooks/high-5xx", summary: "5xx > 2%" }
SLI / SLO / SLA
the measure / the target / the contract
MTTR
mean time to recover: usually improved by fast rollback and good runbooks, not by more alerts
tools
Prometheus · Grafana · Loki · OpenTelemetry · Sentry · PagerDuty / Opsgenie
  1. Mitigate first (roll back, flip the flag, scale up), then investigate.
  2. Communicate: a status page and regular updates.
  3. Write the post-mortem with timeline, impact, contributing factors, and tracked actions.
Say it like a pro

"Alerts on SLO burn with runbooks attached, mitigate before diagnosing, and blameless reviews that produce tracked fixes."

commitsecrets builddeps+SAST packageimage scan sign+ SBOM deploypolicy rundetect Supply-chain basics pin and verify dependencies · lockfiles · private registry/proxy · minimal base images SBOM (what's inside) · signed images (cosign) · provenance (SLSA) Least privilege everywhere short-lived credentials via OIDC · separate dev/prod accounts · scoped tokens containers: non-root, read-only filesystem, drop capabilities, network policies Fail the build on… leaked secrets · critical CVEs with a fix · IaC misconfig (public bucket, open 0.0.0.0/0) track exceptions with an owner and expiry date
PLATE 8 — Security checks belong in the pipeline, not in a meeting at the end.
Chapter 8 · DevSecOps

Secure by default, automatically

$ gitleaks protect --staged                           # pre-commit: block secrets
$ trivy fs --scanners vuln,secret,misconfig .      # deps, secrets, IaC in one go
$ trivy image --severity HIGH,CRITICAL --exit-code 1 myapp:1.0
$ checkov -d infra/                               # Terraform/K8s misconfigurations
$ syft myapp:1.0 -o spdx-json > sbom.json           # software bill of materials
$ cosign sign --yes ghcr.io/acme/myapp@sha256:…     # sign the image
$ cosign verify ghcr.io/acme/myapp@sha256:… --certificate-identity-regexp '.*' --certificate-oidc-issuer https://token.actions.githubusercontent.com
SAST / DAST / SCA
scan source / probe the running app / scan third-party components
Dependabot / Renovate
automated update PRs so dependencies don't rot
admission control
Kubernetes policy (Kyverno, OPA Gatekeeper) rejects unsigned or privileged workloads
Say it like a pro

"Secrets, dependency, image and IaC scans gate the build, artifacts are signed with an SBOM, and the cluster only admits signed images."

PR + CI review merge image+sign dev staging tests approve canary → prod watch · rollback Build the habit in this order 1 · everything in git · 2 · CI on every PR · 3 · containerize 4 · auto-deploy to a test environment · 5 · IaC for the infrastructure 6 · monitoring + alerts + runbooks · 7 · progressive delivery 8 · security scans and signing · 9 · measure DORA, then improve one thing Certifications and practice Docker/K8s (CKA, CKAD) · AWS/Azure DevOps · Terraform Associate · GitHub Actions
PLATE 9 — One path from a commit to production, with checks you trust at every step.
Chapter 9 · Putting it together

A starter project to practise on

  1. Create a tiny web app and a Dockerfile. Run it locally.
  2. Add a GitHub Actions workflow: lint, test, build the image, push to GHCR on main.
  3. Provision a small cluster or VM with Terraform (a lab you can destroy).
  4. Deploy with Argo CD from a separate config repo.
  5. Add Prometheus and Grafana, plus one alert and a runbook.
  6. Break it on purpose (bad deploy, killed pod, full disk). Practise rollback and write a post-mortem.
$ make help                           # give humans and CI the same entry points
.PHONY: test build deploy
test:   ; npm ci && npm test
build:  ; docker build -t myapp:$(shell git rev-parse --short HEAD) .
deploy: ; ./scripts/deploy.sh $(ENV)
read next
"Accelerate" (DORA research) · "The Phoenix Project" · Google's SRE book · "Continuous Delivery" (Humble & Farley)
Say it like a pro

"Small changes, automated checks, immutable artifacts, GitOps promotion, and monitoring that tells us before users do."