-
Notifications
You must be signed in to change notification settings - Fork 1
[CHORE] 운영용 CD 추가 #253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CHORE] 운영용 CD 추가 #253
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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/[email protected] | ||
| 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 <<EOF | ||
| { | ||
| "username": "배포 알림", | ||
| "attachments": [ | ||
| { | ||
| "color": "${BASE_COLOR}", | ||
| "title": "${DEPLOY_TYPE} 배포 : ${DEPLOY_TEXT}", | ||
| "fields": [ | ||
| { | ||
| "title": "Health Check", | ||
| "value": "\`${HEALTH_TEXT}\`", | ||
| "short": false | ||
| }, | ||
| { | ||
| "title": "Commit Message", | ||
| "value": "\`${COMMIT_MESSAGE}\`", | ||
| "short": false | ||
| }, | ||
| { | ||
| "title": "브랜치", | ||
| "value": "\`${BRANCH_NAME}\`", | ||
| "short": false | ||
| }, | ||
| { | ||
| "title": "Workflow URL", | ||
| "value": "<${WORKFLOW_URL}|자세히 보기>", | ||
| "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" | ||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,13 @@ | ||||||||||||
| #!/bin/sh | ||||||||||||
|
|
||||||||||||
| set -ex | ||||||||||||
|
|
||||||||||||
|
Comment on lines
+1
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion
-#!/bin/sh
-set -ex
+#!/usr/bin/env bash
+set -euxo pipefail를 적용하여 스크립트 안정성을 높이는 것을 권장합니다. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
| 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 | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if조건식 표현 오류if: github.event.pull_request.merged == true는${{ }}없이는 항상 truthy 문자열로 평가됩니다.또는
로 수정해야 의도대로 동작합니다.
🤖 Prompt for AI Agents