From b84c61fcf19062b85009fd433838d613a006cfae Mon Sep 17 00:00:00 2001 From: woojong Date: Thu, 24 Oct 2024 17:22:05 +0900 Subject: [PATCH] Modify/#398 infra zero down time (#422) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: 서브모듈 커밋 시점 변경 * docs: 액츄에이터 의존성 추가 * infra: 무중단 배포를 위한 cd 스크립트 변경 * infra: 테스트와 빌드 하나로 통합 * infra: 스크립트 수정 * infra: 스크립트 수정 * infra: 스크립트 수정 * infra: 스크립트 수정 * infra: 스크립트 수정 * infra: 스크립트 수정 * infra: 스크립트 수정 * infra: 서비스 상태 체크 및 종료 로직 추가 --- .github/workflows/Backend-CD-Prod-A.yml | 33 ++++++++++++++++--------- .github/workflows/Backend-CD-Prod-B.yml | 33 ++++++++++++++++--------- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/.github/workflows/Backend-CD-Prod-A.yml b/.github/workflows/Backend-CD-Prod-A.yml index 95acc87e..bee3772b 100644 --- a/.github/workflows/Backend-CD-Prod-A.yml +++ b/.github/workflows/Backend-CD-Prod-A.yml @@ -42,23 +42,32 @@ jobs: -e TZ=Asia/Seoul \ ${{ secrets.DOCKER_SERVER_IMAGE }} - - name: Wait for service to start - run: | - echo "Waiting for the service to start..." - sleep 30 - - name: Check service availability run: | - HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" http://localhost:80/actuator/health) - if [ "$HTTP_STATUS" -eq 200 ]; then - echo "Service is up and running" - else - echo "Service is not responding. HTTP Status: $HTTP_STATUS" - exit 1 - fi + SUCCESS=false + + for i in {1..10}; do + HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" http://localhost:80/actuator/health) + if [ "$HTTP_STATUS" -eq 200 ]; then + echo "Service is up and running" + SUCCESS=true + break + else + echo "Attempt $i: Service is not responding. HTTP Status: $HTTP_STATUS" + sleep 3 + fi + done - name: Port forwarding end run: | sudo iptables -t nat -D PREROUTING 1 sudo iptables -t nat -D POSTROUTING 1 sudo iptables -D INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT + sudo iptables -L -v -t nat + + - name: Exit if fails + run: | + if [ "$SUCCESS" = false ]; then + echo "Service did not respond successfully after $ATTEMPTS attempts" + sudo exit 1 + fi diff --git a/.github/workflows/Backend-CD-Prod-B.yml b/.github/workflows/Backend-CD-Prod-B.yml index 9265fe79..3c742359 100644 --- a/.github/workflows/Backend-CD-Prod-B.yml +++ b/.github/workflows/Backend-CD-Prod-B.yml @@ -42,23 +42,32 @@ jobs: -e TZ=Asia/Seoul \ ${{ secrets.DOCKER_SERVER_IMAGE }} - - name: Wait for service to start - run: | - echo "Waiting for the service to start..." - sleep 30 - - name: Check service availability run: | - HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" http://localhost:80/actuator/health) - if [ "$HTTP_STATUS" -eq 200 ]; then - echo "Service is up and running" - else - echo "Service is not responding. HTTP Status: $HTTP_STATUS" - exit 1 - fi + SUCCESS=false + + for i in {1..10}; do + HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" http://localhost:80/actuator/health) + if [ "$HTTP_STATUS" -eq 200 ]; then + echo "Service is up and running" + SUCCESS=true + break + else + echo "Attempt $i: Service is not responding. HTTP Status: $HTTP_STATUS" + sleep 3 + fi + done - name: Port forwarding end run: | sudo iptables -t nat -D PREROUTING 1 sudo iptables -t nat -D POSTROUTING 1 sudo iptables -D INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT + sudo iptables -L -v -t nat + + - name: Exit if fails + run: | + if [ "$SUCCESS" = false ]; then + echo "Service did not respond successfully after $ATTEMPTS attempts" + sudo exit 1 + fi