134 lines
5.4 KiB
YAML
134 lines
5.4 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>거?? ?<3F>스??볼륨?<3F>서??불필?<3F>한 gradle 빌드 ?<3F>외 - Dockerfile ?<3F>에???<3F><>? ?<3F>행?<3F><>?<3F>?OOM 방<>?)
|
||
|
||
cd /app
|
||
|
||
# 3. 블루/그린 ?<3F><>??<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. 공통 ?<3F>프??(DB, Redis ?? 먼<>? ?<3F>우<EFBFBD>?(Nginx ?<3F>외)
|
||
ACTIVE_PROFILE=dev docker compose up -d redis mci-mock dozzle
|
||
|
||
# 4. ?<3F>규 버전(TARGET) 컨테?<3F>너 기동
|
||
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. 제거할 컨테이너 (포트 충돌 방지, Nginx 제외)
|
||
echo "Finding and killing legacy containers holding our ports..."
|
||
for port in 6379 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.6. Nginx 초기 ?정 ?기동
|
||
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 (??버전???<3F>상?<3F>으<EFBFBD>??<3F>는지 ?<3F>인)
|
||
echo "Curling gateway locally:"
|
||
curl -sv http://localhost:8081/index.html
|
||
echo "Fetching gateway logs..."
|
||
docker logs --tail 100 ax_hub_mcp_tool-gateway-$TARGET-1
|
||
echo "Waiting 30 seconds for services to fully start..."
|
||
sleep 30
|
||
|
||
# ?<3F>규 컨테?<3F>너가 죽<>? ?<3F>고 ?<3F>아?<3F>는지 ?<3F>인
|
||
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 # ?<3F>이?<3F>라???<3F>패 처리 (구버?<3F><>? 그<>?<3F>??<3F><>???
|
||
fi
|
||
|
||
# 6. ?<3F>래???<3F>환 (Nginx ?<3F>정 ?<3F>위<EFBFBD>?
|
||
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
|
||
|
||
# 가비<EAB080>? <20>?<3F><>
|
||
docker system prune -f
|
||
docker image prune -f
|
||
|
||
echo "Blue-Green CI/CD Deploy Success! Currently running: $TARGET"
|
||
|
||
|
||
|
||
|
||
|