paint-brush
Services Stack — with CI/CD for your Infrastructure and Codeby@rgfindley
1,832 reads
1,832 reads

Services Stack — with CI/CD for your Infrastructure and Code

by Randy FindleyJanuary 5th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Back in October I posted the <a href="https://hackernoon.com/the-services-stack-235cca4a15f7" target="_blank">Services Stack</a>. The <a href="https://hackernoon.com/the-services-stack-235cca4a15f7" target="_blank">Services Stack</a> is a collection of CloudFormation templates, to create a microservices application on AWS. If you haven’t seen it already please go check it out.

Coin Mentioned

Mention Thumbnail
featured image - Services Stack — with CI/CD for your Infrastructure and Code
Randy Findley HackerNoon profile picture

Wouldn’t it be great to just check in your infrastructure and code changes and they get deployed automatically?

Back in October I posted the Services Stack. The Services Stack is a collection of CloudFormation templates, to create a microservices application on AWS. If you haven’t seen it already please go check it out.

After posting the Services Stack I got a lot of great feedback, mostly all good ;). Turns out what was missing was Continuous Integration and Continuous Deployment (CI/CD).

I’ve gone back and added these features and am happy to share them with you today. And without further delay, here is the code…


thestackshack/services-stack-cicd_services-stack-cicd - ECS microservices stack with built-in CI/CD_github.com

Pipelines

Everything is a pipeline

I use CodePipeline to continuously update all the CloudFormation stacks, build the code, and deploy the code. There is a pipeline for the application and one for each service.

Take a look at this diagram and then we’ll go into more details below:

Application Pipeline

The application pipeline creates the application specific stacks (i.e. nothing service related) and then bootstraps each of the service pipelines.

The application pipeline is initially created via the command line. It then executes every time a commit is pushed.

The application pipeline consists of the following stages:

  1. Notifications Stage
  2. VPC Stage
  3. ECS Stage
  4. Services Stage

Notifications Stage

The notifications stage contains two actions. The first action creates a CloudFormation stack with resources to notify the user about DevOps events like build status, deployment status, etc…The second action executes a CodeBuild to test and deploy a Lambda function within the previous stack, always keeping it fresh.

VPC Stage

The VPC stage contains one action. A CloudFormation stack that sets up a VPC for our application.

ECS Stage

The ECS stage contains one action. A CloudFormation stack that sets up an ECS Cluster with EC2’s and an ALB.

Services Stage

The Services stage contains an action for each microservice. Each action is a CloudFormation stack that creates the pipeline for that service.

Service Pipeline

The service pipeline creates the service specific stack, performs the code build, and finally the code deployment.

Each service pipeline is executed on every code push to that specific service.

The service pipeline consists of the following stages:

  1. ECR & CodeBuild Stage
  2. Service Stage

ECR & CodeBuild Stage

The ECR & CodeBuild stage has two actions.

The ECR action simply creates an ECR repository for our Docker images.

The CodeBuild action first builds the code, then pushes the image to ECR.

Service Stage

The Service stage has a single action which is a CloudFormation stack for all the service related resources. The newly created ECR image from the previous stage is used when creating the ECR task, thereby deploying the latest changes. A specific version can be used if one wishes to deploy manually.

Environments

Two environments are supported, sandbox and production. Sandbox is triggered off the `develop` branch and production is triggered off the `master` branch.

Conclusion

Infrastructure is just as important as Code. Putting both through CI/CD is the best practice. I hope you like this stack. Please clap if you do (or don’t).