16 CI/CD in the cloud with Docker and GitHub Actions
This chapter presents a practical, portable approach to building a fast CI/CD pipeline powered by Docker and orchestrated with GitHub Actions. The emphasis is on repeatability, speed, and the ability to migrate between providers with minimal rework. Multi-stage Dockerfiles handle compilation and unit tests, Docker Compose models the application for integration checks, and GitHub Actions provides Linux and Windows runners for multi-platform builds. Most logic lives in scripts (PowerShell) rather than provider-specific actions, so the same steps can run locally for quick feedback and in the cloud for automation.
The pipeline starts with a fail-fast Continuous Integration stage: multi-stage Docker builds compile components and run unit tests in a dedicated test stage, and a simple workflow executes the same script used locally. Successful builds proceed to package images and push them to a staging repository in GitHub Container Registry, using layered Compose files and environment variables to centralize image naming, tagging, and labeling with build metadata. Staging runs on Linux first and then Windows, conserving time when failures occur. End-to-end smoke tests use Compose to bring up the full app, verify basic behavior, and tear it down, supporting both local debugging and cloud execution with the same scripts.
With confidence established, the pipeline promotes exact, tested images from staging to a release repository by retagging (not rebuilding), preserving reproducibility. The final step simulates production deployment by creating an ephemeral Kubernetes cluster on the runner and applying a Helm chart, validating the model and images together. Workflows chain from source changes through build, package, test, release, and deploy, with Linux and Windows stages running appropriately in parallel. Key guidance underpins the design: do as much as possible in Docker, keep everything else in portable scripts, support both developer and operations workflows, and minimize provider-specific features—yielding a robust, reproducible CI/CD pipeline that is easy to extend and migrate.
Verifying you have all the tools you need for this chapter
Forking the repo for the chapter creates a copy in your own GitHub account.
Scripting Docker images builds which include compiling code and running unit tests
Proving the build script fails if there's a failing unit test in the source code
Triggering a build in GitHub which uses logic in the PowerShell script
Triggering a GitHub action by pushing changes and fixing the build
The full multi-platform CI/CD pipeline we will build out in this chapter
The next build stage is a script that builds and tags image for a staging repository.
Pushing the workflow files triggers the Linux action run.
GitHub Actions gives you a multi-platform build farm in the cloud—for free.
Pulling a workflow-built image from GitHub Container Registry
Running smoke tests to prove the application starts and runs
Running smoke tests on Linux and Windows in GitHub
Tagging the staging images and pushing them to the release repository
Simulating a production deployment by deploying to a local Kubernetes cluster
The full CI/CD pipeline, triggered from a change to the source code.
Lab
One thing missing from this super-duper CI/CD pipeline is that we build images for different platforms, but we don't publish them as a set of multi-platform images. You can push manifest lists to GHCR, so this lab gets you to do that final step:
- Write a script which creates and pushes a manifest list for each of the three components in this chapter's app.
- Each manifest list should contain Linux and Windows variants for the Intel (AMD64) CPU architecture.
- Your script should follow the same approach as the others, using Compose files as the source of image references.
- When you've tested your script locally, write a GitHub Actions workflow to run the script.
My solution is in the lab folder of the ch16 repo. The documentation is in the README file, which even has pictures to prove that the solution works: https://github.com/diamol2e/ch16/blob/main/lab/README.md.
Learn Docker in a Month of Lunches, Second Edition ebook for free