forked from exit-zero-academy/NetflixMovieCatalog
-
Notifications
You must be signed in to change notification settings - Fork 0
43 lines (34 loc) · 1.29 KB
/
service-deploy.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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"