-
Notifications
You must be signed in to change notification settings - Fork 0
264 lines (224 loc) · 10.1 KB
/
manual-deploy.yml
File metadata and controls
264 lines (224 loc) · 10.1 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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
name: SeeAndYouGo Manual Deploy
permissions:
contents: read
packages: write
on:
workflow_dispatch:
inputs:
deploy_target:
description: '배포 대상 선택'
required: true
type: choice
options:
- all
- backend
- frontend
jobs:
build-backend:
if: ${{ inputs.deploy_target == 'all' || inputs.deploy_target == 'backend' }}
runs-on: ubuntu-latest
steps:
- name: "[Backend] 코드 체크아웃"
uses: actions/checkout@v3
- name: "[Backend] QEMU 설정"
uses: docker/setup-qemu-action@v3
- name: "[Backend] Docker Buildx 설정"
uses: docker/setup-buildx-action@v3
- name: "[Backend] GHCR 로그인"
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: "[Backend] JDK 11 설정"
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: "[Backend] Gradle 실행 권한 부여"
run: chmod +x backend/gradlew
- name: "[Backend] 환경 파일 준비"
run: |
cd backend/src/main/resources
echo "${{ secrets.APPLICATION_YML }}" > application.yml
echo "${{ secrets.APPLICATION_PROD_YML }}" > application-prod.yaml
echo "${{ secrets.KEY_YML }}" > key.yml
shell: bash
- name: "[Backend] JSON 파일 준비"
env:
JSON_CONTENT: ${{ secrets.RES1_JSON }}
run: |
FILE_PATH="backend/src/main/java/com/SeeAndYouGo/SeeAndYouGo/restaurant/menuOfRestaurant1.json"
mkdir -p $(dirname "$FILE_PATH")
printf '%s' "$JSON_CONTENT" > "$FILE_PATH"
- name: "[Backend] Gradle 빌드"
run: |
cd backend
./gradlew clean bootJar
- name: "[Backend] Dockerfile 수정 (JSON 파일 복사)"
run: |
echo "" >> backend/Dockerfile
echo "# Runtime에 필요한 JSON 파일을 이미지로 복사" >> backend/Dockerfile
echo "RUN mkdir -p /app/src/main/java/com/SeeAndYouGo/SeeAndYouGo/restaurant" >> backend/Dockerfile
echo "COPY src/main/java/com/SeeAndYouGo/SeeAndYouGo/restaurant/menuOfRestaurant1.json /app/src/main/java/com/SeeAndYouGo/SeeAndYouGo/restaurant/menuOfRestaurant1.json" >> backend/Dockerfile
- name: "[Backend] Docker 이미지 빌드 및 Push"
run: |
OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
IMAGE_NAME="ghcr.io/$OWNER/seeandyougo-backend"
cd backend
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag $IMAGE_NAME:latest \
--tag $IMAGE_NAME:${{ github.sha }} \
--push \
.
build-frontend:
if: ${{ inputs.deploy_target == 'all' || inputs.deploy_target == 'frontend' }}
runs-on: ubuntu-latest
steps:
- name: "[Frontend] 코드 체크아웃"
uses: actions/checkout@v3
- name: "[Frontend] QEMU 설정"
uses: docker/setup-qemu-action@v3
- name: "[Frontend] Docker Buildx 설정"
uses: docker/setup-buildx-action@v3
- name: "[Frontend] GHCR 로그인"
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: "[Frontend] 환경 파일 준비"
run: |
cd frontend
echo "${{ secrets.FRONTEND_ENV }}" > .env
shell: bash
- name: "[Frontend] Nginx 설정 파일 복사"
run: cp default.conf frontend/
- name: "[Frontend] Dockerfile 수정"
run: |
sed -i.bak 's|COPY frontend/. .|COPY . .|' frontend/Dockerfile
sed -i.bak 's|COPY frontend/package.json frontend/yarn.lock ./|COPY package.json yarn.lock ./|' frontend/Dockerfile
- name: "[Frontend] Docker 이미지 빌드 및 Push"
run: |
OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
IMAGE_NAME="ghcr.io/$OWNER/seeandyougo-frontend"
cd frontend
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag $IMAGE_NAME:latest \
--tag $IMAGE_NAME:${{ github.sha }} \
--push \
.
deploy:
needs: [build-backend, build-frontend]
if: always()
runs-on: ubuntu-latest
steps:
- name: "[배포] 서버에서 배포 실행"
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_PORT }}
timeout: 30m
script: |
set -e
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🚀 SeeAndYouGo 배포 시작"
echo "📦 배포 대상: ${{ inputs.deploy_target }}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "[시스템] GHCR 로그인..."
echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
BACKEND_IMAGE_NAME="ghcr.io/$OWNER/seeandyougo-backend"
FRONTEND_IMAGE_NAME="ghcr.io/$OWNER/seeandyougo-frontend"
# Backend 배포
if [ "${{ inputs.deploy_target }}" == "all" ] || [ "${{ inputs.deploy_target }}" == "backend" ]; then
echo ""
echo "[Backend] Docker 이미지 Pull 중..."
docker pull $BACKEND_IMAGE_NAME:latest
echo "[Backend] 기존 컨테이너 중지 중..."
docker stop seeandyougo > /dev/null 2>&1 || true
docker rm seeandyougo > /dev/null 2>&1 || true
echo "[Backend] 새 컨테이너 시작 중..."
docker run -d \
--name seeandyougo \
--restart always \
--network backbone \
-p 8080:8080 \
-e TZ=Asia/Seoul \
-v /home/shxnzxxn/SeeAndYouGo-2/backend/imageStorage:/app/imageStorage \
$BACKEND_IMAGE_NAME:latest
echo "✅ [Backend] 배포 완료"
fi
# Frontend 배포
if [ "${{ inputs.deploy_target }}" == "all" ] || [ "${{ inputs.deploy_target }}" == "frontend" ]; then
echo ""
echo "[Frontend] Docker 이미지 Pull 중..."
docker pull $FRONTEND_IMAGE_NAME:latest
echo "[Frontend] 기존 컨테이너 중지 중..."
docker stop seeandyougo-nginx > /dev/null 2>&1 || true
docker rm seeandyougo-nginx > /dev/null 2>&1 || true
echo "[Frontend] 새 컨테이너 시작 중..."
docker run -d \
--name seeandyougo-nginx \
--restart always \
--network backbone \
-p 80:80 \
-p 443:443 \
-e TZ=Asia/Seoul \
$FRONTEND_IMAGE_NAME:latest
echo "✅ [Frontend] 배포 완료"
fi
echo ""
echo "[시스템] 사용하지 않는 Docker 이미지 정리 중..."
docker image prune -a -f
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✨ 배포 완료"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
- name: "[검증] 배포 상태 확인"
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
port: ${{ secrets.SERVER_PORT }}
timeout: 15m
script: |
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📊 배포 검증"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
if [ "${{ inputs.deploy_target }}" == "all" ] || [ "${{ inputs.deploy_target }}" == "backend" ]; then
echo "[Backend] 헬스체크:"
sleep 3
if curl -f http://localhost:8080/actuator/health > /dev/null 2>&1; then
echo "✅ Backend 정상 작동 중"
else
echo "⚠️ 헬스체크 엔드포인트 없음 (서버는 실행 중)"
fi
fi
if [ "${{ inputs.deploy_target }}" == "all" ] || [ "${{ inputs.deploy_target }}" == "frontend" ]; then
echo "[Frontend] 헬스체크:"
if curl -f http://localhost/ > /dev/null 2>&1; then
echo "✅ Frontend 정상 작동 중"
else
echo "⚠️ Frontend 응답 없음"
fi
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✅ 검증 완료"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
- name: "[완료] 배포 결과 알림"
if: always()
run: |
if [ "${{ job.status }}" == "success" ]; then
echo "✅ 배포 성공"
echo "📦 배포 대상: ${{ inputs.deploy_target }}"
else
echo "❌ 배포 실패"
echo "📋 로그를 확인해주세요"
fi