-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (72 loc) · 2.37 KB
/
backend-prod-cd.yml
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: Siso - 밸런스 게임 벡엔드 배포 자동화 워크플로우 (backend-prod)
on:
push:
branches: ["main"]
permissions:
checks: write
jobs:
detect-changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get previous tag
id: previoustag
run: echo "PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ --always)" >> $GITHUB_OUTPUT
- uses: dorny/paths-filter@v3
id: filter
with:
base: ${{ steps.previoustag.outputs.PREVIOUS_TAG }}
ref: ${{ github.ref }}
filters: |
backend:
- 'backend/**'
frontend:
- 'frontend/**'
docker-deploy:
needs: detect-changes
if: ${{ needs.detect-changes.outputs.backend == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker hub 로그인
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker 이미지 빌드 및 푸시
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/siso-backend:latest ./backend
docker push ${{ secrets.DOCKER_USERNAME }}/siso-backend:latest
ec2-deploy:
needs: docker-deploy
runs-on: ubuntu-latest
steps:
- name: EC2에 배포
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/siso-backend:latest
docker-compose -f ./docker-compose.yml up -d
- name: 인증서 갱신 및 Nginx 재시작
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
docker-compose run certbot renew
docker-compose restart nginx