The goal of this project was to implement CI/CD for the Dockerized Web_Counter application. The CI portion of the project is our test.yml file which tests the Web_Counter by using both Flake8 and our test file testServer.py. After the CI portion, our CD portion utilizes the AWS_Redeploy.yml the continuously deploy the changes made to an EC2 instance. However, due to the fact that we utilized the AWS learner lab, we were unable to create permanent instances. Due to this the public IP address of the instance and the user's private key to access the instance must be updated in the redeploy.yml file for continuous deployment to occur(if you are creating your own instance). Although the private key needs to be updated in the yaml file a GitHub secret needs to be made to safeguard the private key. Within the yaml file the secret variable would then be used instead of the actual private key itself and displaying it publicly.
- Contributers: Samuel Cadiz and Jaden Peiffer
-
Update the AWS IP address in the redeploy.yml
-
Change the remote host to your AWS instance public IP address
REMOTE HOST: "<AWS IP address>"
-
-
Update SSH_KEY in the redeploy.yml
-
Create a GitHub secret that has the contents of your private ssh key
-
Update SSH_KEY under "env:" to be your GitHub secret name that includes your ssh key
SSH_KEY: ${{ secrets.< Your secret name> }}
-
-
Git clone Cadiz_Peiffer_ec2
git clone Cadiz_Peiffer_ec2
-
Go into Cadiz_Peiffer_ec2
cd Cadiz_Peiffer_ec2
-
Create a virtual environment
python3 -m venv .venv
-
Activate the virtual environment
source .venv/bin/activate
-
Install the requirements.txt
pip install -r requirements.txt
-
Run the app.py file
python app.py
-
Open a web browser and go to
http://localhost:8000
-
You can also launch locally using Gunicorn outside the virtual environment
.venv/bin/gunicorn --bind 0.0.0.0:8000 app:app
-
Then go to
http://localhost:8000
-
-
Create an AWS instance
-
Install git onto AWS instance
ssh -i ~/.ssh/<private ssh key file> ec2-user@<public IP address of instance> sudo yum install -y git
-
Clone GitHub repository
ssh -i ~/.ssh/<ssh key> ec2-user@<public IP address of instance> git clone https://github.com/cs220s24/Cadiz_Peiffer_ec2.git
-
Activate deploy.sh
- Installs docker and allows ec2-user permissions
ssh -i ~/.ssh/<ssh key> ec2-user@<public IP address of instance> ./Cadiz_Peiffer_ec2/deploy.sh
-
Activate build.sh
- Builds and runs docker container for web_counter on port 80
ssh -i ~/.ssh/<ssh key> ec2-user@<public IP address of instance> ./Cadiz_Peiffer_ec2/build.sh
-
To take down the web_counter:
-
ssh -i ~/.ssh/<ssh key> ec2-user@<public IP address of instance> ./Cadiz_Peiffer_ec2/down
- Deletes the docker container
- Git pulls any changes made to the repository
- Rebuilds and runs the docker container on port 80