I have taken sample nodejs source code with Docker file from https://docs.docker.com/get-started/02_our_app/ and create CI/CD pipeline with GitLab CI.
We are using Terraform for infrastructure provisioning on AWS and you can find terraform script inside terraform directory. I have use default VPC and subnets for our app. Terraform script will provision the below resources:
- ECS cluster
- ECS task definition
- ECS services
- Load balancer
- LB listener
- Target group
- security groups
- IAM role for task
You can find GitLab CI/CD configuration in .gitlab-ci.yml file. We assume we have the below keys configured as an environment variables before pipeline execution
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_DEFAULT_REGION
- In the first stage we have include Code-Quality.gitlab-ci.yml template which checks code quality on merge request and generate a report. here is the reference. https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html
- In the second stage, we are building docker image, log in on AWS ecr and push docker image.
- In the third stage, we are provisioning AWS resources with terraforming. before apply to terraform we also validate terraform script and need manually trigger before apply.
- the Last stage is to notify the slack channel by triggering the webhook URL.
Future enhancement:
- We can write scripts for customizing messages on different pipeline statuses.
- Create a multitier architecture for securing our app deployment.
- Configure blue/green deployment for ECS service.