Build, deploy and run an application with ECR, ECS and Codebuild (Part 2)
By Yves Denis Deffo
Introduction
This is the second part of our project including ECS, ECR, Codebuild, github actions. You can find the first part here.
This part will focus more on the deployment of our application (its container image), the unit tests executed by Codebuild at each push in github and finally we can test through our web browser if our application responds as expected.
The source code of the whole project : https://github.com/yvesDenis/website-projects-articles/tree/master/deploy-app-aws-ecs
Architecture diagram
The diagram above should be the production status of our infrastructure. Our ECS cluster will be deployed on two private subnets in which will be the autoscaling group , which with the help of a launchTemplate, will instantiate a pair of EC2s which will be the receptacle of the ecs tasks.
Github workflow
Before testing all these beautiful people. One of our goals at the beginning of this project was to stay close to a real-world situation. So we decided to automate our unit tests via Codebuild and the update of our image in the AWS ECR remote repository.
Here’s the diagram of our Gitops pipeline.
AWS has provided a starter GitHub workflow that takes advantage of the AWS open-source GitHub Actions to build and deploy containers on ECS for each commit to master branch of the repository.
This github workflow contains just a single job whose first step is to query the status of unit tests that have been run in codebuild.
Our codebuild project sends unit test status report to Github asynchronously.
Once the unit tests status is positive. Our pipeline, after retrieving temporary credentials, will build our application and build the docker image that will later be pushed into ECR by tagging our image with the commit ID.
The image being present in the repository, we can update the ECS task definition and redeploy the image in ECS.
Integration test
During the first part of this article, we deployed our ECS cluster with the autoscaling group and the application load balancer which is directly connected with the Internet Gateway. To test our application, we will need the domain name of the ALB.
After launching this request via the browser: https://base-app-alb-1758938518-ca-central-1.elb.amazonaws.com/hello
We should get this result:
Conclusion
This project, which was done in two parts, covered the complete production cycle of an application in the cloud. Let me know in the comments what you think 😉