The image lifecycle, end to end

The image lifecycle as one loop, build, record, test, promote, deploy, monitor, revoke and rebuild, and a pipeline that joins Git, CI, Packer, HCP Packer webhooks, HCP Terraform and the cloud.

GazeekTERRAFORM AND PACKER: INFRASTRUCTURE AS CODE·LESSON 23
LESSON 23

The image lifecycle, end to end

The image lifecycle as one loop, build, record, test, promote, deploy, monitor, revoke and rebuild, and a pipeline that joins Git, CI, Packer, HCP Packer webhooks, HCP Terraform and the cloud.

0:00 / 3:41

Diagrams in this video · 2Free in archhy

Copy and edit in archhy: Eight stages, one loop (new tab)
Copy and edit in archhy: The image lifecycle pipeline (new tab)

After this lesson you can

  • Name the eight stages of the image lifecycle in order
  • Describe a pipeline that builds, tests and promotes images automatically
  • Explain how HCP Packer webhooks connect the registry to other tools
  • Explain why regular rebuilds keep images patched
Transcript

The image lifecycle, end to end

Space Llama here. We've met every piece. Packer, the registry, channels, revocation, and Terraform reading images. Today we put them in a circle, and let the machines push each other round it.

Eight stages, one loop

The image lifecycle has eight stages. Build the image with Packer. Record its metadata in HCP Packer, on the HashiCorp Cloud Platform. Test it. Promote it, by moving a channel. Deploy it, with Terraform. Monitor it, for new vulnerabilities and old age. When something's wrong, revoke it. Then rebuild, with the fix, and you're back at the start. It never really ends. Which is good news for job security.

The image lifecycle pipeline

Here's that loop as a pipeline. A platform engineer changes the Packer template and pushes it to Git. That triggers CI, continuous integration. It runs packer init, validate and build, which creates a new AMI, an Amazon Machine Image, and records it in HCP Packer. Then CI tests the image. Boot it, check the software, run a security scan. If it passes, the pipeline assigns the new version to a channel. First dev, and later production. HCP Packer fires a webhook when a channel is assigned. Your automation catches it, and starts a run in the HCP Terraform workspace. That run reads the channel, and rolls the new image out to the servers. Every arrow here is automated. People review the changes, and approve the move to production.

Testing an image

The test stage is what turns an image into a golden image. Boot a temporary server from the new image. Check that it starts cleanly, and that the services you baked in are running. Scan it for known vulnerabilities. Only if everything passes does the pipeline move the channel. A failed test means the version never reaches production.

Webhooks join the dots

Webhooks are how the registry tells other tools that something happened. HCP Packer sends them for version events. A version completed, revoked, restored or deleted. Also when a version is assigned to a channel, and when a revocation is scheduled or cancelled. Moving a channel doesn't start a Terraform run on its own. The webhook is your cue to start one. A webhook is just an HTTP call to an address you choose, such as a small function, or your CI system.

Monitor, revoke, rebuild

Now the other half of the loop. A vulnerability is announced in your base image. You revoke that version, and its descendants can inherit the revocation. A revoke webhook can tell your team, and kick off a rebuild with the patched packages. The new version is tested and promoted like any other. Many teams also rebuild on a schedule, say weekly, so images never get too old, even when nothing's on fire.

Recap

Let's recap. The lifecycle is build, record, test, promote, deploy, monitor, revoke, rebuild, and round again. CI runs Packer, tests the image, and the registry records it. Moving a channel promotes the image, and Terraform deploys it. Webhooks connect the steps. And when something's wrong, revoke, rebuild, and go again.

Practice and what's next

That's the image lifecycle, end to end. A pipeline that bakes, checks and ships its own images. Next lesson, the last one: What's next. See you there.

Gazeek Flash · free

Exam questions on your phone

Free questions on The image lifecycle, and what's next: quick-fire batches and timed exams, on the web or Android.