From 224c03da393a59a6b49940384c73ecd552ef0978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=5BCLOUD4=5D=20=EA=B9=80=EB=8B=A4=EC=95=A0?= Date: Tue, 20 May 2025 16:06:44 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat=20:=20=EC=9A=B4=EC=98=81=EC=9A=A9=20?= =?UTF-8?q?=EB=B0=B0=ED=8F=AC=20=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eeos/scripts/deploy-product.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 eeos/scripts/deploy-product.sh diff --git a/eeos/scripts/deploy-product.sh b/eeos/scripts/deploy-product.sh new file mode 100644 index 00000000..368fd5d4 --- /dev/null +++ b/eeos/scripts/deploy-product.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +set -ex + +git fetch origin release +git reset --hard origin/release + +./gradlew build -x test + +sudo docker-compose -f docker-compose-prod.yml down + +sudo docker-compose -f docker-compose-prod.yml up --build -d + From b22c4896a98996a475b87e9c0b440c0dc8eb87d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=5BCLOUD4=5D=20=EA=B9=80=EB=8B=A4=EC=95=A0?= Date: Tue, 20 May 2025 16:07:08 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat=20:=20=EC=9A=B4=EC=98=81=EC=9A=A9=20cd?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-cd-prod.yml | 140 ++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 .github/workflows/backend-cd-prod.yml diff --git a/.github/workflows/backend-cd-prod.yml b/.github/workflows/backend-cd-prod.yml new file mode 100644 index 00000000..3de5f178 --- /dev/null +++ b/.github/workflows/backend-cd-prod.yml @@ -0,0 +1,140 @@ +name: CD Deploy + +on: + pull_request: + types: [closed] + branches: ["release"] + +jobs: + deploy: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + steps: + - name: SSH 접속 및 운영용 배포 실행 + id: deploy + uses: appleboy/ssh-action@v0.1.7 + with: + host: ${{ secrets.PROD_HOST }} + username: ${{ secrets.PROD_USERNAME }} + password: ${{ secrets.PROD_PASSWORD }} + port: ${{ secrets.PROD_SSH_PORT }} + script: | + set -ex + cd EEOS-BE/eeos + BRANCH="${{ github.event.pull_request.base.ref }}" + echo "Deploying for branch: ${BRANCH}" + if [ "${BRANCH}" = "release" ]; then + sudo chmod +x ./scripts/deploy-product.sh + ./scripts/deploy-product.sh + else + echo "No deployment script available for branch ${BRANCH}" + exit 1 + fi + + health_check: + needs: deploy + runs-on: ubuntu-latest + outputs: + status: ${{ steps.check.outputs.status }} + steps: + - name: API Health Check + id: check + run: | + echo "Waiting for container to start..." + sleep 20 + HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 https://be.eeos.econovation.kr/api/health-check) + if [ $? -ne 0 ]; then + echo "Health Check timed out." + echo "status=timeout" >> $GITHUB_OUTPUT + elif [ "$HTTP_CODE" = "200" ]; then + echo "status=success" >> $GITHUB_OUTPUT + else + echo "status=failure" >> $GITHUB_OUTPUT + fi + + slack_notify: + needs: [deploy, health_check] + runs-on: ubuntu-latest + if: always() + steps: + - name: Slack 알림 전송 + env: + SLACK_CD_WEBHOOK_URL: ${{ secrets.SLACK_CD_WEBHOOK_URL }} + COMMIT_MESSAGE: ${{ github.event.pull_request.title }} + BRANCH_NAME: ${{ github.event.pull_request.base.ref }} + WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + MERGED_AT: ${{ github.event.pull_request.merged_at }} + HEALTH_STATUS: ${{ needs.health_check.outputs.status }} + DEPLOY_STATUS: ${{ needs.deploy.result }} + run: | + # Determine deployment result based on the deploy job outcome + if [ "${DEPLOY_STATUS}" = "success" ]; then + DEPLOY_TEXT="성공" + BASE_COLOR="#36a64f" + if [ "${HEALTH_STATUS}" = "success" ]; then + HEALTH_TEXT="성공" + elif [ "${HEALTH_STATUS}" = "failure" ]; then + HEALTH_TEXT="실패" + BASE_COLOR="#FF0000" + elif [ "${HEALTH_STATUS}" = "timeout" ]; then + HEALTH_TEXT="Timeout" + BASE_COLOR="#FFA500" + else + HEALTH_TEXT="미실시" + fi + else + DEPLOY_TEXT="실패" + BASE_COLOR="#FF0000" + HEALTH_TEXT="미실시" + fi + + if [ "${BRANCH_NAME}" = "release" ]; then + DEPLOY_TYPE="운영용" + else + DEPLOY_TYPE="${BRANCH_NAME}" + fi + + LOCAL_TIME=$(TZ="Asia/Seoul" date -d "${MERGED_AT}" +'%Y-%m-%d %H:%M:%S') + + PAYLOAD=$(cat <", + "short": false + }, + { + "title": "Merged At", + "value": "\`${LOCAL_TIME}\`", + "short": false + } + ] + } + ] + } + EOF + ) + + echo "$PAYLOAD" + curl -X POST -H "Content-Type: application/json" -d "$PAYLOAD" "$SLACK_CD_WEBHOOK_URL" \ No newline at end of file