Skip to content

Update service-deploy.yaml #3

Update service-deploy.yaml

Update service-deploy.yaml #3

name: Netflix Movie Catalog Service Deployment
on:
push:
branches:
- main
env:
EC2_PUBLIC_IP: ai-spill.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:
Deploy:
name: Deploy in EC2
runs-on: ubuntu-latest
steps:
- name: Checkout the app code
uses: actions/checkout@v2
- name: Set up SSH agent
run: |
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"