-
Notifications
You must be signed in to change notification settings - Fork 1
55 lines (47 loc) · 1.49 KB
/
deploy-backend.yml
File metadata and controls
55 lines (47 loc) · 1.49 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
47
48
49
50
51
52
53
54
55
name: Deploy to AWS EC2
on:
workflow_run:
workflows: [Run CI]
types:
- completed
jobs:
deploy-backend:
if: >
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'main' &&
github.event.workflow_run.event == 'push'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: changed-files
path: .
- name: Check for backend changes
id: backend-check
run: |
if grep '^backend/' changed_files.txt; then
echo "Backend changed"
echo "DEPLOY=true" >> $GITHUB_ENV
else
echo "No backend changes"
echo "DEPLOY=false" >> $GITHUB_ENV
fi
- name: Exit if no backend changes
if: env.DEPLOY == 'false'
run: exit 0
- name: Deploy on EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
cd feed-forward || exit 1
git pull origin main
docker-compose -f docker-compose.yml -f docker-compose.prod.yml down
docker rmi $(docker images -q)
docker system prune -a
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d --build