Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.
Lu Hong edited this page Oct 14, 2019 · 6 revisions

Continuous Integration (CI) and Continuous Deployment (CD) are a critical part of ensuring quality in an application. CI checks are automated builds that kick off to verify new changes before they are accepted and merged into the master branch. CD is a fully automated process of deploying new changes on the master branch to test and production environments.

Although the Quick Start provides a single template that deploys all of the components together, in a real world environment, each component has their own independent CD pipeline. This keeps the component stacks loosely coupled from one another, allowing different deployment strategies to be used for each. For example, you should configure the backend pipeline to deploy changes slowly and gradually to production stages in order to minimize blast radius of any potential bad changes. However, you would likely want to configure the ops pipeline to deploy faster so alarm or dashboard updates can be applied quickly.

The following sections describe how CI/CD are setup for this serverless application via AWS CodeBuild and AWS CodePipeline, as well as how you can install this same CI/CD setup on a fork of this repository in your own account.

CI

Serverless application aws-sam-codebuild-ci is used to setup CI for this GitHub repository using AWS CodeBuild. You can follow the steps in the README of aws-sam-codebuild-ci to setup CI for your GitHub repository or your fork of realworld-serverless-application repository.

aws-sam-codebuild-ci application creates an AWS CodeBuild project. The project runs the build commands specified in buildspec.yaml that compile and run unit tests for the project when a PR is created or when a commit is pushed to master branch.

In GitHub, a branch rule is configured on the master branch to ensure a PR can't be merged until the AWS CodeBuild project passes. This ensures PRs merged to master build successfully.

You can also see the AWS CodeBuild Badge on the README file that shows the build status of master branch. This helps give visitors to your repository confidence of the quality of the code committed to the master branch.

CD

Serverless application aws-sam-codepipeline-cd is used to setup CD for this GitHub repository using AWS CodePipeline. See the README of aws-sam-codepipeline-cd for details on how to use it.

In this repository, aws-sam-codepipeline-cd is used as a nested application in a template.yaml file under the sam/cicd folder for each component. Each component has its own CD pipeline for deployment that is created by the cicd template. Since there is a separate pipeline for each component, deployments to components are independent and can happen in parallel. This can reduce the impact of a production deployment.

When a change is pushed to the master branch, the CD pipeline for the component automatically builds the code based on buildspec.yaml(example) in the component, run integration tests for the component based on buildspec-integ-tests.yaml(example) in the component if applicable and deploy the component.

CI/CD Setup

To see the CI/CD for this project in action, deploy the CI/CD template for a component into your account and setup CD for your fork of realworld-serverless-application by following these steps:

  1. Create a fork of realworld-serverless-application by clicking the Fork button on the top-right of the repository page.
  2. Create a GitHub OAuth token by following the instructions here
  3. Run the following AWS CLI command to save your GitHub OAuth token in AWS Secrets Manager
aws secretsmanager create-secret --name GitHubOAuthToken --secret-string <your github oauth token>
  1. Run the following AWS CLI command to deploy the CICD template into your account and setup CD for your fork of realworld-serverless-application. can be backend, ops, static-website or analytics
aws cloudformation deploy --template-file <component>/sam/cicd/template.yaml --capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND --stack-name <your-stack-name> --parameter-overrides GitHubOwner=<your github name>

Once the CD pipeline is created, whenever you push changes to your fork of realworld-serverless-application, the CD pipeline will automatically build and deploy your changes.

The CI/CD templates for each component can be found here: