Skip to content

Commit 4ce9e64

Browse files
authored
Merge pull request #128 from YAPP-Github/develop
[Feat] 1차 스프린트 배포
2 parents 7b000e2 + 8d4bee8 commit 4ce9e64

File tree

202 files changed

+6644
-1864
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+6644
-1864
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: ERD to GitHub Pages
2+
3+
on:
4+
pull_request:
5+
branches: [ "main", "develop" ]
6+
paths: [ "src/main/resources/db/migration/**" ]
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
permissions:
13+
contents: write
14+
pull-requests: write
15+
16+
jobs:
17+
generate-erd-from-flyway:
18+
runs-on: ubuntu-latest
19+
20+
services:
21+
mysql:
22+
image: mysql:8.0
23+
env:
24+
MYSQL_USER: ${{ secrets.TEST_DB_USER }}
25+
MYSQL_PASSWORD: ${{ secrets.TEST_DB_PASSWORD }}
26+
MYSQL_ROOT_PASSWORD: ${{ secrets.TEST_DB_ROOT_PASSWORD }}
27+
MYSQL_DATABASE: testdb
28+
ports:
29+
- 3306:3306
30+
options: >-
31+
--health-cmd="mysqladmin ping"
32+
--health-interval=10s
33+
--health-timeout=5s
34+
--health-retries=3
35+
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v4
39+
40+
- name: Set up JDK 21
41+
uses: actions/setup-java@v4
42+
with:
43+
java-version: '21'
44+
distribution: 'temurin'
45+
46+
- name: Download Flyway
47+
run: |
48+
curl -sSL "https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/10.13.0/flyway-commandline-10.13.0-linux-x64.tar.gz" -o flyway.tar.gz
49+
tar -xzf flyway.tar.gz
50+
echo "$(pwd)/flyway-10.13.0" >> $GITHUB_PATH
51+
52+
- name: Run Flyway migrations
53+
run: |
54+
flyway -url="jdbc:mysql://127.0.0.1:3306/testdb?allowPublicKeyRetrieval=true&useSSL=false" -user=${{ secrets.TEST_DB_USER }} -password=${{ secrets.TEST_DB_PASSWORD }} -locations=filesystem:src/main/resources/db/migration migrate
55+
shell: bash
56+
57+
- name: Dump database schema
58+
run: |
59+
mkdir -p erd
60+
mysqldump -h 127.0.0.1 -u ${{ secrets.TEST_DB_USER }} -p${{ secrets.TEST_DB_PASSWORD }} --no-data --skip-comments testdb > erd/schema.sql
61+
62+
- name: Set up Node.js
63+
uses: actions/setup-node@v4
64+
with:
65+
node-version: '20'
66+
67+
- name: Install DBML Tools
68+
run: npm install -g @dbml/cli @softwaretechnik/dbml-renderer
69+
70+
- name: Convert SQL to DBML
71+
run: |
72+
npx sql2dbml erd/schema.sql --mysql -o erd/schema.dbml
73+
74+
- name: Render ERD to SVG
75+
run: |
76+
npx dbml-renderer -i erd/schema.dbml -o erd/erd.svg
77+
78+
- name: Generate HTML wrapper
79+
run: |
80+
echo "<html><head><title>ERD Preview</title></head><body><h2>ERD Preview for PR #${{ github.event.pull_request.number }}</h2><img src='erd.svg' style='max-width:100%;'/></body></html>" > erd/index.html
81+
82+
- name: Deploy ERD to GitHub Pages
83+
uses: peaceiris/actions-gh-pages@v4
84+
with:
85+
github_token: ${{ secrets.GITHUB_TOKEN }}
86+
publish_dir: ./erd
87+
force_orphan: true
88+
89+
- name: Comment on PR with ERD Link
90+
uses: peter-evans/create-or-update-comment@v4
91+
with:
92+
issue-number: ${{ github.event.pull_request.number }}
93+
body: |
94+
📌 최신 ERD가 자동 생성되었습니다.
95+
96+
👉 [ERD 보러가기](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/)

.github/workflows/deploy-dev.yml

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,14 @@ jobs:
8585
runs-on: ubuntu-latest
8686
environment: develop
8787
needs: terraform-apply-dev
88+
outputs:
89+
outcome: ${{ job.status }}
90+
has_version: ${{ steps.get_version.outputs.HAS_VERSION }}
91+
version: ${{ steps.get_version.outputs.VERSION }}
8892
steps:
8993
- uses: actions/checkout@v4
94+
with:
95+
fetch-depth: 0
9096

9197
- name: Parse Terraform Outputs and Set Environment Variables
9298
run: |
@@ -107,12 +113,12 @@ jobs:
107113
- name: Update MYSQL_URL in Parameter Store
108114
run: |
109115
MYSQL_URL="jdbc:mysql://${PRIVATE_IP}:3306/eatda?useUnicode=true&characterEncoding=UTF-8"
110-
116+
111117
aws ssm put-parameter \
112-
--name "/dev/MYSQL_URL" \
113-
--type "SecureString" \
114-
--value "$MYSQL_URL" \
115-
--overwrite
118+
--name "/dev/MYSQL_URL" \
119+
--type "SecureString" \
120+
--value "$MYSQL_URL" \
121+
--overwrite
116122
117123
- name: Set up Node.js
118124
uses: actions/setup-node@v4
@@ -131,18 +137,27 @@ jobs:
131137
- name: Semantic Release
132138
id: get_version
133139
run: |
134-
OUTPUT=$(./node_modules/.bin/semantic-release --no-ci)
140+
OUTPUT=$(npm exec --no -- semantic-release --no-ci)
135141
echo "$OUTPUT"
136-
VERSION=$(echo "$OUTPUT" | grep -oP 'Published (?:pre)?release \K[0-9.a-z-]+')
137-
if [ -z "$VERSION" ]; then
142+
VERSION=$(echo "$OUTPUT" | grep -oP 'Published (?:pre)?release v?\K[0-9.a-z.-]+' | head -n 1)
143+
if [[ -z "$VERSION" ]]; then
144+
VERSION=$(echo "$OUTPUT" | grep -oP 'The next release version is \K[0-9.a-z.-]+' | head -n 1)
145+
fi
146+
147+
if [[ -z "$VERSION" ]]; then
138148
echo "릴리즈할 새로운 버전이 없습니다. 배포를 건너뜁니다."
139-
exit 0
149+
echo "HAS_VERSION=false" >> $GITHUB_OUTPUT
150+
else
151+
echo "새 버전($VERSION) 릴리즈가 감지되었습니다."
152+
echo "HAS_VERSION=true" >> $GITHUB_OUTPUT
153+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
154+
echo "SEMANTIC_VERSION=$VERSION" >> $GITHUB_ENV
140155
fi
141-
echo "SEMANTIC_VERSION=$VERSION" >> $GITHUB_ENV
142156
env:
143157
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
144158

145159
- name: Set up JDK 21
160+
if: steps.get_version.outputs.HAS_VERSION == 'true'
146161
uses: actions/setup-java@v4
147162
with:
148163
distribution: 'temurin'
@@ -152,17 +167,14 @@ jobs:
152167
cache: 'gradle'
153168

154169
- name: Get TEST_JWT_SECRET_KEY from SSM
170+
if: steps.get_version.outputs.HAS_VERSION == 'true'
155171
id: get-test-secret
156172
run: |
157-
SECRET_VALUE=$(aws ssm get-parameter \
158-
--name "/common/TEST_JWT_SECRET_KEY" \
159-
--with-decryption \
160-
--region "${{ env.AWS_REGION }}" \
161-
--query "Parameter.Value" \
162-
--output text)
173+
SECRET_VALUE=$(aws ssm get-parameter --name "/common/TEST_JWT_SECRET_KEY" --with-decryption --region "${{ env.AWS_REGION }}" --query "Parameter.Value" --output text)
163174
echo "TEST_JWT_SECRET_KEY=$SECRET_VALUE" >> $GITHUB_ENV
164175
165176
- name: Build with Gradle
177+
if: steps.get_version.outputs.HAS_VERSION == 'true'
166178
run: |
167179
cd ${{ github.workspace }}
168180
chmod +x gradlew
@@ -171,12 +183,14 @@ jobs:
171183
TEST_JWT_SECRET_KEY: ${{ env.TEST_JWT_SECRET_KEY }}
172184

173185
- name: Login to Amazon ECR
186+
if: steps.get_version.outputs.HAS_VERSION == 'true'
174187
id: login-ecr
175188
uses: aws-actions/amazon-ecr-login@v2
176189
with:
177190
mask-password: 'true'
178191

179192
- name: Build, tag, and push image to Amazon ECR
193+
if: steps.get_version.outputs.HAS_VERSION == 'true'
180194
env:
181195
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
182196
run: |
@@ -185,57 +199,95 @@ jobs:
185199
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$SEMANTIC_VERSION" >> $GITHUB_ENV
186200
187201
- name: Get latest ECS task definition
202+
if: steps.get_version.outputs.HAS_VERSION == 'true'
188203
id: get-latest-task-def
189204
run: |
190-
TASK_DEF_ARN=$(aws ecs describe-services --cluster "${{ env.ECS_CLUSTER }}" --services "${{ env.ECS_SERVICE }}" --region "${{ env.AWS_REGION }}" --query "services[0].taskDefinition" --output text)
191-
aws ecs describe-task-definition --task-definition "$TASK_DEF_ARN" --region "${{ env.AWS_REGION }}" --query "taskDefinition" --output json > task-definition.json
205+
TASK_DEF_ARN=$(aws ecs describe-services --cluster "${{ env.ECS_CLUSTER }}" --services "${{ env.ECS_SERVICE }}" --query "services[0].taskDefinition" --output text)
206+
aws ecs describe-task-definition --task-definition "$TASK_DEF_ARN" --query "taskDefinition" --output json > task-definition.json
192207
193208
- name: Fill in the new image ID in the Amazon ECS task definition
209+
if: steps.get_version.outputs.HAS_VERSION == 'true'
194210
id: task-def
195211
uses: aws-actions/amazon-ecs-render-task-definition@v1
196212
with:
197213
task-definition: task-definition.json
198214
container-name: ${{ env.CONTAINER_NAME }}
199215
image: ${{ env.image }}
200216

201-
- name: Deploy Amazon ECS task definition
217+
- name: Deploy Amazon ECS task definition and wait for stability
218+
if: steps.get_version.outputs.HAS_VERSION == 'true'
219+
id: deploy-ecs
202220
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
203221
with:
204222
task-definition: ${{ steps.task-def.outputs.task-definition }}
205223
service: ${{ env.ECS_SERVICE }}
206224
cluster: ${{ env.ECS_CLUSTER }}
207225
wait-for-service-stability: true
208226

227+
- name: Verify deployment by comparing Task Definition ARNs
228+
if: steps.get_version.outputs.HAS_VERSION == 'true'
229+
run: |
230+
DEPLOYED_ARN="${{ steps.deploy-ecs.outputs.task-definition-arn }}"
231+
FINAL_ARN=$(aws ecs describe-services --cluster "${{ env.ECS_CLUSTER }}" --services "${{ env.ECS_SERVICE }}" --query "services[0].taskDefinition" --output text)
232+
233+
echo "배포 시도 ARN: $DEPLOYED_ARN"
234+
echo "실제 적용된 ARN: $FINAL_ARN"
235+
236+
if [[ "$DEPLOYED_ARN" == "$FINAL_ARN" ]]; then
237+
echo "✅ 검증 성공. 서비스가 올바른 새 태스크 정의로 실행 중입니다."
238+
else
239+
echo "❌ 검증 실패. 롤백이 발생했습니다."
240+
echo "서비스가 다른 태스크 정의($FINAL_ARN)로 안정화되었습니다."
241+
exit 1 # 스크립트를 실패 처리하여 워크플로우 잡을 중단시킵니다.
242+
fi
243+
244+
notify:
245+
name: Send Discord Notification
246+
runs-on: ubuntu-latest
247+
needs: deploy-service
248+
if: always()
249+
steps:
209250
- name: Prepare Notification Info
210251
id: vars
211252
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
212253

213254
- name: Discord Notify (Success)
214-
if: success()
255+
if: needs.deploy-service.outputs.has_version == 'true' && needs.deploy-service.outputs.outcome == 'success'
215256
uses: tsickert/[email protected]
216257
with:
217258
webhook-url: ${{ secrets.DISCORD_WEBHOOK }}
218259
embed-title: "✅ 개발 서버 배포 성공!"
219260
embed-color: 65280
220261
embed-description: |
221262
새로운 버전이 성공적으로 배포되었습니다.
222-
223-
**버전**: [v${{ env.SEMANTIC_VERSION }}](${{ github.server_url }}/${{ github.repository }}/releases/tag/v${{ env.SEMANTIC_VERSION }})
263+
**버전**: [v${{ needs.deploy-service.outputs.version }}](${{ github.server_url }}/${{ github.repository }}/releases/tag/v${{ needs.deploy-service.outputs.version }})
224264
**커밋**: [${{ steps.vars.outputs.sha_short }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
225265
**배포자**: ${{ github.actor }}
226266
embed-url: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
227267

228268
- name: Discord Notify (Failure)
229-
if: failure()
269+
if: needs.deploy-service.outputs.has_version == 'true' && needs.deploy-service.outputs.outcome == 'failure'
230270
uses: tsickert/[email protected]
231271
with:
232272
webhook-url: ${{ secrets.DISCORD_WEBHOOK }}
233273
embed-title: "❌ 개발 서버 배포 실패!"
234274
embed-color: 16711680
235275
embed-description: |
236-
배포 과정 중 오류가 발생했습니다. 아래 링크에서 로그를 확인하세요.
237-
238-
**시도 버전**: ${{ env.SEMANTIC_VERSION }}
276+
배포 과정 중 오류가 발생했거나 롤백되었습니다. 아래 링크에서 로그를 확인하세요.
277+
**시도 버전**: v${{ needs.deploy-service.outputs.version }}
278+
**커밋**: [${{ steps.vars.outputs.sha_short }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
279+
**요청자**: ${{ github.actor }}
280+
embed-url: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
281+
282+
- name: Discord Notify (No Version to Release)
283+
if: needs.deploy-service.outputs.has_version == 'false'
284+
uses: tsickert/[email protected]
285+
with:
286+
webhook-url: ${{ secrets.DISCORD_WEBHOOK }}
287+
embed-title: "ℹ️ 개발 서버 배포 건너뜀"
288+
embed-color: 8421504
289+
embed-description: |
290+
릴리즈할 새로운 버전이 없어 배포를 진행하지 않았습니다.
239291
**커밋**: [${{ steps.vars.outputs.sha_short }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
240292
**요청자**: ${{ github.actor }}
241293
embed-url: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"

0 commit comments

Comments
 (0)