DevOps, CI/CD and IaCVol. 8 · Part VIII
0 / 0

Shelves / DevOps, CI/CD and IaC

DL·00

Start Here: How Code Reaches Production

For readers who have written and committed code but never shipped it: the path from a commit to running software, a five-step delivery pipeline run for real (test, build, publish, deploy, verify) that ships one commit and stops another, the vocabulary of the volume, and how to study it.

8 topics · ~5 min read · 10-question quiz
Updated Suggest a correction

Start here: how to use this volume

Two reading paths

This volume is about delivery: how a change goes from a developer's editor to users safely, quickly and repeatably. Git, CI/CD pipelines, infrastructure as code, GitOps and release engineering. Every chapter has the same shape: a plain-language Start here section with small, verified experiments; a How deep to go ladder; the full-depth sections; a Lab of real measurements; and a Revision sheet.

  • New to delivery? Read this chapter, then the chapters in order. Run the experiments: they need Git, Docker and a small Kubernetes (the volume uses k3s 1.37 from Volume 6), plus OpenTofu 1.13 with the AWS provider pointed at the moto emulator from Volume 7.
  • Experienced? Skip this chapter. In each chapter read the revision sheet first, take its quiz, then use How deep to go to choose the sections and lab experiments to study.

Mastery levels

Every chapter uses the same six levels:

Level Name You can… Example for CI/CD
L1 Recognition define it and spot it "that's a build stage producing an artifact"
L2 Working use it correctly write a pipeline that tests, builds and deploys
L3 Internals explain why it works explain caching, runners, artifacts and promotion
L4 Debugging diagnose failures find why a pipeline is slow, flaky or deployed the wrong thing
L5 Design choose between approaches design pipelines and environments for many teams
L6 Production run it at scale operate a delivery platform with security and DORA metrics

The path from a commit to production

What happens after git commit

On a team, a commit isn't "done" when it compiles on your machine. It's done when it's running in production, observed to work, and could be undone if it didn't. In between sits a delivery pipeline: an automated sequence of steps, each of which can stop the change:

  1. Integrate: the change is pushed to a shared repository and merged with everyone else's (Git, chapter 92).
  2. Test: automated checks run on every change (unit tests, linters, security scans).
  3. Build: the code becomes an artifact (a container image, a JAR, a package) named so it can be traced to its commit.
  4. Publish: the artifact is stored in a registry, unchanged from here on.
  5. Deploy: the artifact is rolled out to an environment (Volume 6's strategies), and infrastructure changes are applied as code (chapter 94) or reconciled from Git (chapter 95).
  6. Verify: smoke tests and monitoring confirm it works; if not, roll back.
  7. Release: users get the change, perhaps gradually or behind a feature flag, with a version number and a changelog (chapter 96).

A pipeline, run for real

Here is a five-step pipeline for the tiffin service, written as a shell script so every step is visible. Each step must succeed before the next runs. The first commit changes the API:

Text
commit a37c906: feat: report menu version
1 test (go vet, go test)          ok      0.9 s
2 build image tiffin:a37c906      ok     20.6 s
3 publish (import to cluster)     ok      0.3 s
4 deploy (rolling update)         ok      1.7 s
5 verify (smoke test via Service) ok      0.8 s
total                                    24.3 s

Twenty-four seconds from commit to verified in the cluster. The image is named after the commit (tiffin:a37c906), so anyone can tell exactly which code is running. The next commit changes the tax rate, but forgets the test that documents the old rule:

Text
commit d4d4821: fix: apply 18% GST
1 test (go vet, go test)          FAIL    0.7 s
   | --- FAIL: TestPriceWithTax (0.00s)
   |     main_test.go:7: priceWithTax(100) = 118, want 105
$ kubectl get deploy shop -o jsonpath='{…image}'
tiffin:a37c906

The pipeline stopped in under a second, nothing was built or deployed, and production kept running the previous commit. That's the whole point: every change passes the same gates, automatically, and a failing change can't reach users. Maybe the test was right and the code wrong, or the rule really changed and the test needs updating; either way, a human decides with full information, before customers see wrong prices.

Real pipelines run on CI services (GitHub Actions, GitLab CI, Jenkins, TeamCity, Buildkite) that run steps in clean environments, in parallel, with caches, secrets and approvals, and record everything (chapter 93).

Measuring delivery

The DORA research programme found four metrics that separate high-performing teams from others:

Metric Measures Elite teams (DORA reports)
Deployment frequency How often you deploy to production On demand, many times a day
Lead time for changes Commit to running in production Less than a day
Change failure rate Deployments causing a failure needing remediation Low (around 5–15%)
Time to restore service Recovering from a failed change or incident Less than an hour

Speed and stability turn out not to be a trade-off: teams that deploy small changes often also fail less and recover faster, because each change is small, tested and easy to undo.

How to study delivery

A routine that works

  1. Automate one step at a time: tests on every push first, then builds, then deployments.
  2. Break the pipeline on purpose: failing tests, flaky tests, missing secrets, bad deploys; then read the logs.
  3. Keep everything in Git: application code, pipeline definitions, infrastructure and deployment manifests.
  4. Measure: pipeline duration, flakiness and the four DORA metrics.

Warm-up exercises

  1. Run git log --graph --oneline --all on a real project and explain each branch and merge.
  2. Write a three-step pipeline for a project of yours as a shell script, like the one above.
  3. Look up how your team's last production change got there: who approved it, what ran, how long it took.
  4. Name the artifact your pipeline produces and how you'd find which commit it came from.

Glossary

  • Commit: a recorded snapshot of the project with a message and parent(s).
  • Pipeline: an automated sequence of stages run on each change.
  • Artifact: the built, versioned output of a pipeline (image, package, binary).
  • Environment: a place the software runs (development, staging, production).
  • Continuous integration (CI): merging and testing changes frequently, automatically.
  • Continuous delivery / deployment (CD): always deployable / deploying automatically.
  • Infrastructure as code (IaC): infrastructure defined in versioned files.
  • GitOps: Git as the source of truth for what runs, reconciled automatically.
  • Release: making a change available to users, with a version.