-
Notifications
You must be signed in to change notification settings - Fork 3
208 lines (190 loc) ยท 9.92 KB
/
cd-dev.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
name: Development CD
on:
workflow_dispatch:
push:
branches: [ "backend" ]
permissions:
contents: read
jobs:
deploy:
runs-on: development
steps:
- uses: actions/checkout@v3
- name: ๋น๋
working-directory: ./backend
run: |
chmod +x ./gradlew
./gradlew bootjar
- name: ๋น ํฌํธ ์ฐพ๊ธฐ
id: port
shell: bash {0}
run: |
if [ -z "$(lsof -i:8080)" ]; then
echo "green=8080">>$GITHUB_OUTPUT
echo "server1=8081">>$GITHUB_OUTPUT
echo "server2=8082">>$GITHUB_OUTPUT
elif [ -z "$(lsof -i:8081)" ]; then
echo "green=8081">>$GITHUB_OUTPUT
echo "server1=8080">>$GITHUB_OUTPUT
echo "server2=8082">>$GITHUB_OUTPUT
elif [ -z "$(lsof -i:8082)" ]; then
echo "green=8082">>$GITHUB_OUTPUT
echo "server1=8080">>$GITHUB_OUTPUT
echo "server2=8081">>$GITHUB_OUTPUT
fi;
- name: JAR ํ์ผ ๋ณต์ฌ
working-directory: ./backend
shell: bash {0}
run: |
mkdir -p /home/ubuntu/backend
cp -f build/libs/DigginRoom-0.0.1-SNAPSHOT.jar /home/ubuntu/backend/
- name: ๋น ํฌํธ์ ์ ์ดํ๋ฆฌ์ผ์ด์
์คํ
working-directory: /home/ubuntu/backend
env:
RUNNER_TRACKING_ID: ""
GREEN: ${{ steps.port.outputs.green }}
run: |
nohup java -jar \
-Dspring.profiles.active=develop \
-Dserver.port=$GREEN \
-Dserver.shutdown=graceful \
-DDEV_DATASOURCE_URL=${{ secrets.DEV_DATASOURCE_URL }} \
-DDEV_DATASOURCE_USERNAME=${{ secrets.DEV_DATASOURCE_USERNAME }} \
-DDEV_DATASOURCE_PASSWORD=${{ secrets.DEV_DATASOURCE_PASSWORD }} \
-DCLIENT_ID=${{ secrets.CLIENT_ID }} \
-DCLIENT_SECRET=${{ secrets.CLIENT_SECRET }} \
-DREDIRECT_URI=${{ secrets.REDIRECT_URI }} \
DigginRoom-0.0.1-SNAPSHOT.jar &
- name: ์ดํ๋ฆฌ์ด์
์ด ์ ์ ๊ฐ๋ฅํ ์ํ๊ฐ ๋๋๋ก ๊ธฐ๋ค๋ฆฐ๋ค
shell: bash {0}
env:
GREEN: ${{ steps.port.outputs.green }}
run: |
while [ "$(curl -o /dev/null -s -w %{http_code} localhost:$GREEN/join/exist?username=admin1234)" != 200 ]
do
echo "์๋ก์ด ์ดํ๋ฆฌ์ผ์ด์
์ ๋์ฐ๋ ์ค์
๋๋ค.";
done
- name: ๊ธฐ์กด ๋ฒ์ ์ ์ดํ๋ฆฌ์ผ์ด์
์ ํ์ธํ๋ค.
id: version
shell: bash {0}
env:
GREEN: ${{ steps.port.outputs.green }}
SERVER1_PORT: ${{ steps.port.outputs.server1 }}
SERVER2_PORT: ${{ steps.port.outputs.server2 }}
run: |
function getVersion {
version=$(curl -s -H "Content-Type: application/json; charset=utf-8" -X GET http://localhost:$1/manage/info | jq -r '.version')
if [ -z $version ]; then
version="1.0.0"
fi;
echo ${version}
}
SERVER1_VERSION=$(getVersion $SERVER1)
SERVER2_VERSION=$(getVersion $SERVER2)
NOW_SERVER_VERSION=$(getVersion $GREEN)
NOW_MAJOR_VERSION=$(echo $NOW_SERVER_VERSION | cut -d "." -f1)
NOW_MINOR_VERSION=$(echo $NOW_SERVER_VERSION | cut -d "." -f2)
SERVER1_MAJOR_VERSION=$(echo $SERVER1_VERSION | cut -d "." -f1)
SERVER1_MINOR_VERSION=$(echo $SERVER1_VERSION | cut -d "." -f2)
SERVER2_MAJOR_VERSION=$(echo $SERVER2_VERSION | cut -d "." -f1)
SERVER2_MINOR_VERSION=$(echo $SERVER2_VERSION | cut -d "." -f2)
GREEN_VERSION="$NOW_MAJOR_VERSION.$NOW_MINOR_VERSION"
if [ -z $SERVER1_MAJOR_VERSION ] && [ -z $SERVER2_MAJOR_VERSION ]; then
echo "์๋ฒ๊ฐ ํ ๋๋ ๋์์ ธ์์ง ์์ต๋๋ค. ์๋ฒ 1์ ๋ฐฐํฌ"
BLUE_PORT=$SERVER1_PORT
RETAIN_PORT=$GREEN
RETAIN_VERSION="$SERVER2_MAJOR_VERSION.$SERVER2_MINOR_VERSION"
elif [ -z $SERVER1_MAJOR_VERSION ]; then
if [ $SERVER1_MAJOR_VERSION -eq $NOW_MAJOR_VERSION ] && [ $SERVER2_MINOR_VERSION -eq $NOW_MINOR_VERSION ]; then
echo "์๋ฒ 2์ ํ ๋๋ง ๋์์ ธ์์ต๋๋ค. ๊ธฐ์กด ์๋ฒ์์ MAJOR/MINOR ๋ฒ์ ์ด ๋์ผํฉ๋๋ค. ์๋ฒ 2์ ๋ธ๋ฃจ๊ทธ๋ฆฐ ๋ฐฐํฌ - 1"
BLUE_PORT=$SERVER2_PORT
RETAIN_PORT=$GREEN
RETAIN_VERSION="$SERVER1_MAJOR_VERSION.$SERVER1_MINOR_VERSION"
else
echo "์๋ฒ 2์ ํ ๋๋ง ๋์์ ธ์์ต๋๋ค. ๊ธฐ์กด ์๋ฒ์์ MAJOR or MINOR ๋ฒ์ ์ด ๋ค๋ฆ
๋๋ค. ์๋ฒ 1์ ๋ฐฐํฌ - 2"
BLUE_PORT=$SERVER1_PORT
RETAIN_PORT=$SERVER2_PORT
RETAIN_VERSION="$SERVER2_MAJOR_VERSION.$SERVER2_MINOR_VERSION"
fi;
elif [ -z $SERVER2_MAJOR_VERSION ]; then
if [ $SERVER1_MAJOR_VERSION -eq $NOW_MAJOR_VERSION ] && [ $SERVER1_MINOR_VERSION -eq $NOW_MINOR_VERSION ]; then
echo "์๋ฒ 1์ ํ ๋๋ง ๋์์ ธ์์ต๋๋ค. ๊ธฐ์กด ์๋ฒ์์ MAJOR/MINOR ๋ฒ์ ์ด ๋์ผํฉ๋๋ค. ์๋ฒ 1์ ๋ธ๋ฃจ๊ทธ๋ฆฐ ๋ฐฐํฌ - 1"
BLUE_PORT=$SERVER1_PORT
RETAIN_PORT=$GREEN
RETAIN_VERSION="$SERVER2_MAJOR_VERSION.$SERVER2_MINOR_VERSION"
else
echo "์๋ฒ 1์ ํ ๋๋ง ๋์์ ธ์์ต๋๋ค. ๊ธฐ์กด ์๋ฒ์์ MAJOR or MINOR ๋ฒ์ ์ด ๋ค๋ฆ
๋๋ค. ์๋ฒ 2์ ๋ธ๋ฃจ๊ทธ๋ฆฐ ๋ฐฐํฌ - 2"
BLUE_PORT=$SERVER2_PORT
RETAIN_PORT=$SERVER1_PORT
RETAIN_VERSION="$SERVER1_MAJOR_VERSION.$SERVER1_MINOR_VERSION"
fi;
elif [ $SERVER1_MAJOR_VERSION -eq $NOW_MAJOR_VERSION ] && [ $SERVER1_MINOR_VERSION -eq $NOW_MINOR_VERSION ]; then
echo "์๋ฒ 1๊ณผ์ MAJOR/MINOR ๋ฒ์ ์ด ๋์ผํฉ๋๋ค. ์๋ฒ 1์ ๋ธ๋ฃจ๊ทธ๋ฆฐ ๋ฐฐํฌ - 1"
BLUE_PORT=$SERVER1_PORT
RETAIN_PORT=$GREEN
RETAIN_VERSION="$SERVER2_MAJOR_VERSION.$SERVER2_MINOR_VERSION"
elif [ $SERVER2_MAJOR_VERSION -eq $NOW_MAJOR_VERSION ] && [ $SERVER2_MINOR_VERSION -eq $NOW_MINOR_VERSION ]; then
echo "์๋ฒ 2์์ MAJOR/MINOR ๋ฒ์ ์ด ๋์ผํฉ๋๋ค. ์๋ฒ 2์ ๋ธ๋ฃจ๊ทธ๋ฆฐ ๋ฐฐํฌ - 2"
BLUE_PORT=$SERVER2_PORT
RETAIN_PORT=$GREEN
RETAIN_VERSION="$SERVER1_MAJOR_VERSION.$SERVER1_MINOR_VERSION"
elif [ $SERVER1_MAJOR_VERSION -eq $SERVER2_MAJOR_VERSION ] && [ $SERVER1_MINOR_VERSION -le $SERVER2_MINOR_VERSION ]; then
echo "์๋ก์ด ์๋ฒ์ MAJOR or MINOR๋ฒ์ ์ด ์
๊ทธ๋ ์ด๋ ๋์์ต๋๋ค. ์๋ฒ 1์ MINOR ๋ฒ์ ์ด ์๋ฒ 2๋ณด๋ค ๋ฎ์ต๋๋ค. ์๋ฒ 1์ ๋ธ๋ฃจ๊ทธ๋ฆฐ ๋ฐฐํฌ - 3";
echo "$SERVER1_VERSION ์ ์ดํ์ ๊ฐ์ ์
๋ฐ์ดํธํ์ธ์."
BLUE_PORT=$SERVER1_PORT
RETAIN_PORT=$SERVER2_PORT
RETAIN_VERSION="$SERVER2_MAJOR_VERSION.$SERVER2_MINOR_VERSION"
elif [ $SERVER1_MAJOR_VERSION -eq $SERVER2_MAJOR_VERSION ] && [ $SERVER1_MINOR_VERSION -gt $SERVER2_MINOR_VERSION ]; then
echo "์๋ก์ด ์๋ฒ์ MAJOR or MINOR๋ฒ์ ์ด ์
๊ทธ๋ ์ด๋ ๋์์ต๋๋ค. ์๋ฒ 2์ MINOR ๋ฒ์ ์ด ์๋ฒ 1๋ณด๋ค ๋ฎ์ต๋๋ค. ์๋ฒ 2์ ๋ธ๋ฃจ๊ทธ๋ฆฐ ๋ฐฐํฌ - 4"
echo "$SERVER2_VERSION ์ ์ดํ์ ๊ฐ์ ์
๋ฐ์ดํธํ์ธ์."
BLUE_PORT=$SERVER2_PORT
RETAIN_PORT=$SERVER1_PORT
RETAIN_VERSION="$SERVER1_MAJOR_VERSION.$SERVER1_MINOR_VERSION"
elif [ $SERVER1_MAJOR_VERSION -lt $SERVER2_MAJOR_VERSION ]; then
echo "์๋ก์ด ์๋ฒ์ MAJOR or MINOR๋ฒ์ ์ด ์
๊ทธ๋ ์ด๋ ๋์์ต๋๋ค. ์๋ฒ 1์ MAJOR ๋ฒ์ ์ด ์๋ฒ 2๋ณด๋ค ๋ฎ์ต๋๋ค. ์๋ฒ 1์ ๋ธ๋ฃจ๊ทธ๋ฆฐ ๋ฐฐํฌ - 5";
BLUE_PORT=$SERVER1_PORT
RETAIN_PORT=$SERVER2_PORT
RETAIN_VERSION="$SERVER2_MAJOR_VERSION.$SERVER2_MINOR_VERSION"
elif [ $SERVER1_MAJOR_VERSION -gt $SERVER2_MAJOR_VERSION ]; then
echo "์๋ก์ด ์๋ฒ์ MAJOR or MINOR๋ฒ์ ์ด ์
๊ทธ๋ ์ด๋ ๋์์ต๋๋ค. ์๋ฒ 2์ MINOR ๋ฒ์ ์ด ์๋ฒ 1๋ณด๋ค ๋ฎ์ต๋๋ค. ์๋ฒ 2์ ๋ธ๋ฃจ๊ทธ๋ฆฐ ๋ฐฐํฌ - 6"
BLUE_PORT=$SERVER2_PORT
RETAIN_PORT=$SERVER1_PORT
RETAIN_VERSION="$SERVER1_MAJOR_VERSION.$SERVER1_MINOR_VERSION"
else
echo "::error title=๋ฐฐํฌ ์คํจ::์ผ์ด์ค๋ฅผ ๊ตฌ๋ถํ ์ ์์ต๋๋ค. ์๋ฒ 1: $SERVER1_VERSION ์๋ฒ 2: $SERVER2_VERSION ์๋ก์ด ์๋ฒ: $NOW_VERSION";
exit 1;
fi;
echo "blue=$BLUE_PORT">>$GITHUB_OUTPUT
echo "retain=$RETAIN_PORT">>$GITHUB_OUTPUT
echo "green_version=$GREEN_VERSION">>$GITHUB_OUTPUT
echo "retain_version=$RETAIN_VERSION">>$GITHUB_OUTPUT
- name: NGINX์ ๋ฆฌ๋ฒ์ค ํ๋ก์ ์ค์ ์ ๋ณ๊ฒฝํ๋ค.
env:
GREEN: ${{ steps.port.outputs.green }}
RETAIN: ${{ steps.version.outputs.retain }}
GREEN_VERSION: ${{ steps.version.outputs.green_version }}
RETAIN_VERSION: ${{ steps.version.outputs.retain_version }}
shell: bash {0}
run: |
INC_CONTENTS="if (\$http_version = \"$RETAIN_VERSION\") {
proxy_pass http://localhost:$RETAIN;
}
if (\$http_version = \"$GREEN_VERSION\") {
proxy_pass http://localhost:$GREEN;
}
proxy_pass http://localhost:$RETAIN;"
echo $INC_CONTENTS | sudo tee /etc/nginx/conf.d/port.inc;
- name: NGINX reload ๋ฅผ ์งํํ๋ค.
shell: bash {0}
run: |
sudo nginx -s reload;
- name: ๊ธฐ์กด ์ดํ๋ฆฌ์ผ์ด์
์ ์ข
๋ฃํ๋ค
shell: bash {0}
env:
BLUE: ${{ steps.version.outputs.blue }}
run: |
PROCESS_ID="$(lsof -i:$BLUE -t)"
if [ -n "$PROCESS_ID" ]; then
sudo kill -15 $PROCESS_ID
echo "๊ตฌ๋์ค์ธ ์ ํ๋ฆฌ์ผ์ด์
์ ์ข
๋ฃํ์ต๋๋ค. (pid : $PROCESS_ID, port : $BLUE)\n"
fi