-
Notifications
You must be signed in to change notification settings - Fork 1
144 lines (122 loc) ยท 4.6 KB
/
deploy.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
name: Backend CD
on:
pull_request:
types: [closed]
jobs:
build-and-push:
if: |
github.event.pull_request.merged == true &&
github.event.pull_request.base.ref == 'main' &&
contains(github.event.pull_request.labels.*.name, '๐
๐ผdeploy')
runs-on: ubuntu-latest
steps:
- name: ๋ฆฌํฌ์งํ ๋ฆฌ๋ฅผ ๊ฐ์ ธ์ต๋๋ค
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: JDK 17์ ์ค์นํฉ๋๋ค
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'
- name: Install redis
run: sudo apt-get install -y redis-tools redis-server
- name: Verify that redis is up
run: redis-cli ping
- name: Gradle ๋ช
๋ น ์คํ์ ์ํ ๊ถํ์ ๋ถ์ฌํฉ๋๋ค
run: chmod +x gradlew
- name: ๋ณ๊ฒฝ๋ ๋ชจ๋์ ์ฒดํฌํ๋ค.
id: check_changes
run: |
git fetch origin main
if git diff --name-only HEAD^ HEAD | grep -q "^domain/"; then
echo "domain ๋ชจ๋์ด ๋ณ๊ฒฝ๋์์ต๋๋ค."
echo "::set-output name=domain_changed::true"
else
if git diff --name-only HEAD^ HEAD | grep -q "^app-api/"; then
echo "api ๋ชจ๋์ด ๋ณ๊ฒฝ๋์์ต๋๋ค."
echo "::set-output name=api_changed::true"
fi
if git diff --name-only HEAD^ HEAD | grep -q "^app-scheduler/"; then
echo "scheduler ๋ชจ๋์ด ๋ณ๊ฒฝ๋์์ต๋๋ค."
echo "::set-output name=scheduler_changed::true"
fi
fi
- name: ๋ณ๊ฒฝ๋ ๋ชจ๋์ ๋น๋ํ๋ค.
run: |
domain_changed=${{ steps.check_changes.outputs.domain_changed }}
api_changed=${{ steps.check_changes.outputs.api_changed }}
scheduler_changed=${{ steps.check_changes.outputs.scheduler_changed }}
if [ "$domain_changed" == "true" ]; then
echo "๋๋ฉ์ธ ๋ชจ๋ ๋ฐ ํ์ ๋ชจ๋์ ๋น๋ํฉ๋๋ค."
./gradlew build --parallel
else
if [ "$api_changed" == "true" ]; then
echo "api ๋ชจ๋์ ๋น๋ํฉ๋๋ค."
./gradlew :app-api:build
fi
if [ "$scheduler_changed" == "true" ]; then
echo "scheduler ๋ชจ๋์ ๋น๋ํฉ๋๋ค."
./gradlew :app-scheduler:build
fi
if [ "$api_changed" != "true" ] && [ "$scheduler_changed" != "true" ]; then
echo "๋ชจ๋์ ๋ณ๊ฒฝ ์ฌํญ์ด ์์ต๋๋ค."
fi
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: ๋์ปค ๋ก๊ทธ์ธ
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: ๋์ปค ์ด๋ฏธ์ง build ํ push (API)
uses: docker/build-push-action@v2
if: |
steps.check_changes.outputs.domain_changed == 'true' ||
steps.check_changes.outputs.api_changed == 'true'
with:
context: ./app-api
file: ./app-api/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.API_IMAGE }}:${{ github.sha }}
platforms: linux/amd64
- name: ๋์ปค ์ด๋ฏธ์ง build ํ push (Scheduler)
uses: docker/build-push-action@v2
if: |
steps.check_changes.outputs.domain_changed == 'true' ||
steps.check_changes.outputs.scheduler_changed == 'true'
with:
context: ./app-scheduler
file: ./app-scheduler/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.SCHEDULER_IMAGE }}:${{ github.sha }}
platforms: linux/amd64
deploy-to-ec2:
runs-on: ubuntu-latest
needs: build-and-push
steps:
- name: Install SSH
run: sudo apt update && sudo apt install -y openssh-client
- name: EC2 ์ ์ ๋ฐ ๋ฐฐํฌ ์งํ
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
script: |
export COMMIT_VERSION=${{ github.sha }} &&
./deploy.sh
notify-slack:
runs-on: ubuntu-latest
needs: deploy-to-ec2
steps:
- name: ๋ฐฐํฌ ์ฑ๊ณต์ Slack์ผ๋ก ์๋ฆฝ๋๋ค
uses: 8398a7/action-slack@v3
with:
author_name: ๋ฐฐํฌ ์ฑ๊ณต
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow # selectable (default: repo,message)
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
if: always() # Pick up events even if the job fails or is canceled.