Skip to content

Commit f6fa875

Browse files
committed
ci: 롤백시 기존 버전을 덮어쓰지 않게 수정
1 parent 1094699 commit f6fa875

File tree

2 files changed

+41
-38
lines changed

2 files changed

+41
-38
lines changed

.github/workflows/deploy-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ jobs:
114114
run: |
115115
MYSQL_URL="jdbc:mysql://${PRIVATE_IP}:3306/eatda?useUnicode=true&characterEncoding=UTF-8"
116116
117-
aws ssm put-parameter \
117+
aws ssm put-parameter \
118118
--name "/dev/MYSQL_URL" \
119119
--type "SecureString" \
120120
--value "$MYSQL_URL" \

.github/workflows/deploy-prod.yml

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,6 @@ jobs:
9898
- uses: actions/checkout@v4
9999
with:
100100
fetch-depth: 0
101-
fetch-tags: true
102-
103-
- name: Configure AWS credentials
104-
uses: aws-actions/configure-aws-credentials@v4
105-
with:
106-
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
107-
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
108-
aws-region: ${{ env.AWS_REGION }}
109101

110102
- name: Parse Terraform Outputs and Set Environment Variables
111103
run: |
@@ -116,30 +108,42 @@ jobs:
116108
echo "CONTAINER_NAME=$(echo "$TF_OUTPUTS" | jq -r '.ecs_api_container_name.value')" >> $GITHUB_ENV
117109
echo "RDS_ENDPOINT=$(echo "$TF_OUTPUTS" | jq -r '.rds_endpoint.value')" >> $GITHUB_ENV
118110
111+
- name: Configure AWS credentials
112+
uses: aws-actions/configure-aws-credentials@v4
113+
with:
114+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
115+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
116+
aws-region: ${{ env.AWS_REGION }}
117+
119118
- name: Update DB URL in Parameter Store
120119
run: |
121-
aws ssm put-parameter \
122-
--name "/prod/RDS_ENDPOINT" \
123-
--value "jdbc:mysql://${{ env.RDS_ENDPOINT }}/eatda?useUnicode=true&characterEncoding=UTF-8" \
124-
--type SecureString \
125-
--overwrite
120+
aws ssm put-parameter --name "/prod/RDS_ENDPOINT" --value "jdbc:mysql://${{ env.RDS_ENDPOINT }}/eatda?useUnicode=true&characterEncoding=UTF-8" --type SecureString --overwrite
126121
127122
- name: Set up Node.js
128123
uses: actions/setup-node@v4
129124
with:
130125
node-version: '22'
131126

132127
- name: Install Semantic Release dependencies
133-
run: npm install semantic-release @semantic-release/commit-analyzer @semantic-release/release-notes-generator @semantic-release/github @semantic-release/changelog @semantic-release/git conventional-changelog-conventionalcommits
134-
135-
- name: Semantic Release (Dry Run)
128+
run: |
129+
npm install \
130+
semantic-release \
131+
@semantic-release/commit-analyzer \
132+
@semantic-release/release-notes-generator \
133+
@semantic-release/github \
134+
@semantic-release/changelog \
135+
@semantic-release/git \
136+
conventional-changelog-conventionalcommits
137+
138+
- name: Get Next Version or Set Rollback
136139
id: get_version
137140
run: |
138141
if [[ -n "${{ github.event.inputs.rollback_version }}" ]]; then
139142
echo "수동 롤백을 시작합니다. 버전: ${{ github.event.inputs.rollback_version }}"
140143
echo "HAS_VERSION=true" >> $GITHUB_OUTPUT
141144
echo "VERSION=${{ github.event.inputs.rollback_version }}" >> $GITHUB_OUTPUT
142145
echo "SEMANTIC_VERSION=${{ github.event.inputs.rollback_version }}" >> $GITHUB_ENV
146+
echo "SKIP_BUILD=true" >> $GITHUB_OUTPUT
143147
else
144148
echo "배포할 버전을 결정하기 위해 dry-run을 실행합니다..."
145149
OUTPUT=$(npm exec --no -- semantic-release --dry-run --no-ci)
@@ -150,18 +154,20 @@ jobs:
150154
if [[ -z "$VERSION" ]]; then
151155
echo "릴리즈할 새로운 버전이 없습니다. 배포를 건너뜁니다."
152156
echo "HAS_VERSION=false" >> $GITHUB_OUTPUT
157+
echo "SKIP_BUILD=false" >> $GITHUB_OUTPUT
153158
else
154159
echo "배포 예정 버전: $VERSION"
155160
echo "HAS_VERSION=true" >> $GITHUB_OUTPUT
156161
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
157162
echo "SEMANTIC_VERSION=$VERSION" >> $GITHUB_ENV
163+
echo "SKIP_BUILD=false" >> $GITHUB_OUTPUT
158164
fi
159165
fi
160166
env:
161167
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
162168

163169
- name: Set up JDK 21
164-
if: steps.get_version.outputs.HAS_VERSION == 'true'
170+
if: steps.get_version.outputs.HAS_VERSION == 'true' && steps.get_version.outputs.SKIP_BUILD != 'true'
165171
uses: actions/setup-java@v4
166172
with:
167173
distribution: 'temurin'
@@ -171,19 +177,14 @@ jobs:
171177
cache: 'gradle'
172178

173179
- name: Get TEST_JWT_SECRET_KEY from SSM
174-
if: steps.get_version.outputs.HAS_VERSION == 'true'
180+
if: steps.get_version.outputs.HAS_VERSION == 'true' && steps.get_version.outputs.SKIP_BUILD != 'true'
175181
id: get-test-secret
176182
run: |
177-
SECRET_VALUE=$(aws ssm get-parameter \
178-
--name "/common/TEST_JWT_SECRET_KEY" \
179-
--with-decryption \
180-
--region "${{ env.AWS_REGION }}" \
181-
--query "Parameter.Value" \
182-
--output text)
183+
SECRET_VALUE=$(aws ssm get-parameter --name "/common/TEST_JWT_SECRET_KEY" --with-decryption --region "${{ env.AWS_REGION }}" --query "Parameter.Value" --output text)
183184
echo "TEST_JWT_SECRET_KEY=$SECRET_VALUE" >> $GITHUB_ENV
184185
185186
- name: Build with Gradle
186-
if: steps.get_version.outputs.HAS_VERSION == 'true'
187+
if: steps.get_version.outputs.HAS_VERSION == 'true' && steps.get_version.outputs.SKIP_BUILD != 'true'
187188
run: |
188189
cd ${{ github.workspace }}
189190
chmod +x gradlew
@@ -199,14 +200,18 @@ jobs:
199200
mask-password: 'true'
200201

201202
- name: Build, tag, and push image to Amazon ECR
202-
if: steps.get_version.outputs.HAS_VERSION == 'true'
203+
if: steps.get_version.outputs.HAS_VERSION == 'true' && steps.get_version.outputs.SKIP_BUILD != 'true'
203204
env:
204205
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
205206
run: |
206207
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$SEMANTIC_VERSION .
207208
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$SEMANTIC_VERSION
208-
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$SEMANTIC_VERSION" >> $GITHUB_ENV
209-
209+
- name: Set Image URI
210+
if: steps.get_version.outputs.HAS_VERSION == 'true'
211+
id: set-image
212+
run: |
213+
ECR_REGISTRY=$(aws ecr describe-repositories --repository-names ${{ env.ECR_REPOSITORY }} --query "repositories[0].registryId" --output text).dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com
214+
echo "image=$ECR_REGISTRY/${{ env.ECR_REPOSITORY }}:${{ env.SEMANTIC_VERSION }}" >> $GITHUB_OUTPUT
210215
- name: Get latest ECS task definition
211216
if: steps.get_version.outputs.HAS_VERSION == 'true'
212217
id: get-latest-task-def
@@ -221,8 +226,7 @@ jobs:
221226
with:
222227
task-definition: task-definition.json
223228
container-name: ${{ env.CONTAINER_NAME }}
224-
image: ${{ env.image }}
225-
229+
image: ${{ steps.set-image.outputs.image }}
226230
- name: Deploy Amazon ECS task definition and wait for stability
227231
if: steps.get_version.outputs.HAS_VERSION == 'true'
228232
id: deploy-ecs
@@ -237,7 +241,7 @@ jobs:
237241
if: steps.get_version.outputs.HAS_VERSION == 'true'
238242
run: |
239243
DEPLOYED_ARN="${{ steps.deploy-ecs.outputs.task-definition-arn }}"
240-
FINAL_ARN=$(aws ecs describe-services --cluster "${{ env.ECS_CLUSTER }}" --services "${{ env.ECS_SERVICE }}" --query "services[0].taskDefinition" --output text)
244+
FINAL_ARN=$(aws ecs describe-services --cluster "${{ env.ECS_CLUSTER }}" --services "${{ env.ECS_SERVICE }}" --region "${{ env.AWS_REGION }}" --query "services[0].taskDefinition" --output text)
241245
echo "배포 시도 ARN: $DEPLOYED_ARN"
242246
echo "실제 적용된 ARN: $FINAL_ARN"
243247
if [[ "$DEPLOYED_ARN" == "$FINAL_ARN" ]]; then
@@ -248,10 +252,9 @@ jobs:
248252
exit 1
249253
fi
250254
251-
- name: Semantic Release (Final)
252-
if: success() && env.SEMANTIC_VERSION != '' && (github.event.inputs.rollback_version == null || github.event.inputs.rollback_version == '')
253-
run: |
254-
./node_modules/.bin/semantic-release --no-ci
255+
- name: Create GitHub Release (Final)
256+
if: success() && steps.get_version.outputs.HAS_VERSION == 'true' && steps.get_version.outputs.SKIP_BUILD != 'true'
257+
run: npm exec --no -- semantic-release --no-ci
255258
env:
256259
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
257260

@@ -273,7 +276,7 @@ jobs:
273276
embed-title: "✅ 프로덕션 서버 배포 성공!"
274277
embed-color: 65280
275278
embed-description: |
276-
새로운 버전이 성공적으로 배포되었습니다.
279+
새로운 버전이 성공적으로 배포 및 릴리즈되었습니다.
277280
**버전**: [v${{ needs.deploy-service.outputs.version }}](${{ github.server_url }}/${{ github.repository }}/releases/tag/v${{ needs.deploy-service.outputs.version }})
278281
**커밋**: [${{ steps.vars.outputs.sha_short }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
279282
**배포자**: ${{ github.actor }}
@@ -287,7 +290,7 @@ jobs:
287290
embed-title: "❌ 프로덕션 서버 배포 실패!"
288291
embed-color: 16711680
289292
embed-description: |
290-
배포 과정 중 오류가 발생했거나 롤백되었습니다. 아래 링크에서 로그를 확인하세요.
293+
배포 과정 중 오류가 발생했거나 롤백되었습니다. GitHub 릴리즈는 생성되지 않았습니다.
291294
**시도 버전**: v${{ needs.deploy-service.outputs.version }}
292295
**커밋**: [${{ steps.vars.outputs.sha_short }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
293296
**요청자**: ${{ github.actor }}

0 commit comments

Comments
 (0)