Real-world CodePipeline CI/CD examples

Real-world CodePipeline CI/CD examples

AWS CodePipeline helps us to orchestrate CI/CD pipelines. To implement real-world pipelines, CodePipeline calls additional AWS services to do the work. E.g., CodeBuild to run arbitrary scripts, CloudFormation to create or update stacks, or CodeDeploy to deploy software to running EC2 instances. A pipeline is connected to sources such as a git repository (Bitbucket, GitHub, and GitHub Enterprise Server, CodeCommit), an S3 bucket, or an ECR repository. If a source changes, the pipeline executes.

[wpcc-element _tag=”source” type=”image/webp” srcset=”/images/2021/04/pipeline@730w.webp 730w, /images/2021/04/pipeline@730w2x.webp 1460w, /images/2021/04/pipeline@610w.webp 610w, /images/2021/04/pipeline@610w2x.webp 1220w, /images/2021/04/pipeline@450w.webp 450w, /images/2021/04/pipeline@450w2x.webp 900w, /images/2021/04/pipeline@330w.webp 330w, /images/2021/04/pipeline@330w2x.webp 660w, /images/2021/04/pipeline@545w.webp 545w, /images/2021/04/pipeline@545w2x.webp 1090w” sizes=”(min-width: 1200px) 730px, (min-width: 992px) 610px, (min-width: 768px) 450px, (min-width: 576px) 330px, 545px” _close=”0″]

But how do real-world pipelines look like? In this post, I share pipelines with you, from simple to complex.

Simple but bold pipeline

The following pipeline connects to a GitHub repository. CodeBuild is used to build a Docker image, and CodeBuild is used to push the Docker image and deploy it into production.

[wpcc-element _tag=”source” type=”image/webp” srcset=”/images/2021/04/codepipeline-simple@730w.webp 730w, /images/2021/04/codepipeline-simple@730w2x.webp 1460w, /images/2021/04/codepipeline-simple@610w.webp 610w, /images/2021/04/codepipeline-simple@610w2x.webp 1220w, /images/2021/04/codepipeline-simple@450w.webp 450w, /images/2021/04/codepipeline-simple@450w2x.webp 900w, /images/2021/04/codepipeline-simple@330w.webp 330w, /images/2021/04/codepipeline-simple@330w2x.webp 660w, /images/2021/04/codepipeline-simple@545w.webp 545w, /images/2021/04/codepipeline-simple@545w2x.webp 1090w” sizes=”(min-width: 1200px) 730px, (min-width: 992px) 610px, (min-width: 768px) 450px, (min-width: 576px) 330px, 545px” _close=”0″]

This pipeline comes with several disadvantages:

  1. It runs no unit tests
  2. It runs no acceptance tests in a pre-prod environment

Manual acceptance testing

The following pipeline excerpt shows a pipeline where manual acceptance tests prevent bugs from reaching production. Not perfect, but better than before!

[wpcc-element _tag=”source” type=”image/webp” srcset=”/images/2021/04/codepipeline-pre-prod@730w.webp 730w, /images/2021/04/codepipeline-pre-prod@730w2x.webp 1460w, /images/2021/04/codepipeline-pre-prod@610w.webp 610w, /images/2021/04/codepipeline-pre-prod@610w2x.webp 1220w, /images/2021/04/codepipeline-pre-prod@450w.webp 450w, /images/2021/04/codepipeline-pre-prod@450w2x.webp 900w, /images/2021/04/codepipeline-pre-prod@330w.webp 330w, /images/2021/04/codepipeline-pre-prod@330w2x.webp 660w, /images/2021/04/codepipeline-pre-prod@545w.webp 545w, /images/2021/04/codepipeline-pre-prod@545w2x.webp 1090w” sizes=”(min-width: 1200px) 730px, (min-width: 992px) 610px, (min-width: 768px) 450px, (min-width: 576px) 330px, 545px” _close=”0″]

We could still do better by running automated acceptance tests, right?

The following video goes into details and includes demos:

  • CodePipeline 101
  • Real-world CodePipeline examples
  • Demo: marbot pipeline
  • Pitfall: Update pipeline in pipeline

[wpcc-iframe class=”embed-responsive-item lozad” data-src=”https://www.youtube-nocookie.com/embed/MNt2HGxClZ0″ allow=”accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture” allowfullscreen=””]

Phased rollout

My last example shows a pipeline excerpt that AWS uses to deploy parts of CodePipeline itself. You can see how new changes are rolled out in phases—starting with a single region to lower the risk.

[wpcc-element _tag=”source” type=”image/webp” srcset=”/images/2021/04/codepipeline-phased@730w.webp 730w, /images/2021/04/codepipeline-phased@730w2x.webp 1460w, /images/2021/04/codepipeline-phased@610w.webp 610w, /images/2021/04/codepipeline-phased@610w2x.webp 1220w, /images/2021/04/codepipeline-phased@450w.webp 450w, /images/2021/04/codepipeline-phased@450w2x.webp 900w, /images/2021/04/codepipeline-phased@330w.webp 330w, /images/2021/04/codepipeline-phased@330w2x.webp 660w, /images/2021/04/codepipeline-phased@545w.webp 545w, /images/2021/04/codepipeline-phased@545w2x.webp 1090w” sizes=”(min-width: 1200px) 730px, (min-width: 992px) 610px, (min-width: 768px) 450px, (min-width: 576px) 330px, 545px” _close=”0″]

I used a similar approach in a pipeline to deploy an environment per customer (the application was missing multi-tenant capabilities).

Summary

CodePipeline is the pipeline orchestrator. CodePipeline calls other AWS services to implement a CI/CD pipeline.