Many organizations have been shifting adopting to DevOps practices, which is the combination of cultural philosophies, practices, and tools that increases your organization’s ability to deliver applications and services at high velocity; for example, evolving and improving products at a faster pace than organizations using traditional software development and infrastructure management processes.
This Quick Start deploys a continuous integration and continuous delivery (CI/CD) pipeline on the Amazon Web Services (AWS) Cloud in about 15 minutes, to automatically test AWS CloudFormation templates from a CodeCommit repository.
It creates stacks in multiple AWS Regions simultaneously and generates a report with a pass/fail grade for each region. You can specify the regions, indicate the number of Availability Zones you want to include in the test, and pass in the AWS CloudFormation parameter values you want to test. You can use the CI/CD pipeline to test any AWS CloudFormation templates, including nested templates, from a CodeCommit repository.
Title: AWS ECS-Fargate with CI/CD
Challenges:
- It is difficult to manage code locally, so a Code Commit is used for the management of different branches.
- Container images are managed by the AWS code repository.
- The whole network configuration is done using a cloud formation template.
- All the required configuration details can be mentioned in the cloud formation template.
- The manual process of deployment was updated to cloud formation automation.
- Restricted Roles and policies are assigned to the containers for accessing different services using cloud formation.
Architecture:
Solution Overview:
- Code commit repository was created using cloud formation.
- Aws ECR was also created using cloud formation with unique tags and the container images were pushed using code build.
- Custom VPC and its related resources (subnets, Internet gateway, route tables, Nat gateway) were created using a cloud formation template.
- Fargate cluster, task definition, and service is created using cloud formation template.
- The application load balancer and target groups were also launched using a cloud formation template.
- Developer services(Code commit, code build, code pipeline) were also implemented using cloud formation.
- Fargate alerts were also implemented using cloud formation.
Steps:
1)Create VPC Using CloudFormation.
→ Create Cloud Formation stack using VPC Template. Goto cloud formation service on console and create the stack.
→ Add stack parameters as enter the stack name and choose the parameters as CIDR, VPC…
→ You can see parameters stack details as given and then click on create the stack.
→ Then wait to execute cloud formation template, once stack comes in Create_Complete state.
2) Create ALB SecurityGroup Using Cloudformation.
→ Specify the stack name as ALB-SG and parent stack name as VPC and then click on next to start creating the security group.
3) Create ALB Using Cloud formation
→ Launch the cloud formation template for the creation of Application Load Balancer and check the details of the template.
→Specify the stack details as stack name, VPC environment name, and port.
→ Once the process gets complete of cloud formation, we will have ALB ready.
4) Create a Fargate cluster using Cloud formation.
→ Launch the cloud formation template for creating of Fargate cluster and check the details of the template.
→ Enter your parameter
→ Wait to complete cloud formation
5) create an AWS Fargate service using cloud formation.
→ Launch the cloud formation template for creating Fargate services and check the details of the template.
→ Check your created ALB endpoint
→ Check your clusters and task is running or not.
Source stage. When a commit is made into the source branch of the CodeCommit repository, it triggers the CI/CD pipeline. The repository contents are pulled, zipped, and stored in an S3 bucket.
6) create an AWS code commit Repo using cloud formation
→ Launch the cloud formation template for creating of CodeCommit repo and check the details of the template.
→ Enter your parameter
→ Wait to complete CloudFormation
→ Clone your repo to your system.
→ Install git and clone your created repo on your system.
→ Create an AWS ECR repository
→ Create buildspec.yaml and upload your code commit repository.
A buildspec is a collection of build commands and related settings, in YAML format, that CodeBuild uses to run a build. You can include a buildspec as part of the source code or you can define a buildspec when you create a building project. For information about how a build spec works
→ Verify your docker file and buildspec.yaml push on your code commit.
→ Create your own Dockerfile and upload your CodeCommit repo branch to build your custom container images.
7) create an AWS CodePipeline using cloud formation
→Launch the cloud formation template for creating of CodePipeline and check the details of the template.
→ Check created pipeline is running or not.
→ The old task is deleted and the new task deployed.
→ Check your cloud formation complete.
→ Wait to complete your pipeline execute
Build/test stage. CodeBuild creates a Linux container, installs Nginx and its dependencies in the container, downloads the zipped file that contains the source code from the S3 bucket, unpacks it, and runs tests using ALB endpoint that is uploaded to the S3 bucket. If the tests are successful, the deploy stage is triggered.
Deploy stage. CodePipeline runs a Lambda function that merges the source branch of the CodeCommit repository into the release branch. The code is now ready to deploy from the CodeCommit repository.
→ Check your ALB endpoint working.
→ All cloud formation temple execute properly
Result:
Using the cloud formation template above listed services setup can be done in all the AWS regions without involving any human interaction.
Costing:
The above setup will cost less than $10 per day for the resources allotted.
Reference Links:
https://github.com/kkpkishan/AWSFargate-CF/blob/master/Pipeline.yml
https://github.com/kkpkishan/AWS-SecurityGroup/blob/master/client-sg.yaml
https://github.com/kkpkishan/AWSFargate-CF/blob/master/ingress/alb-external.yml
https://github.com/kkpkishan/AWSFargate-CF/blob/master/cluster/cluster-fargate.yml
https://github.com/kkpkishan/AWS-codecommit/blob/master/create-repo.yaml
https://github.com/kkpkishan/CI-CD-php-fpm-nginx-container-AWS/blob/master/buildspec.yml