diff --git a/.github/workflows/Dev_CD.yml b/.github/workflows/Dev_CD.yml index 8718cc23..e9a4e830 100644 --- a/.github/workflows/Dev_CD.yml +++ b/.github/workflows/Dev_CD.yml @@ -1,6 +1,7 @@ name: dev-cd on: + workflow_dispatch: push: branches: - "develop" @@ -10,10 +11,8 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout Develop Branch + - name: Checkout Branch uses: actions/checkout@v4 - with: - ref: "develop" - name: Setting dev-secret.yml run: | @@ -66,7 +65,18 @@ jobs: uses: actions/download-artifact@v4 with: name: deploy-scripts - path: ~/app/scripts + path: ~/app/scripts/ - name: Replace application to latest run: sudo sh ~/app/scripts/replace-new-version.sh + + - name: Health Check + run: sh ~/app/scripts/health-check.sh + + - name: Send Discord Alert on Failure + if: failure() + run: | + curl -H "Content-Type: application/json" \ + -X POST \ + -d "{\"content\":\":x: [DEV] 배포 실패! 확인이 필요합니다.\n링크: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}" \ + ${{ secrets.DISCORD_WEB_HOOK }} diff --git a/.github/workflows/Prod_CD.yml b/.github/workflows/Prod_CD.yml index 20e0c517..cb10ee58 100644 --- a/.github/workflows/Prod_CD.yml +++ b/.github/workflows/Prod_CD.yml @@ -1,6 +1,7 @@ name: prod-cd on: + workflow_dispatch: push: branches: - "main" @@ -12,8 +13,6 @@ jobs: steps: - name: Checkout Develop Branch uses: actions/checkout@v4 - with: - ref: "main" - name: Setting prod-secret.yml run: | @@ -66,7 +65,18 @@ jobs: uses: actions/download-artifact@v4 with: name: deploy-scripts - path: ~/app/scripts + path: ~/app/scripts/ - name: Replace application to latest run: sudo sh ~/app/scripts/replace-new-version.sh + + - name: Health Check + run: sh ~/app/scripts/health-check.sh + + - name: Send Discord Alert on Failure + if: failure() + run: | + curl -H "Content-Type: application/json" \ + -X POST \ + -d "{\"content\":\":warning: :warning: [PROD] 배포 실패! :warning: :warning: \n링크: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}" \ + ${{ secrets.DISCORD_WEB_HOOK }} diff --git a/scripts/dev/health-check.sh b/scripts/dev/health-check.sh new file mode 100644 index 00000000..96fd66fc --- /dev/null +++ b/scripts/dev/health-check.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# 최대 반복 횟수 +MAX_RETRIES=60 + +# 성공 상태 코드와 요청 URL +SUCCESS_STATUS=200 +HEALTH_CHECK_URL="http://localhost:8083/monitoring/health" + +# 반복 시작 +i=1 +while [ "$i" -le "$MAX_RETRIES" ]; do + # HTTP 요청 보내기 + RESPONSE_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$HEALTH_CHECK_URL") + echo "[TRY $i] StatusCode : $RESPONSE_STATUS " + # 상태 코드 확인 + if [ "$RESPONSE_STATUS" -eq "$SUCCESS_STATUS" ]; then + echo "Success: Received $SUCCESS_STATUS status code on attempt $i." + exit 0 + fi + + # 2초 대기 + sleep 2 + + # 반복 변수 증가 + i=$((i + 1)) +done + +# 실패 메시지 +echo "Failure: Did not receive $SUCCESS_STATUS status code within $MAX_RETRIES attempts." +exit 1 diff --git a/scripts/prod/health-check.sh b/scripts/prod/health-check.sh new file mode 100644 index 00000000..96fd66fc --- /dev/null +++ b/scripts/prod/health-check.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# 최대 반복 횟수 +MAX_RETRIES=60 + +# 성공 상태 코드와 요청 URL +SUCCESS_STATUS=200 +HEALTH_CHECK_URL="http://localhost:8083/monitoring/health" + +# 반복 시작 +i=1 +while [ "$i" -le "$MAX_RETRIES" ]; do + # HTTP 요청 보내기 + RESPONSE_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$HEALTH_CHECK_URL") + echo "[TRY $i] StatusCode : $RESPONSE_STATUS " + # 상태 코드 확인 + if [ "$RESPONSE_STATUS" -eq "$SUCCESS_STATUS" ]; then + echo "Success: Received $SUCCESS_STATUS status code on attempt $i." + exit 0 + fi + + # 2초 대기 + sleep 2 + + # 반복 변수 증가 + i=$((i + 1)) +done + +# 실패 메시지 +echo "Failure: Did not receive $SUCCESS_STATUS status code within $MAX_RETRIES attempts." +exit 1