Skip to content
Merged
Show file tree
Hide file tree
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
140 changes: 140 additions & 0 deletions .github/workflows/backend-cd-prod.yml
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

if 조건식 표현 오류
if: github.event.pull_request.merged == true${{ }} 없이는 항상 truthy 문자열로 평가됩니다.

if: ${{ github.event.pull_request.merged == true }}

또는

if: ${{ github.event.pull_request.merged }}

로 수정해야 의도대로 동작합니다.

🤖 Prompt for AI Agents
In .github/workflows/backend-cd-prod.yml at line 10, the if condition is missing
the required expression syntax and is treated as a string. Fix this by wrapping
the condition in ${{ }} like if: ${{ github.event.pull_request.merged == true }}
or simplify to if: ${{ github.event.pull_request.merged }} to ensure it
evaluates correctly.

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"
13 changes: 13 additions & 0 deletions eeos/scripts/deploy-product.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

set -ex

Comment on lines +1 to +4
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

set -ex 대신 stricter 옵션 적용 제안
현재 set -ex 만 사용 중인데, undefined 변수나 파이프 실패를 잡지 못합니다.

-#!/bin/sh
-set -ex
+#!/usr/bin/env bash
+set -euxo pipefail

를 적용하여 스크립트 안정성을 높이는 것을 권장합니다.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#!/bin/sh
set -ex
#!/usr/bin/env bash
set -euxo pipefail
🤖 Prompt for AI Agents
In eeos/scripts/deploy-product.sh at lines 1 to 4, replace the current 'set -ex'
with stricter shell options by adding 'set -euo pipefail' to improve script
robustness. This change will make the script exit on errors, treat unset
variables as errors, and catch failures in pipelines, enhancing overall
stability.

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