Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions .github/workflows/service-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ on:
- main

env:
EC2_PUBLIC_IP: X.X.X.X # 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-spill.devops-days-upes.com # Replace with your EC2 instance public IP
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} # Define this secret in your GitHub repo settings

jobs:
Deploy:
Expand All @@ -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 on EC2
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:~/NetflixMovieCatalog

- name: Deploy to EC2
run: |
ssh -o StrictHostKeyChecking=no -i ~/.ssh/mykey.pem ubuntu@$EC2_PUBLIC_IP "bash ~/app/deploy.sh"
37 changes: 36 additions & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
#!/bin/bash
set -e

# TODO your deploy script implementation...
echo ""
echo "Installing python3.12-venv..."
echo "--------------------------------"
sudo apt-get update
sudo apt-get install -y python3.12-venv

echo ""
echo "Creating a Python virtual environment..."
echo "--------------------------------"
python3 -m venv venv

echo ""
echo "Activating the Python virtual environment..."
echo "--------------------------------"
source venv/bin/activate

echo ""
echo "Changing to the application directory..."
echo "--------------------------------"
cd ~/NetflixMovieCatalog

echo ""
echo "Checking directory contents..."
echo "--------------------------------"
ls -la

echo ""
echo "Install Python dependencies..."
echo "--------------------------------"
pip install -r requirements.txt

echo ""
echo "Starting the Python application..."
echo "--------------------------------"
python app.py