From 94d607779d7ef76be8d2796686c1fb1f339b8665 Mon Sep 17 00:00:00 2001 From: yashgp-coder <114697174+yashgp-coder@users.noreply.github.com> Date: Thu, 19 Sep 2024 12:09:26 +0530 Subject: [PATCH 01/10] Update service-deploy.yaml --- .github/workflows/service-deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/service-deploy.yaml b/.github/workflows/service-deploy.yaml index d778ea4..86fe867 100644 --- a/.github/workflows/service-deploy.yaml +++ b/.github/workflows/service-deploy.yaml @@ -6,7 +6,7 @@ on: - main env: - EC2_PUBLIC_IP: X.X.X.X # TODO replace to your EC2 instance public IP + EC2_PUBLIC_IP: ai-yash-nflix.devops-days-upes.com # TODO replace to your EC2 instance public IP SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} # TODO define this secret in your GitHub repo settings jobs: From 558d0d6191777a7a4383d743409b84440e736ff4 Mon Sep 17 00:00:00 2001 From: yashgp-coder <114697174+yashgp-coder@users.noreply.github.com> Date: Thu, 19 Sep 2024 12:28:33 +0530 Subject: [PATCH 02/10] Update1 service-deploy.yaml From fd3897f2dfb2a3e8808bbbc978eb2e2b1f326e9c Mon Sep 17 00:00:00 2001 From: yashgp-coder <114697174+yashgp-coder@users.noreply.github.com> Date: Thu, 19 Sep 2024 12:30:23 +0530 Subject: [PATCH 03/10] Update deploy.sh --- deploy.sh | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/deploy.sh b/deploy.sh index 11c5981..7141151 100644 --- a/deploy.sh +++ b/deploy.sh @@ -1,3 +1,38 @@ #!/bin/bash -# TODO your deploy script implementation... \ No newline at end of file +# TODO your deploy script implementation... +#!/bin/bash + +# Exit immediately if a command exits with a non-zero status +set -e + +# Update package lists and install Python 3.12 venv if not already installed +sudo apt-get update +sudo apt-get install -y python3.12-venv + +# Navigate to the application directory +cd ~/app || exit + +# Create a virtual environment if it doesn't already exist +if [ ! -d "venv" ]; then + python3 -m venv venv +fi + +# Activate the virtual environment +source venv/bin/activate + +# Install required Python packages +pip install --no-cache-dir -r requirements.txt + +# Stop the app service if it's running (optional) +# Uncomment and modify if using a service manager like systemd +# sudo systemctl stop netflix-movie-catalog.service + +# Run the application +nohup python app.py > app.log 2>&1 & + +# Optional: Start the service using systemd (if applicable) +# Uncomment and modify if you have a service defined +# sudo systemctl start netflix-movie-catalog.service + +echo "Deployment complete! Application is running in the background." From 1be088326a1e5676fdd2d1145aa0526a05c1efe4 Mon Sep 17 00:00:00 2001 From: yashgp-coder <114697174+yashgp-coder@users.noreply.github.com> Date: Thu, 19 Sep 2024 12:31:49 +0530 Subject: [PATCH 04/10] Update2 service-deploy.yaml --- .github/workflows/service-deploy.yaml | 41 ++++++++++++++++----------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/.github/workflows/service-deploy.yaml b/.github/workflows/service-deploy.yaml index 86fe867..ae2d4dc 100644 --- a/.github/workflows/service-deploy.yaml +++ b/.github/workflows/service-deploy.yaml @@ -6,8 +6,8 @@ on: - main env: - EC2_PUBLIC_IP: ai-yash-nflix.devops-days-upes.com # TODO replace to your EC2 instance public IP - SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} # TODO define this secret in your GitHub repo settings + EC2_PUBLIC_IP: ai-yash-nflix.devops-days-upes.com + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} jobs: Deploy: @@ -17,19 +17,26 @@ jobs: - name: Checkout the app code uses: actions/checkout@v2 - - name: SSH to EC2 instance + - name: Set up SSH agent run: | - echo "$SSH_PRIVATE_KEY" > mykey.pem - chmod 400 mykey.pem - - # Copy the files from the current work dir into the EC2 instance, under `~/app`. - scp -o StrictHostKeyChecking=no -i mykey.pem -r * ubuntu@$EC2_PUBLIC_IP:~/app - - # Connect to your EC2 instance and execute the `deploy.sh` script (this script is part of the repo files). - # TODO You need to implement the `deploy.sh` script yourself. - # - # Upon completion, the NetflixMovieCatalog app should be running with its newer version. - # To keep the app running in the background independently on the terminal session you are logging to, configure it as a Linux service. - - ssh -i mykey.pem ubuntu@$EC2_PUBLIC_IP "bash ~/app/deploy.sh" - + mkdir -p ~/.ssh + echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/mykey.pem + chmod 600 ~/.ssh/mykey.pem + eval "$(ssh-agent -s)" + ssh-add ~/.ssh/mykey.pem + + - name: Check SSH connectivity + run: | + ssh -o StrictHostKeyChecking=no -i ~/.ssh/mykey.pem ubuntu@$EC2_PUBLIC_IP "echo 'Connection successful!'" + + - name: Ensure app directory exists + run: | + ssh -o StrictHostKeyChecking=no -i ~/.ssh/mykey.pem ubuntu@$EC2_PUBLIC_IP "mkdir -p ~/app" + + - name: Copy files to EC2 + run: | + scp -o StrictHostKeyChecking=no -i /.ssh/mykey.pem -r * ubuntu@$EC2_PUBLIC_IP:/app + + - name: Deploy to EC2 + run: | + ssh -o StrictHostKeyChecking=no -i ~/.ssh/mykey.pem ubuntu@$EC2_PUBLIC_IP "bash ~/app/deploy.sh" From d713dc1f3cfa2ecfb797bab79a88cbd842fd7daf Mon Sep 17 00:00:00 2001 From: yashgp-coder <114697174+yashgp-coder@users.noreply.github.com> Date: Thu, 19 Sep 2024 12:40:17 +0530 Subject: [PATCH 05/10] Update4 service-deploy.yaml --- .github/workflows/service-deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/service-deploy.yaml b/.github/workflows/service-deploy.yaml index ae2d4dc..068c416 100644 --- a/.github/workflows/service-deploy.yaml +++ b/.github/workflows/service-deploy.yaml @@ -6,7 +6,7 @@ on: - main env: - EC2_PUBLIC_IP: ai-yash-nflix.devops-days-upes.com + EC2_PUBLIC_IP: ai-yash3-netflix.devops-days-upes.com SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} jobs: From 41382737944c570a936abbb0938427d2109aad7d Mon Sep 17 00:00:00 2001 From: yashgp-coder <114697174+yashgp-coder@users.noreply.github.com> Date: Thu, 19 Sep 2024 12:44:19 +0530 Subject: [PATCH 06/10] Update1 deploy.sh --- deploy.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/deploy.sh b/deploy.sh index 7141151..f140849 100644 --- a/deploy.sh +++ b/deploy.sh @@ -1,8 +1,5 @@ #!/bin/bash -# TODO your deploy script implementation... -#!/bin/bash - # Exit immediately if a command exits with a non-zero status set -e @@ -15,7 +12,7 @@ cd ~/app || exit # Create a virtual environment if it doesn't already exist if [ ! -d "venv" ]; then - python3 -m venv venv +python3 -m venv venv fi # Activate the virtual environment @@ -35,4 +32,4 @@ nohup python app.py > app.log 2>&1 & # Uncomment and modify if you have a service defined # sudo systemctl start netflix-movie-catalog.service -echo "Deployment complete! Application is running in the background." +echo "Deployment complete! Application is running in the background." From f261eaf77c189106ab0871c3514832a0269c20b6 Mon Sep 17 00:00:00 2001 From: yashgp-coder <114697174+yashgp-coder@users.noreply.github.com> Date: Thu, 19 Sep 2024 12:50:33 +0530 Subject: [PATCH 07/10] Update4 deploy.sh --- deploy.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/deploy.sh b/deploy.sh index f140849..dc64442 100644 --- a/deploy.sh +++ b/deploy.sh @@ -3,6 +3,13 @@ # Exit immediately if a command exits with a non-zero status set -e +# Set the correct permissions for the SSH key +chmod 400 ~/.ssh/mykey.pem + +# Start the SSH agent and add the key +eval $(ssh-agent -s) +ssh-add ~/.ssh/mykey.pem + # Update package lists and install Python 3.12 venv if not already installed sudo apt-get update sudo apt-get install -y python3.12-venv @@ -12,7 +19,7 @@ cd ~/app || exit # Create a virtual environment if it doesn't already exist if [ ! -d "venv" ]; then -python3 -m venv venv + python3.12 -m venv venv fi # Activate the virtual environment @@ -21,15 +28,10 @@ source venv/bin/activate # Install required Python packages pip install --no-cache-dir -r requirements.txt -# Stop the app service if it's running (optional) -# Uncomment and modify if using a service manager like systemd -# sudo systemctl stop netflix-movie-catalog.service - -# Run the application +# Run the application in the background nohup python app.py > app.log 2>&1 & # Optional: Start the service using systemd (if applicable) -# Uncomment and modify if you have a service defined # sudo systemctl start netflix-movie-catalog.service echo "Deployment complete! Application is running in the background." From 1b7aa30820522d6ec9e4524e7ad76c8cbbea49b9 Mon Sep 17 00:00:00 2001 From: yashgp-coder <114697174+yashgp-coder@users.noreply.github.com> Date: Thu, 19 Sep 2024 12:52:27 +0530 Subject: [PATCH 08/10] Update deploy.sh --- deploy.sh | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/deploy.sh b/deploy.sh index dc64442..f140849 100644 --- a/deploy.sh +++ b/deploy.sh @@ -3,13 +3,6 @@ # Exit immediately if a command exits with a non-zero status set -e -# Set the correct permissions for the SSH key -chmod 400 ~/.ssh/mykey.pem - -# Start the SSH agent and add the key -eval $(ssh-agent -s) -ssh-add ~/.ssh/mykey.pem - # Update package lists and install Python 3.12 venv if not already installed sudo apt-get update sudo apt-get install -y python3.12-venv @@ -19,7 +12,7 @@ cd ~/app || exit # Create a virtual environment if it doesn't already exist if [ ! -d "venv" ]; then - python3.12 -m venv venv +python3 -m venv venv fi # Activate the virtual environment @@ -28,10 +21,15 @@ source venv/bin/activate # Install required Python packages pip install --no-cache-dir -r requirements.txt -# Run the application in the background +# Stop the app service if it's running (optional) +# Uncomment and modify if using a service manager like systemd +# sudo systemctl stop netflix-movie-catalog.service + +# Run the application nohup python app.py > app.log 2>&1 & # Optional: Start the service using systemd (if applicable) +# Uncomment and modify if you have a service defined # sudo systemctl start netflix-movie-catalog.service echo "Deployment complete! Application is running in the background." From 9e1d4e0193de8551801752005f7bda5e937105a6 Mon Sep 17 00:00:00 2001 From: yashgp-coder <114697174+yashgp-coder@users.noreply.github.com> Date: Thu, 19 Sep 2024 14:14:54 +0530 Subject: [PATCH 09/10] Update deploy.sh From f1d901b3da59ad2eeb820e58bff085dd6eecafb8 Mon Sep 17 00:00:00 2001 From: yashgp-coder <114697174+yashgp-coder@users.noreply.github.com> Date: Thu, 19 Sep 2024 14:40:07 +0530 Subject: [PATCH 10/10] Update deploy.sh --- deploy.sh | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/deploy.sh b/deploy.sh index f140849..7ec5954 100644 --- a/deploy.sh +++ b/deploy.sh @@ -1,35 +1,28 @@ #!/bin/bash - -# Exit immediately if a command exits with a non-zero status set -e -# Update package lists and install Python 3.12 venv if not already installed -sudo apt-get update +echo "" +echo "Installing python3.12-venv..." +echo "--------------------------------" +sudo apt-get update sudo apt-get install -y python3.12-venv -# Navigate to the application directory -cd ~/app || exit - -# Create a virtual environment if it doesn't already exist -if [ ! -d "venv" ]; then +echo "" +echo "Creating a Python virtual environment..." +echo "--------------------------------" python3 -m venv venv -fi -# Activate the virtual environment +echo "" +echo "Activating the Python virtual environment..." +echo "--------------------------------" source venv/bin/activate -# Install required Python packages -pip install --no-cache-dir -r requirements.txt - -# Stop the app service if it's running (optional) -# Uncomment and modify if using a service manager like systemd -# sudo systemctl stop netflix-movie-catalog.service - -# Run the application -nohup python app.py > app.log 2>&1 & - -# Optional: Start the service using systemd (if applicable) -# Uncomment and modify if you have a service defined -# sudo systemctl start netflix-movie-catalog.service +echo "" +echo "Install Python dependencies..." +echo "--------------------------------" +pip install -r requirements.txt -echo "Deployment complete! Application is running in the background." +echo "" +echo "Starting the Python application..." +echo "--------------------------------" +python app.py