The objective of this assignment is to deploy a two-tiered web application with web and database components running as containers on Amazon EC2. The application will be hosted on AWS EC2 instances deployed into a public subnet in the default VPC for simplicity in debugging.
This assignment comprises three main parts:
-
Configuring GitHub Actions: Automatically build and publish container images. Both the application and MySQL DB images should be published to Amazon ECR.
-
Running Web Application Instances: Deploy three instances of the web application on Amazon EC2.
-
Updating and Re-deploying the Application: Manage updates to the application code and re-deploy it on Amazon EC2.
- GitHub Actions: Create Docker images and push them to Amazon ECR automatically.
- Amazon ECR: Securely store your container images.
- Cloud9 IDE : Develop application and build container images.
- Docker CLI: Work with Docker containers.
- AWS EC2: Host your containerized application.
- AWS IAM (Identity and Access Management): Grant EC2 instance access to Amazon ECR.
- Terraform: Deploy the required infrastructure.
sudo yum update -y
sudo yum install docker -y
sudo systemctl start docker
sudo systemctl status dockersudo chmod 666 /var/run/docker.sock
sudo usermod -a -G docker ec2-useraws configure
sudo vi ~/.aws/credentials
Move to the Terraform folder and generate an assignment1 key pair file using the following command:
ssh-keygen -t rsa -f assignment1
terraform init
terraform plan
terraform apply -auto-approveOnce the image is successfully pushed from GitHub to Amazon ECR clo835-ecr-assignment1, Docker login using the following commands:
docker pull db_uri
docker pull App_uridocker network create -d bridge ranjith-network
docker run -d --network ranjith-network -e MYSQL_ROOT_PASSWORD=pw uri
docker inspect <container_id>
export DBHOST=172.18.0.2
export DBPORT=3306
export DBUSER=root
export DATABASE=employees
export DBPWD=pw
export APP_COLOR=blue
docker run -p 8081:8080 --name blue --network=ranjith-network -e APP_COLOR=$APP_COLOR -e DBHOST=$DBHOST -e DBPORT=$DBPORT -e DBUSER=$DBUSER -e DBPWD=$DBPWD [uri]
export APP_COLOR=pink
docker run -p 8082:8080 --name pink --network=ranjith-network -e APP_COLOR=$APP_COLOR -e DBHOST=$DBHOST -e DBPORT=$DBPORT -e DBUSER=$DBUSER -e DBPWD=$DBPWD uri
export APP_COLOR=lime
docker run -p 8083:8080 --name lime --network=ranjith-network -e APP_COLOR=$APP_COLOR -e DBHOST=$DBHOST -e DBPORT=$DBPORT -e DBUSER=$DBUSER -e DBPWD=$DBPWD uri
docker exec -it <container_name> /bin/bash
mysql -u root -p employees
