/oui-docs-cdk

This is the automation code for creating the infrastructure required for CI/CD of OUI documentations website

Primary LanguageTypeScriptApache License 2.0Apache-2.0

made-with-TypeScript

About

This is code sample that uses CDK to:

  • Create a Pipeline Template to Deploy
  • Create a Lambda that creates multiple pipelines using existing pipeline template for all the release branches
  • triggerOnPush: true Controls automatically starting your exisiting pipeline when a new commit is made on the configured repository and branch.

⚡️ Quick Start

In short :

First, you will need to install the AWS CDK:

$ npm install -g aws-cdk

Install the required dependencies:

$ npm install

At this point you can build and then synthesize the CloudFormation template for this code.

$ npm run build
$ cdk synth

If you haven't already you'll need to deploy the CDK Bootstrap stack. This only needs to be ran once per account/region

$ cdk bootstrap

If everything looks good, go ahead and deploy!

$ cdk deploy

Synthesize CloudFormation Template

To see the CloudFormation template generated by the CDK, run cdk synth, then check the output file in the "cdk.out" directory.

CDK Stack has following resources

  • S3
  • Cloudfront
  • OriginAccessIdentity
  • Cloudfront Function
  • Codepipeline
  • Lambda
  • Eventbridge
  • Codebuild
  • IAM

CodePipeline Template

  • Source : Connect with GitHub, pull the code from latest/main branch
  • Build : Build doc-site to docs folder
  • PreDeploy Lambda : Empty S3 directory
  • Deploy : Deploy to S3
  • PostDeploy Lambda : Invalidate CloudFront cache

Cron Lambda

  • Run periodically & create new pipeline from codePipeline-template above for each release branch.

CDK Toolkit

The cdk.json file in the root of this repository includes instructions for the CDK toolkit on how to execute this program.

After building your TypeScript code, you will be able to run the CDK toolkits commands as usual:

$ cdk ls
<list all stacks in this program>

$ cdk synth
<generates and outputs cloudformation template>

$ cdk deploy
<deploys stack to your account>

$ cdk diff
<shows diff against deployed stack>

Useful commands

  • npm run build compile typescript to js
  • npm run watch watch for changes and compile
  • npm run test perform the jest unit tests
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk synth emits the synthesized CloudFormation template