enricopesce / AWSome-pipeline

A stable and fully supported continuous delivery service for AWS ECS Fargate implemented with AWS CDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AWSome Pipeline

Example how with AWS CDK you can deploy a continuous delivery pipeline using AWS CodePipeline, AWS CodeBuild and AWS Fargate. I have included all the best practices with a strong focus on the KISS principle. The infrastructure code is written in TypeScript. The infrastructure is a sidecar with Nginx as proxy and a Flask "hello world" application on Gunicorn

Folder structure

code
docker
infrastructure

code directory

dedicated to Flask code

docker directory

dedicated to Docker definitions: sidecard of Nginx + Gunicorn

infrastructure directory

dedicated to AWS CDK infrastructure definition

Installation and requirements

cd infrastructure

### Install the CDK framework

npm install -g aws-cdk

Install the dependencies

npm install

### Authenticate in your AWS account:

Follow this guide: Configuring the AWS CLI

Configure GitHub Token

Create a personal access token in GitHub and store it in AWS SecretsManager. Needed to configure your repo webhooks.

aws secretsmanager create-secret \
    --name my_secret_token \
    --secret-string yourtokenhereyourtokenhere \
    --region eu-west-1

Usage

The first step is to exporting the AWS variables to obtain the rights:

export AWS_PROFILE="profilename"
export AWS_DEFAULT_REGION="eu-west-1"

Configuring the application

edit the app_config.json file for defining the project name and the existing VPC

{
    "PROJECT_NAME": "awsome",
    "VPC_NAME": "default"
}

Deploy the pipeline an get the codepipeline endpoint

You can create a continuous integration service bonded to your current git branch.

Suppose that you are in the master branch:

git branch --show-current
master

You can create the pipeline triggerable from any commit to master branch:

cdk deploy "*" --context tier=pipeline

 ✅  awsome-master-pipeline

Outputs:
awsome-master-pipeline.LinkCodePipelinePage = https://eu-west-1.console.aws.amazon.com/codesuite/codepipeline/pipelines/awsome-master-pipeline-PipelineC660917D-11U99LG5Y4H4V/view?region=eu-west-1

The pipeline after the creation and by every commits in the branch will be triggered. It launches the staging env, after a manual approval, the production env.

Alternatively you can deploy staging env directly without passing by codepipeline and get the staging http endpoints:

cdk deploy "*" --context tier=stg

 ✅  awsome-master-stg-app

Outputs:
awsome-master-stg-app.fargateLoadBalancerDNSB13ECB0B = awsom-farga-1KNVPTS0GNV8J-XXXXXXXXX.eu-west-1.elb.amazonaws.com
awsome-master-stg-app.LinkEcsClusterPage = https://eu-west-1.console.aws.amazon.com/ecs/home?region=eu-west-1#/clusters/awsome-master-stg-app-cluster611F8AFF-okLxuoDdfc1o/fargateServices
awsome-master-stg-app.LinkCLoudWatchDashboard = https://eu-west-1.console.aws.amazon.com/cloudwatch//home?region=eu-west-1#dashboards:name=awsome-dashboard-stg-app
awsome-master-stg-app.fargateServiceURL145CCBE8 = http://awsom-farga-1KNVPTS0GNV8J-XXXXXXXXX.eu-west-1.elb.amazonaws.com

or you can deploy the production env and get the production http endpoints:

cdk deploy "*" --context tier=prd
 ✅  awsome-master-prd-app

Outputs:
awsome-master-prd-app.fargateLoadBalancerDNSB13ECB0B = awsom-farga-1KNVPTS0GNV8J-XXXXXXXXX.eu-west-1.elb.amazonaws.com
awsome-master-prd-app.LinkEcsClusterPage = https://eu-west-1.console.aws.amazon.com/ecs/home?region=eu-west-1#/clusters/awsome-master-prd-app-cluster611F8AFF-okLxuoDdfc1o/fargateServices
awsome-master-prd-app.LinkCLoudWatchDashboard = https://eu-west-1.console.aws.amazon.com/cloudwatch//home?region=eu-west-1#dashboards:name=awsome-master-prd-app
awsome-master-prd-app.fargateServiceURL145CCBE8 = http://awsom-farga-1KNVPTS0GNV8J-XXXXXXXXX.eu-west-1.elb.amazonaws.com

Customize the application code

You can customize the code inside the docker/code directory

PLEASE GIVE ME FEEDBACKS

OPEN A GITHUB ISSUE FOR FIX OR REQUEST

About

A stable and fully supported continuous delivery service for AWS ECS Fargate implemented with AWS CDK

License:Apache License 2.0


Languages

Language:TypeScript 85.7%Language:JavaScript 10.3%Language:Dockerfile 3.1%Language:Python 0.9%