Deploy Infrastructure and Code in just a Click!
This repository is a complete implementation of a CI-CD pipeline. Everytime a push happens to the repository a new build is triggered via GitHub Actions.
-
FastAPI : To build an app.
-
Terraform : To implement infrastructure as a code.
-
AWS EC2 : To create a docker environment and run docker containers.
-
AWS ECR : To store docker images.
-
AWS S3 Bucket : To store the output of terraform scripts.
-
GitHub Workflows : To define the jobs of CI-CD.
-
Each push to this repository triggers a new build using Github Workflows.
-
In each build, the Terraform script (main.tf), allocates a new AWS EC2 instance, equips it with appropriate security groups and IAM roles, so that it can execute commands on AWS ECR to pull images. It also assigns ingress and egress rules to the instance. The Public IP is generated as an output from this terraform file.
-
The GiHub Workflows is used to assign environment variables required for the associated jobs. In the 1st job Infrastructure is deployed (EC2). In the second job FastAPI app is deployed after building and pushing the docker image to AWS ECR.
-
Then docker is installed on AWS EC2 and the pushed image on AWS ECR is pulled and deployed on the allocated AWS EC2 instance.