From 047d1def627ac010ff2ffe4b156d1af1e90122c6 Mon Sep 17 00:00:00 2001 From: yujamint Date: Fri, 26 Jul 2024 00:18:51 +0900 Subject: [PATCH] =?UTF-8?q?Revert=20"Revert=20"feat:=20Nginx=20=EB=8F=84?= =?UTF-8?q?=EC=9E=85=20=EB=B0=8F=20=EB=B8=94=EB=A3=A8/=EA=B7=B8=EB=A6=B0?= =?UTF-8?q?=20=EB=AC=B4=EC=A4=91=EB=8B=A8=20=EB=B0=B0=ED=8F=AC=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9""?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit fcdd4487e25b552731b8ea3f53cfdd9402ad74e2. --- .github/workflows/deploy-prod.yaml | 55 ++++++++++++++++++++++++++---- build.gradle | 3 ++ 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy-prod.yaml b/.github/workflows/deploy-prod.yaml index 825c94f..db5872e 100644 --- a/.github/workflows/deploy-prod.yaml +++ b/.github/workflows/deploy-prod.yaml @@ -53,10 +53,53 @@ jobs: host: ${{ secrets.PROD_SERVER_HOST }} username: ${{ secrets.PROD_SERVER_USERNAME }} key: ${{ secrets.PROD_SERVER_PEM_KEY }} - envs: GITHUB_SHA + envs: GITHUB_SHA, DOCKERHUB_USERNAME script: | - sudo docker stop $(sudo docker ps -a -q) - sudo docker rm $(sudo docker ps -a -q) - sudo docker pull ${{secrets.DOCKERHUB_USERNAME}}/qtudy-server:prod - sudo docker run -d -p 8080:8080 --name qtudy-server-container ${{secrets.DOCKERHUB_USERNAME}}/qtudy-server:prod - sudo docker image prune -f + # 현재 활성화된 Nginx 설정 파일 확인 + CURRENT_CONF=$(sudo readlink /etc/nginx/sites-enabled/current) + echo "Current Nginx configuration: $CURRENT_CONF" + if [[ "$CURRENT_CONF" == *"blue" ]]; then + NEW_CONF="/etc/nginx/sites-available/green" + OLD_CONTAINER="blue-container" + NEW_CONTAINER="green-container" + NEW_PORT=8081 + else + NEW_CONF="/etc/nginx/sites-available/blue" + OLD_CONTAINER="green-container" + NEW_CONTAINER="blue-container" + NEW_PORT=8080 + fi + + echo "New Nginx configuration: $NEW_CONF" + echo "Old container: $OLD_CONTAINER" + echo "New container: $NEW_CONTAINER" + echo "New port: $NEW_PORT" + + # 새 Docker 이미지 가져오기 + sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/qtudy-server:prod + + # 새로운 컨테이너 실행 + sudo docker run -d -p $NEW_PORT:8080 --name $NEW_CONTAINER ${{ secrets.DOCKERHUB_USERNAME }}/qtudy-server:prod + + # 새로운 컨테이너가 준비될 때까지 대기 + echo "Waiting for the new container to be ready..." + sleep 10 + + # 헬스 체크를 통해 새 컨테이너가 정상적으로 실행 중인지 확인 + until [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:$NEW_PORT/actuator/health)" == "200" ]]; do + echo "Waiting for the new container to respond with HTTP 200..." + sleep 2 + done + + echo "New container is ready. Switching Nginx configuration." + + # Nginx 설정 파일 교체 및 재시작 + sudo ln -sf $NEW_CONF /etc/nginx/sites-enabled/current + sudo systemctl reload nginx + + # 이전 컨테이너 중지 및 제거 + sudo docker stop $OLD_CONTAINER + sudo docker rm $OLD_CONTAINER + + # 사용하지 않는 Docker 이미지 정리 + sudo docker image prune -f \ No newline at end of file diff --git a/build.gradle b/build.gradle index 90dbf9e..0a2a3d4 100644 --- a/build.gradle +++ b/build.gradle @@ -49,6 +49,9 @@ dependencies { implementation 'org.mapstruct:mapstruct:1.5.3.Final' annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final' + // Spring Boot Actuator + implementation 'org.springframework.boot:spring-boot-starter-actuator' + // GPT 스크립트 테스트 편의성을 위해 추가 testAnnotationProcessor 'org.projectlombok:lombok' testImplementation 'com.theokanning.openai-gpt3-java:service:0.18.2'