feat: 적용 무중단 배포 시스템 (Blue-Green Deployment)
Some checks failed
Deploy to OCIWP / deploy (push) Failing after 51s

This commit is contained in:
jade
2026-07-24 08:51:01 +09:00
parent 60a7226199
commit 8b11c1aae8
8 changed files with 489 additions and 80 deletions

View File

@@ -22,7 +22,7 @@ jobs:
- name: Deploy Task on Host
run: |
echo "Starting Standard CI/CD Deploy pipeline..."
echo "Starting Blue-Green CI/CD Deploy pipeline..."
# 1. gradle 공식 이미지로 바로 컴파일 빌드!
docker run --rm \
@@ -36,22 +36,59 @@ jobs:
# 2. 빌드 결과 plain jar 아카이브 정리
find /app -name "*-plain.jar" -delete
# 3. 좀비 컨테이너 청소 (현재 우리가 쓸 포트를 점유 중인 옛날 컨테이너들만 정확히 색출해서 사살)
echo "Finding and killing zombie containers holding our ports..."
for port in 6379 8080 8089 8281 8282 8283 8284 8285 8288; do
cid=$(docker ps -q --filter "publish=$port")
if [ ! -z "$cid" ]; then
echo "Force killing container $cid using port $port"
docker rm -f $cid
fi
done
# 4. 마운트된 /app 디렉토리로 이동하여 호스트의 도커 컴포즈 제어!
cd /app
docker system prune -f
ACTIVE_PROFILE=dev docker compose up -d --build gateway redis mci-mock dozzle tool-sms tool-email tool-other tool-payment
# 4. 배포 후 대롱대롱 매달려 있는 가비지 이미지 자동 소거 청소!
# 3. 블루/그린 타겟 식별
IS_BLUE_RUNNING=$(docker ps --filter "name=ax_hub_mcp_tool-gateway-blue-1" --filter "status=running" -q)
if [ ! -z "$IS_BLUE_RUNNING" ]; then
echo "Current active color is BLUE. Deploying to GREEN..."
TARGET="green"
OLD_TARGET="blue"
else
echo "Current active color is GREEN (or none). Deploying to BLUE..."
TARGET="blue"
OLD_TARGET="green"
fi
# 공통 인프라 (DB, Redis 등) 띄우기
ACTIVE_PROFILE=dev docker compose up -d redis mci-mock dozzle nginx
# 4. 신규 버전(TARGET) 컨테이너 기동
echo "Building and starting $TARGET containers..."
ACTIVE_PROFILE=dev docker compose up -d --build \
gateway-$TARGET \
tool-sms-$TARGET \
tool-email-$TARGET \
tool-other-$TARGET \
tool-payment-$TARGET
# 5. 헬스 체크 대기 (Spring Boot 기동 시간 확보)
echo "Waiting 30 seconds for Spring Boot to start..."
sleep 30
# 신규 컨테이너가 죽지 않고 살아있는지 확인
IS_TARGET_ALIVE=$(docker ps --filter "name=ax_hub_mcp_tool-gateway-${TARGET}-1" --filter "status=running" -q)
if [ -z "$IS_TARGET_ALIVE" ]; then
echo "Health Check Failed! $TARGET container crashed. Rollback."
echo "Stopping failed $TARGET containers..."
docker compose stop gateway-$TARGET tool-sms-$TARGET tool-email-$TARGET tool-other-$TARGET tool-payment-$TARGET
exit 1 # 파이프라인 실패 처리 (구버전은 그대로 유지됨)
fi
# 6. 트래픽 전환 (Nginx 설정 스위칭)
echo "Health Check Passed! Switching traffic to $TARGET..."
mkdir -p ./nginx/conf.d
cp ./nginx/${TARGET}.conf ./nginx/conf.d/default.conf
docker compose exec -T nginx nginx -s reload
# 7. 구버전 종료
echo "Traffic switched. Stopping old $OLD_TARGET containers..."
docker compose stop gateway-$OLD_TARGET tool-sms-$OLD_TARGET tool-email-$OLD_TARGET tool-other-$OLD_TARGET tool-payment-$OLD_TARGET
# 가비지 청소
docker system prune -f
docker image prune -f
echo "CI/CD Deploy Success!"
echo "Blue-Green CI/CD Deploy Success! Currently running: $TARGET"