Simple GitHub Simulated Shell Build Simulated Deployment AWS CodePipeline Pipeline: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Simple GitHub - Simulated Shell Build - Simulated Deployment Pipeline= {{Internal|Simple GitHub - Simulated Shell Build - Simulated Deployment Pipeline|Simple GitHub - Simul...")
 
 
(76 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Simple GitHub - Simulated Shell Build - Simulated Deployment Pipeline=
=Internal=


{{Internal|Simple GitHub - Simulated Shell Build - Simulated Deployment Pipeline|Simple GitHub - Simulated Shell Build - Simulated Deployment Pipeline}}
* [[AWS_CodePipeline_Operations#Simple_GitHub_-_Simulated_Shell_Build_-_Simulated_Deployment_Pipeline|AWS CodePipeline Operations]]
 
=Overview=
 
This article documents an example of a simple [[AWS_CodePipeline_Concepts#Pipeline|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=
 
{{External|[https://github.com/ovidiuf/aws/tree/master/release-pipeline GitHub Release Pipeline Example]}}


==Prerequisites==
==Prerequisites==


* The example requires a GitHub repository to be available. We'll use https://github.com/ovidiuf/aws-pipeline-source-example.
* The example requires a GitHub repository to be available. We'll use https://github.com/ovidiuf/aws-pipeline-source-example. The repository contains [[AWS CodeBuild Buildspec|buildspec]] metadata, that drives the build, and a CloudFormation deployment-stack.yml stack template, which will drive the deployment.
* The CodeBuild and CodePipeline service roles must be created in advanced and referred from the CloudFormation stack specification by their ARN. I tried creating them as part of the same stack, but I got: "CodeBuild is not authorized to perform: sts:AssumeRole on ...". If they exist when the stack creation is attempted, it works. <Font color=darkgray>TODO: try to declare them in the same stack, experiment with dependencies, try to make this work.</font>


==Procedure==
==Procedure==


The CodePipeline pipeline, the delegate CodeBuild project, required service roles and the S3 bucket to keep the artifacts produced by the pipeline will be created as part of one CodeFormation stack:
===<span id='CodeFormation_Stack'></span>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:
 
{{External|[https://github.com/ovidiuf/aws/blob/master/release-pipeline/release-pipeline-template.yaml release-pipeline-template.yaml]}}
 
<syntaxhighlight lang='bash'>
aws cloudformation create-stack \
  --stack-name thalarion-release-pipeline \
  --template-body file://./release-pipeline.yml \
  --capabilities CAPABILITY_NAMED_IAM \
  --parameters ParameterKey=GitHubPersonalAccessCode,ParameterValue=...
</syntaxhighlight>
 
There is a convenience script that assembles the aws cloudformation command line:
 
<syntaxhighlight lang='bash'>
./create-release-pipeline --project-id=thalarion --github-repository=aws-release-pipeline --github-organization=ovidiuf --github-access-code=... --nlb-host=http://test.com
</syntaxhighlight>
 
===Buildspec===
 
The GitHub repository should expose a [[AWS_CodeBuild_Buildspec#Overview|builspec.yml]] in root. A simple example is available here: {{Internal|AWS_CodeBuild_Buildspec#Example|buildspec.yml Example}}
 
aws-release-pipeline example: {{External|[https://github.com/ovidiuf/aws/blob/master/beryllium/buildspec.yaml buildspec.yaml]}}
 
===CloudFormation Deployment Stack Template===
 
aws-release-pipeline example: {{External|[https://github.com/ovidiuf/aws/blob/master/beryllium/deployment.yaml 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:


<syntaxhighlight lang='yaml'>
<syntaxhighlight lang='yaml'>
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
</syntaxhighlight>
=Removal=
To remove the pipeline, and implicitly the project stack deployed by the pipeline:
<syntaxhighlight lang='bash'>
./delete-release-pipeline --project-id=thalarion
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 23:13, 5 April 2019

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