Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 53 additions & 31 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI/CD Pipeline with Dual Approval Gates
name: CI/CD Pipeline for frontend-service

on:
push:
Expand Down Expand Up @@ -66,40 +66,41 @@ jobs:
with:
name: build-log-${{ needs.build.outputs.version_tag }}

# ▼▼▼ [1단계] 로그를 필터링하여 보낼 메시지를 준비하는 단계 ▼▼▼
- name: Prepare Notification Message
id: prepare_message # 이 스텝의 출력을 참조하기 위해 id 지정
- name: Send Discord Notification with Correctly Formatted Log
run: |
# 1. 이전과 같이 로그에서 문제 라인을 필터링합니다.
KEYWORDS="error|failed|warning|deprecated"
LOG_ISSUES=$(grep -i -E -C 2 "$KEYWORDS" build_log.txt || true)

# 2. 결과에 따라 요약 메시지를 준비합니다.
if [[ -z "$LOG_ISSUES" ]]; then
SUMMARY="✅ 빌드 로그에서 특별한 경고나 에러가 발견되지 않았습니다."
SUMMARY_CONTENT="✅ 빌드 로그에서 특별한 경고나 에러가 발견되지 않았습니다."
else
TRUNCATED_LOGS=$(echo "$LOG_ISSUES" | head -c 1500)
SUMMARY="⚠️ 빌드 로그에서 잠재적인 문제가 발견되었습니다. 아래 요약을 확인해주세요.\\n\\n**Log Issues Summary:**\\n\`\`\`\\n${TRUNCATED_LOGS}\\n\`\`\`"
# JSON에 넣기 전에 " 와 \ 문자만 이스케이프 처리합니다. (줄바꿈 \n은 처리하지 않음)
ESCAPED_LOGS=$(echo "$LOG_ISSUES" | head -c 1500 | sed 's/\\/\\\\/g' | sed 's/"/\\"/g')
SUMMARY_CONTENT="⚠️ 빌드 로그에서 잠재적인 문제가 발견되었습니다. 아래 요약을 확인해주세요.\n\n**Log Issues Summary:**\n\`\`\`\n${ESCAPED_LOGS}\n\`\`\`"
fi

# 다음 스텝에서 사용할 수 있도록 summary 내용을 output으로 설정
# EOF를 사용하여 여러 줄의 문자열을 안정적으로 전달
{
echo "summary<<EOF"
echo "$SUMMARY"
echo "EOF"
} >> "$GITHUB_OUTPUT"
# 3. 최종 description 내용을 만듭니다.
FINAL_DESCRIPTION="${SUMMARY_CONTENT}\n\n[➡️ 전체 로그 및 승인 페이지로 이동](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"

# ▼▼▼ [2단계] 준비된 메시지를 담아 Discord 알림을 보내는 단계 ▼▼▼
- name: Send Discord Notification for ECR Push Approval
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }}
title: "🔎 [1차 승인] ECR Push 승인 요청: ${{ needs.build.outputs.version_tag }}"
# description에 바로 앞 스텝의 'summary' output을 사용
description: |
${{ steps.prepare_message.outputs.summary }}

[➡️ 전체 로그 및 승인 페이지로 이동](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
color: 49151 # 16진수 0x00BFFF
# 4. JSON에 넣기 위해 다시 한번 전체 description의 특수문자를 이스케이프 합니다.
JSON_FRIENDLY_DESCRIPTION=$(echo "$FINAL_DESCRIPTION" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g')

# 5. heredoc을 사용하여 JSON 페이로드를 생성하고 curl로 바로 전송합니다.
curl -X POST -H "Content-Type: application/json" \
-d @- \
"${{ secrets.DISCORD_WEBHOOK_URL }}" <<EOF
{
"embeds": [
{
"title": "🔎 [1차 승인] ECR Push 승인 요청: ${{ needs.build.outputs.version_tag }}",
"description": "${JSON_FRIENDLY_DESCRIPTION}",
"color": 49151
}
]
}
EOF

# =====================================
# JOB 3: ECR 푸시 실행 (1차 승인 게이트)
Expand Down Expand Up @@ -128,9 +129,9 @@ jobs:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: 326536620954dkr.ecr.ap-northeast-2.amazonaws.com/highfive/highfive-frontend:${{ needs.build.outputs.version_tag }}
cache-from: type=registry,ref=326536620954dkr.ecr.ap-northeast-2.amazonaws.com/highfive/highfive-frontend:buildcache
cache-to: type=registry,ref=326536620954dkr.ecr.ap-northeast-2.amazonaws.com/highfive/highfive-frontend:buildcache,mode=max
tags: 326536620954.dkr.ecr.ap-northeast-2.amazonaws.com/highfive/highfive-frontend:${{ needs.build.outputs.version_tag }}
cache-from: type=registry,ref=326536620954.dkr.ecr.ap-northeast-2.amazonaws.com/highfive/highfive-frontend:buildcache
cache-to: type=registry,ref=326536620954.dkr.ecr.ap-northeast-2.amazonaws.com/highfive/highfive-frontend:buildcache,mode=max

# ==================================================
# JOB 4: 2차 승인 알림 발송 (EKS 배포)
Expand Down Expand Up @@ -167,10 +168,31 @@ jobs:
path: 'config-repo'
- name: Update manifest file
run: |
sed -i -E "s|^(\s*image:\s*).*|\1326536620954dkr.ecr.ap-northeast-2.amazonaws.com/highfive/highfive-frontend:${{ needs.build.outputs.version_tag }}|" config-repo/highfive-frontend-service.yaml
sed -i -E "s|^(\s*image:\s*).*|\1326536620954.dkr.ecr.ap-northeast-2.amazonaws.com/highfive/highfive-frontend:${{ needs.build.outputs.version_tag }}|" config-repo/highfive-frontend-service.yaml
- name: Commit and push changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Deploy image ${{ needs.build.outputs.version_tag }} for highfive-frontend-service"
repository: 'config-repo'
file_pattern: 'highfive-frontend-service.yaml'
file_pattern: 'highfive-frontend-service.yaml'

# ==========================================================
# JOB 6: 워크플로우 실패 시 알림
# ==========================================================
notify-on-failure:
# 'if: failure()'는 이전 잡 중 하나라도 실패하면 이 잡을 실행시킵니다.
if: failure()
# 실패 여부와 상관없이 항상 실행되어야 하는 이전 잡들에 대한 needs 설정
# 이 잡이 모든 주요 잡들이 끝난 후에 실행되도록 보장합니다.
needs: [build, push-to-ecr, deploy-to-eks]
runs-on: ubuntu-latest
steps:
- name: Send Discord Failure Notification
run: |
JSON_PAYLOAD=$(printf '{"embeds":[{"title":"❌ CI/CD 파이프라인 실패","description":"`${{ github.repository }}` 레포지토리의 워크플로우 실행에 실패했습니다.\n자세한 내용은 아래 링크에서 확인해주세요.\n\n[➡️ 실패한 워크플로우 로그 확인하기](https://github.com/%s/actions/runs/%s)","color":15158332}]}' \
"${{ github.repository }}" \
"${{ github.run_id }}")

curl -X POST -H "Content-Type: application/json" \
-d "$JSON_PAYLOAD" \
"${{ secrets.DISCORD_WEBHOOK_URL }}"