Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull #5

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
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-yash3-netflix.devops-days-upes.com
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}

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
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"
27 changes: 26 additions & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
#!/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 "Install Python dependencies..."
echo "--------------------------------"
pip install -r requirements.txt

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