-
Notifications
You must be signed in to change notification settings - Fork 0
46 lines (38 loc) · 1.21 KB
/
deploy.yml
File metadata and controls
46 lines (38 loc) · 1.21 KB
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
44
45
46
name: Deploy to EC2
on:
push:
branches:
- main
jobs:
deploy:
name: Deploy to EC2 Instance
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Create SSH key to connect to EC2
run: |
echo "${{ secrets.EC2_SSH_KEY }}" | base64 -d > ec2_key.pem
chmod 400 ec2_key.pem
- name: Deploy to EC2 via SSH
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key_path: ec2_key.pem
script: |
# Clone repo if not exists, otherwise pull
if [ ! -d "/home/ubuntu/scribble/.git" ]; then
GIT_SSH_COMMAND="ssh -i ./.ssh/deploy-key" git clone git@github.com:paramsgit/scribble.git
else
cd /home/ubuntu/scribble
GIT_SSH_COMMAND="ssh -i ../.ssh/deploy-key" git pull origin main
fi
# Run docker compose backend
cd /home/ubuntu/scribble/backend
docker compose down
docker compose up -d --build
# Run docker compose frontend
cd /home/ubuntu/scribble/frontend
docker compose down
docker compose up -d --build