Simple GitHub Simulated Shell Build Simulated Deployment AWS CodePipeline Pipeline

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

Internal

Overview

This article documents an example of a simple pipeline that is created with a CloudFormation template, reads code from a GitHub repository, applies a trivial "build" transformation and "deploys" the final artifacts via a CloudFormation project-embedded stack.

Example

GitHub Release Pipeline Example

Prerequisites

Procedure

CodeFormation Release Pipeline Stack

All required AWS resources (roles, the CodePipeline pipeline, the delegate CodeBuild project, the S3 bucket to keep the artifacts produced by the pipeline and the ECR repository that will hold images produced by the project) will be created as part of one CodeFormation stack:

release-pipeline-template.yaml
aws cloudformation create-stack \
  --stack-name thalarion-release-pipeline \
  --template-body file://./release-pipeline.yml \
  --capabilities CAPABILITY_NAMED_IAM \
  --parameters ParameterKey=GitHubPersonalAccessCode,ParameterValue=...

There is a convenience script that assembles the aws cloudformation command line:

./create-release-pipeline --project-id=thalarion --github-repository=aws-release-pipeline --github-organization=ovidiuf --github-access-code=... --nlb-host=http://test.com

Buildspec

The GitHub repository should expose a builspec.yml in root. A simple example is available here:

buildspec.yml Example

aws-release-pipeline example:

buildspec.yaml

CloudFormation Deployment Stack Template

aws-release-pipeline example:

deployment.yaml

The GitHub repository should expose a CloudFormation deployment stack template, which will be used by CloudFormation in the "deploy" stage of the pipeline to perform the deployment. This is a simple example:

AWSTemplateFormatVersion: '2010-09-09'

Description: "CloudFormation deployment template, will drive the deployment as part of this project's release pipeline."

Parameters:

  #
  # these must be set in the deployment stack configuration file, produced by a prior pipeline step, or by the "ParameterOverrides" configuration.
  #

  BuildBucket:
    Type: String

  MyConfigurationParameterA:
    Type: String

  MyConfigurationParameterB:
    Type: String

Resources:

  ServiceLogGroup:
    Type: AWS::Logs::LogGroup
    Properties:
      LogGroupName: !Sub '/playground/${MyConfigurationParameterA}-${MyConfigurationParameterB}'
      RetentionInDays: 1

Removal

To remove the pipeline, and implicitly the project stack deployed by the pipeline:

./delete-release-pipeline --project-id=thalarion