Skip to content

Commit e4c2d25

Browse files
committed
ci: 배포 헬스체크를 서버 내부 Actuator 기준으로 전환
1 parent a7909dc commit e4c2d25

1 file changed

Lines changed: 29 additions & 28 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -71,44 +71,45 @@ jobs:
7171
7272
cd ${{ secrets.DEPLOY_PATH }}
7373
74-
echo "[1/3] Pulling latest image..."
74+
echo "[1/5] Pulling latest image..."
7575
docker compose pull git-ranker-api
7676
77-
echo "[2/3] Restarting container..."
77+
echo "[2/5] Restarting container..."
7878
docker compose up -d --no-deps --force-recreate git-ranker-api
7979
80-
echo "[3/3] Cleaning up old images..."
81-
docker image prune -f
80+
echo "[3/5] Waiting for Docker health status..."
81+
for i in {1..12}; do
82+
HEALTH_STATUS=$(docker inspect --format='{{if .State.Health}}{{.State.Health.Status}}{{else}}unknown{{end}}' git-ranker-api 2>/dev/null || echo "missing")
83+
echo "Attempt $i/12 - container health: $HEALTH_STATUS"
8284
83-
echo "=========================================="
84-
echo "Backend Deployment Completed!"
85-
echo "=========================================="
85+
if [ "$HEALTH_STATUS" = "healthy" ]; then
86+
break
87+
fi
8688
87-
- name: Health Check
88-
run: |
89-
echo "Waiting for application to start..."
90-
sleep 45
89+
if [ "$HEALTH_STATUS" = "unhealthy" ] || [ "$i" -eq 12 ]; then
90+
echo "Container health check failed."
91+
docker logs --tail 200 git-ranker-api || true
92+
exit 1
93+
fi
9194
92-
HEALTH_URL="${{ secrets.BACKEND_HEALTH_URL }}"
93-
if [ -z "$HEALTH_URL" ]; then
94-
echo "BACKEND_HEALTH_URL secret is required."
95-
exit 1
96-
fi
97-
echo "Health URL: $HEALTH_URL"
95+
sleep 10
96+
done
9897
99-
for i in {1..5}; do
100-
RESPONSE=$(curl -sS --connect-timeout 5 --max-time 10 -w $'\n%{http_code}' "$HEALTH_URL" || true)
98+
echo "[4/5] Verifying actuator health endpoint..."
99+
HEALTH_URL="http://127.0.0.1:9090/actuator/health"
100+
RESPONSE=$(curl -sS --connect-timeout 5 --max-time 10 -w '\n%{http_code}' "$HEALTH_URL" || true)
101101
HTTP_STATUS=$(printf '%s' "$RESPONSE" | tail -n1)
102102
RESPONSE_BODY=$(printf '%s' "$RESPONSE" | sed '$d')
103103
104-
if [ "$HTTP_STATUS" = "200" ] && echo "$RESPONSE_BODY" | grep -Eq '"status"[[:space:]]*:[[:space:]]*"UP"'; then
105-
echo "Health check passed! (HTTP 200, status=UP)"
106-
exit 0
104+
if [ "$HTTP_STATUS" != "200" ] || ! echo "$RESPONSE_BODY" | grep -Eq '"status"[[:space:]]*:[[:space:]]*"UP"'; then
105+
echo "Actuator health check failed. HTTP=$HTTP_STATUS, body=$RESPONSE_BODY"
106+
docker logs --tail 200 git-ranker-api || true
107+
exit 1
107108
fi
108-
echo "Attempt $i/5 failed. HTTP=$HTTP_STATUS, body=$RESPONSE_BODY"
109-
echo "Retrying in 15s..."
110-
sleep 15
111-
done
112109
113-
echo "Health check failed! Expected HTTP 200 with status=UP."
114-
exit 1
110+
echo "[5/5] Cleaning up old images..."
111+
docker image prune -f
112+
113+
echo "=========================================="
114+
echo "Backend Deployment Completed!"
115+
echo "=========================================="

0 commit comments

Comments
 (0)