124 lines
4.9 KiB
YAML
124 lines
4.9 KiB
YAML
name: Deploy to OCIWP
|
||
|
||
on:
|
||
push:
|
||
branches:
|
||
- main
|
||
- master
|
||
workflow_dispatch:
|
||
|
||
jobs:
|
||
deploy:
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
|
||
- name: Checkout Code
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Sync Code to Host Volume
|
||
run: |
|
||
echo "Cleaning up old src directories to prevent stale source files..."
|
||
rm -rf /app/*/src
|
||
echo "Copying latest code to /app (Host Volume)..."
|
||
cp -a . /app/
|
||
|
||
- name: Deploy Task on Host
|
||
run: |
|
||
echo "Starting Blue-Green CI/CD Deploy pipeline..."
|
||
|
||
# 1. (?œê±°?? ?¸ìФ??볼륨?<3F>서??불필?”한 gradle 빌드 ?œì™¸ - Dockerfile ?´ì—<C3AC>???´ë? ?˜í–‰?˜ë?ë¡?OOM ë°©ì?)
|
||
|
||
cd /app
|
||
|
||
# 3. 블루/그린 ?€ê²??<3F>별
|
||
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
|
||
|
||
# 3.5. 공통 ?¸í”„??(DB, Redis ?? 먼ì? ?„ìš°ê¸?(Nginx ?œì™¸)
|
||
ACTIVE_PROFILE=dev docker compose up -d redis mci-mock dozzle
|
||
|
||
# 4. ? ê·œ ë²„ì „(TARGET) 컨테?´ë„ˆ 기ë<C2B0>™
|
||
echo "Building and starting $TARGET containers sequentially to prevent OOM..."
|
||
ACTIVE_PROFILE=dev docker compose build gateway-$TARGET
|
||
ACTIVE_PROFILE=dev docker compose build tool-sms-$TARGET
|
||
ACTIVE_PROFILE=dev docker compose build tool-email-$TARGET
|
||
ACTIVE_PROFILE=dev docker compose build tool-other-$TARGET
|
||
ACTIVE_PROFILE=dev docker compose build tool-payment-$TARGET
|
||
|
||
ACTIVE_PROFILE=dev docker compose up -d gateway-$TARGET
|
||
sleep 5
|
||
ACTIVE_PROFILE=dev docker compose up -d tool-sms-$TARGET
|
||
sleep 5
|
||
ACTIVE_PROFILE=dev docker compose up -d tool-email-$TARGET
|
||
sleep 5
|
||
ACTIVE_PROFILE=dev docker compose up -d tool-other-$TARGET
|
||
sleep 5
|
||
ACTIVE_PROFILE=dev docker compose up -d tool-payment-$TARGET
|
||
|
||
# 4.5. ?ˆê±°??컨테?´ë„ˆ ì²?†Œ (?¬íЏ ì¶©ë<C2A9>Œ ë°©ì?, Nginx ?œì™¸)
|
||
echo "Finding and killing legacy containers holding our ports..."
|
||
|
||
|
||
# 4.6. Nginx 초기 ?¤ì • ë°?기ë<C2B0>™
|
||
mkdir -p ./nginx/conf.d
|
||
echo "Initializing Nginx config to $TARGET..."
|
||
cp ./nginx/${TARGET}.conf ./nginx/conf.d/default.conf
|
||
ACTIVE_PROFILE=dev docker compose up -d nginx
|
||
|
||
# 5. Health Check (??ë²„ì „???•ìƒ<C3AC>?<3F>으ë¡??´ëŠ”ì§€ ?•ì<E280A2>¸)
|
||
echo "Curling gateway locally:"
|
||
curl -sv http://localhost:8081/index.html
|
||
echo "Waiting 30 seconds for services to fully start..."
|
||
sleep 30
|
||
|
||
# ? ê·œ 컨테?´ë„ˆê°€ 죽ì? ?Šê³ ?´ì•„?ˆëŠ”ì§€ ?•ì<E280A2>¸
|
||
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 "Rolling back Nginx config to $OLD_TARGET..."
|
||
cp ./nginx/${OLD_TARGET}.conf ./nginx/conf.d/default.conf
|
||
echo "Restarting Nginx to apply rollback..."
|
||
docker compose restart nginx || true
|
||
echo "Stopping failed $TARGET containers..."
|
||
docker compose stop gateway-$TARGET tool-sms-$TARGET tool-email-$TARGET tool-other-$TARGET tool-payment-$TARGET
|
||
exit 1 # ?Œì<C592>´?„ë<E2809E>¼???¤íŒ¨ 처리 (구버?„ì? ê·¸ë?ë¡?? ì???
|
||
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
|
||
|
||
if ! docker compose exec -T nginx nginx -s reload; then
|
||
echo "Nginx reload failed! Rolling back Nginx configuration..."
|
||
cp ./nginx/${OLD_TARGET}.conf ./nginx/conf.d/default.conf
|
||
docker compose exec -T nginx nginx -s reload || true
|
||
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
|
||
|
||
# 7. 구버??종료
|
||
echo "Traffic switched successfully. 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 "Blue-Green CI/CD Deploy Success! Currently running: $TARGET"
|
||
|
||
|
||
|
||
|