From c92478b0c39b127ca20a6d11c872047523941940 Mon Sep 17 00:00:00 2001 From: GiSeok Kang Date: Thu, 27 Nov 2025 17:06:47 +0900 Subject: [PATCH 01/17] =?UTF-8?q?chore:=20dev=20=EC=84=9C=EB=B2=84=20?= =?UTF-8?q?=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-dev-cd.yml | 54 ++++++---------------------- 1 file changed, 10 insertions(+), 44 deletions(-) diff --git a/.github/workflows/backend-dev-cd.yml b/.github/workflows/backend-dev-cd.yml index f2e3ec2eb..c7ff01a53 100644 --- a/.github/workflows/backend-dev-cd.yml +++ b/.github/workflows/backend-dev-cd.yml @@ -1,7 +1,7 @@ name: Backend Dev Server CD on: - push: + pull_request: branches: [ backend ] workflow_dispatch: @@ -52,49 +52,15 @@ jobs: deploy: name: 개발서버 배포 needs: build - runs-on: [ self-hosted, dev-app ] - defaults: - run: - working-directory: /home/ssm-user/coursepick + runs-on: ubuntu-latest steps: - - name: Docker 로그인 - uses: docker/login-action@v3 + - name: SSH로 배포 스크립트 실행 + uses: appleboy/ssh-action@v1.0.0 with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: .env 파일 생성 - run: | - cat > .env <<'EOF' - ${{ secrets.DEV_ENV_FILE }} - EOF - chmod 600 .env - - - name: 새로운 서버 시작 - run: | - sudo docker compose --env-file .env up -d --pull always backend - - - name: 사용하지 않는 도커 이미지 정리 - run: | - sudo docker image prune -a -f - - - name: 시작된 서버 헬스체크 - run: | - for i in $(seq 1 10) - do - SERVER_STATUS=$(curl -o /dev/null -w "%{http_code}" http://localhost:80/actuator/health || true) - - if [ "$SERVER_STATUS" -eq 200 ]; then - echo "서버 정상적으로 실행됨 status=$SERVER_STATUS" - break - else - echo "헬스체크에 실패함. 5초 후 다시 시도" - sleep 5 - fi - - if [ $i -eq 10 ]; then - echo "서버가 정상적으로 실행되지 않아 종료함" - exit 1 - fi - done + host: ${{ secrets.DEV_SERVER_HOST }} + username: ubuntu + key: ${{ secrets.SSH_PRIVATE_KEY }} + script: | + cd /home/ubuntu/coursepick + ./deploy.sh From b33380c85acbf191cf0ccdef038bb982b2de9dbb Mon Sep 17 00:00:00 2001 From: GiSeok Kang Date: Thu, 27 Nov 2025 17:11:40 +0900 Subject: [PATCH 02/17] =?UTF-8?q?chore:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EB=A5=BC=20=EC=9C=84=ED=95=B4=20=EB=B0=94=EA=BE=BC=20=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=20=EC=9E=AC=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-dev-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend-dev-cd.yml b/.github/workflows/backend-dev-cd.yml index c7ff01a53..09eb49583 100644 --- a/.github/workflows/backend-dev-cd.yml +++ b/.github/workflows/backend-dev-cd.yml @@ -1,7 +1,7 @@ name: Backend Dev Server CD on: - pull_request: + push: branches: [ backend ] workflow_dispatch: From 0fdf328fed7ea7b50caf7a95e7a3a0d80d481387 Mon Sep 17 00:00:00 2001 From: GiSeok Kang Date: Thu, 27 Nov 2025 20:15:27 +0900 Subject: [PATCH 03/17] =?UTF-8?q?chore:=20prod=20cd=20=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A6=BD=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-prod-app-cd.yml | 86 ----------------------- .github/workflows/backend-prod-cd.yml | 80 ++++----------------- 2 files changed, 15 insertions(+), 151 deletions(-) delete mode 100644 .github/workflows/backend-prod-app-cd.yml diff --git a/.github/workflows/backend-prod-app-cd.yml b/.github/workflows/backend-prod-app-cd.yml deleted file mode 100644 index 3d728e7bd..000000000 --- a/.github/workflows/backend-prod-app-cd.yml +++ /dev/null @@ -1,86 +0,0 @@ -name: Backend Prod App CD - -on: - workflow_call: - inputs: - run_id: - required: true - type: string - main_runner: - required: true - type: string - sub_runner: - required: true - type: string - -jobs: - deploy-prod-main: - name: main runner에 서버 배포 - runs-on: [ self-hosted, "${{ inputs.main_runner }}" ] - defaults: - run: - working-directory: /home/ssm-user/coursepick - steps: - - name: Docker 로그인 - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: .env 파일 생성 - working-directory: /home/ssm-user/coursepick - run: | - cat > .env <<'EOF' - ${{ secrets.PROD_ENV_FILE }} - EOF - chmod 600 .env - - - name: 새로운 서버 시작 - working-directory: /home/ssm-user/coursepick - run: | - sudo docker compose --env-file .env up -d --pull always backend - - - name: 시작된 서버 헬스체크 - run: | - for i in $(seq 1 10) - do - SERVER_STATUS=$(curl -o /dev/null -w "%{http_code}" http://localhost:80/actuator/health || true) - - if [ "$SERVER_STATUS" -eq 200 ]; then - echo "서버 정상적으로 실행됨 status=$SERVER_STATUS" - break - else - echo "헬스체크에 실패함. 5초 후 다시 시도" - sleep 5 - fi - - if [ $i -eq 10 ]; then - echo "서버가 정상적으로 실행되지 않아 종료함" - exit 1 - fi - done - - update-nginx-to-prod-main: - name: nginx 로드밸런서 설정 파일 main runner 설정으로 변경 - needs: [ deploy-prod-main ] - if: ${{ needs.deploy-prod-main.result == 'success' }} - runs-on: [ self-hosted, prod-lb ] - steps: - - name: upstream 갱신, 리로드 - run: | - sudo ln -sfn /etc/nginx/snippets/upstream.${{ inputs.main_runner }} /etc/nginx/snippets/upstream.active - sudo nginx -t && sudo systemctl reload nginx - - shutdown-prod-sub: - name: sub runner 서버 종료 - needs: [ update-nginx-to-prod-main ] - runs-on: [ self-hosted, "${{ inputs.sub_runner }}" ] - defaults: - run: - working-directory: /home/ssm-user/coursepick - steps: - - name: 기존 서버 내리기 - working-directory: /home/ssm-user/coursepick - run: | - sudo docker compose down - sudo docker image prune -a -f diff --git a/.github/workflows/backend-prod-cd.yml b/.github/workflows/backend-prod-cd.yml index da9adc630..0087ebfeb 100644 --- a/.github/workflows/backend-prod-cd.yml +++ b/.github/workflows/backend-prod-cd.yml @@ -1,8 +1,8 @@ name: Backend Prod Server CD on: - push: - branches: [ main ] + pull_request: + branches: [ backend ] paths: - 'backend/**' - '.github/workflows/backend-prod-cd.yml' @@ -52,68 +52,18 @@ jobs: --push \ . - # 1) 유휴 서버 탐지 - detect-idle: - name: 쉬고있는 EC2 서버 탐지 + deploy: + name: Prod 서버 배포 needs: build - runs-on: [ self-hosted, prod-lb ] - outputs: - idle-server: ${{ steps.find.outputs.idle }} - steps: - - name: 탐침 스크립트 실행 - id: find - run: | - declare -A servers=( - [prod-app-1]="${{ secrets.PROD_APP_1_HEALTH_URL }}" - [prod-app-2]="${{ secrets.PROD_APP_2_HEALTH_URL }}" - ) - - idle_servers=() - - for name in "${!servers[@]}"; do - url="${servers[$name]}" - code=$(curl -s -o /dev/null -w "%{http_code}" "$url" || echo "") - if [[ "$code" -eq 200 ]]; then - echo "$name 응답 성공" - else - echo "$name 응답 실패" - idle_servers+=("$name") - fi - done - - if [[ ${#idle_servers[@]} -eq 0 ]]; then - echo "Both servers are healthy – cannot find idle server" - elif [[ ${#idle_servers[@]} -eq 1 ]]; then - idle="${idle_servers[0]}" - echo "One server is idle, idle=$idle" - echo "idle=$idle" >> $GITHUB_OUTPUT - else - idle="prod-app-1" - echo "None servers are idle – as default, deploy to server1, idle=$idle" - echo "idle=$idle" >> $GITHUB_OUTPUT - fi - - echo "idle=$idle" >> $GITHUB_OUTPUT - - # 2) 유휴 서버에 배포 (server1 / server2 중 하나만 실행) - deploy-prod-app-1: - name: prod-app-1 서버에 배포 - needs: detect-idle - if: needs.detect-idle.outputs.idle-server == 'prod-app-1' - uses: ./.github/workflows/backend-prod-app-cd.yml - with: - run_id: ${{ github.run_id }} - main_runner: prod-app-1 - sub_runner: prod-app-2 - secrets: inherit + runs-on: ubuntu-latest - deploy-prod-app-2: - name: prod-app-2 서버에 배포 - needs: detect-idle - if: needs.detect-idle.outputs.idle-server == 'prod-app-2' - uses: ./.github/workflows/backend-prod-app-cd.yml - with: - run_id: ${{ github.run_id }} - main_runner: prod-app-2 - sub_runner: prod-app-1 - secrets: inherit + steps: + - name: SSH로 배포 스크립트 실행 + uses: appleboy/ssh-action@v1.0.0 + with: + host: ${{ secrets.PROD_SERVER_HOST }} + username: ubuntu + key: ${{ secrets.SSH_PRIVATE_KEY }} + script: | + cd ~ + ./deploy.sh From 036d963557f5013ee8fd334a4ad5c83fff545868 Mon Sep 17 00:00:00 2001 From: GiSeok Kang Date: Thu, 27 Nov 2025 20:17:53 +0900 Subject: [PATCH 04/17] =?UTF-8?q?fix:=20cd=20=EC=8A=A4=ED=81=AC=EB=A6=BD?= =?UTF-8?q?=ED=8A=B8=20=ED=94=BD=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-prod-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend-prod-cd.yml b/.github/workflows/backend-prod-cd.yml index 0087ebfeb..86a6b25ac 100644 --- a/.github/workflows/backend-prod-cd.yml +++ b/.github/workflows/backend-prod-cd.yml @@ -65,5 +65,5 @@ jobs: username: ubuntu key: ${{ secrets.SSH_PRIVATE_KEY }} script: | - cd ~ + cd /home/ubuntu/coursepick ./deploy.sh From 0ad378d99d5e66eb51b9a45e458bb9a449e3a485 Mon Sep 17 00:00:00 2001 From: GiSeok Kang Date: Sat, 29 Nov 2025 20:59:23 +0900 Subject: [PATCH 05/17] =?UTF-8?q?refactor:=20=EB=B0=B0=ED=8F=AC=20?= =?UTF-8?q?=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=20girhub=20actions=20scrip?= =?UTF-8?q?t=EB=A1=9C=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-dev-cd.yml | 31 +++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/.github/workflows/backend-dev-cd.yml b/.github/workflows/backend-dev-cd.yml index 09eb49583..d0edfd392 100644 --- a/.github/workflows/backend-dev-cd.yml +++ b/.github/workflows/backend-dev-cd.yml @@ -24,6 +24,9 @@ jobs: distribution: 'corretto' cache: 'gradle' + - name: Gradle 실행 권한 부여 + run: chmod +x gradlew + - name: 프로젝트 gradlew 빌드 run: ./gradlew build @@ -63,4 +66,30 @@ jobs: key: ${{ secrets.SSH_PRIVATE_KEY }} script: | cd /home/ubuntu/coursepick - ./deploy.sh + + echo "🚀 개발 서버 배포 시작..." + + echo "📦 최신 이미지 Pull..." + sudo docker pull ${{ secrets.DOCKER_USERNAME }}/coursepick-backend:dev + + echo "▶️ 새 서버 시작..." + sudo docker compose up -d backend + + echo "🧹 사용하지 않는 이미지 정리..." + sudo docker image prune -a -f + + echo "⛑️ 헬스 체크..." + for i in $(seq 1 10); do + SERVER_STATUS=$(curl -o /dev/null -w "%{http_code}" http://localhost:80/actuator/health || echo "000") + if [ "$SERVER_STATUS" -eq 200 ]; then + echo "✅ 배포 성공! 서버 동작 중..." + exit 0 + else + echo "Attempt $i/10: 헬스 체크 실패 (status=$SERVER_STATUS). 5초 후 재시도..." + sleep 5 + fi + done + + echo "❌ 배포 실패! 서버가 동작하지 않습니다." + sudo docker logs coursepick-backend --tail 50 + exit 1 From 6ca48fbb8030c0336ce8b07b86170b311cc23ce6 Mon Sep 17 00:00:00 2001 From: GiSeok Kang Date: Sat, 29 Nov 2025 21:06:21 +0900 Subject: [PATCH 06/17] =?UTF-8?q?refactor:=20=EB=B0=B0=ED=8F=AC=20?= =?UTF-8?q?=EA=B3=BC=EC=A0=95=EC=97=90=EC=84=9C=20CI=20=EA=B3=BC=EC=A0=95?= =?UTF-8?q?=20ci=20=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=ED=96=89=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-dev-cd.yml | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/.github/workflows/backend-dev-cd.yml b/.github/workflows/backend-dev-cd.yml index d0edfd392..d8374d12a 100644 --- a/.github/workflows/backend-dev-cd.yml +++ b/.github/workflows/backend-dev-cd.yml @@ -6,8 +6,14 @@ on: workflow_dispatch: jobs: + ci: + name: CI 실행 + uses: ./.github/workflows/backend-ci.yml + secrets: inherit + build: name: 도커 이미지 빌드 & 푸시 + needs: ci runs-on: ubuntu-latest defaults: run: @@ -17,27 +23,6 @@ jobs: - name: 레포지토리 불러오기 uses: actions/checkout@v4 - - name: JDK 21 설정 - uses: actions/setup-java@v4 - with: - java-version: '21' - distribution: 'corretto' - cache: 'gradle' - - - name: Gradle 실행 권한 부여 - run: chmod +x gradlew - - - name: 프로젝트 gradlew 빌드 - run: ./gradlew build - - - name: 테스트 결과 보고서 작성 - uses: dorny/test-reporter@v1 - if: success() || failure() - with: - name: 테스트 결과 - path: backend/build/test-results/test/*.xml - reporter: java-junit - - name: Docker 로그인 uses: docker/login-action@v3 with: From e3742794e76da168f3c912f407dc2bc9f889db0a Mon Sep 17 00:00:00 2001 From: GiSeok Kang Date: Sat, 29 Nov 2025 21:10:20 +0900 Subject: [PATCH 07/17] =?UTF-8?q?refactor:=20env=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EA=B3=BC=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-dev-cd.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/backend-dev-cd.yml b/.github/workflows/backend-dev-cd.yml index d8374d12a..eec9ce418 100644 --- a/.github/workflows/backend-dev-cd.yml +++ b/.github/workflows/backend-dev-cd.yml @@ -57,8 +57,14 @@ jobs: echo "📦 최신 이미지 Pull..." sudo docker pull ${{ secrets.DOCKER_USERNAME }}/coursepick-backend:dev + echo "🌳 .env 파일 생성..." + cat > .env <<'EOF' + ${{ secrets.DEV_ENV_FILE }} + EOF + chmod 600 .env + echo "▶️ 새 서버 시작..." - sudo docker compose up -d backend + sudo docker compose --env-file .env up -d --pull always backend echo "🧹 사용하지 않는 이미지 정리..." sudo docker image prune -a -f From efdd45a4be8790bb8801d753a7b962ff20da5a7a Mon Sep 17 00:00:00 2001 From: GiSeok Kang Date: Sat, 29 Nov 2025 21:10:52 +0900 Subject: [PATCH 08/17] =?UTF-8?q?chore:=20prod=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=EC=A1=B0=EA=B1=B4=20?= =?UTF-8?q?=EC=9B=90=EB=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-prod-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend-prod-cd.yml b/.github/workflows/backend-prod-cd.yml index 86a6b25ac..f1f6bc8eb 100644 --- a/.github/workflows/backend-prod-cd.yml +++ b/.github/workflows/backend-prod-cd.yml @@ -1,7 +1,7 @@ name: Backend Prod Server CD on: - pull_request: + push: branches: [ backend ] paths: - 'backend/**' From ac59341f37f6f35beb883908d784cfc6a39b96be Mon Sep 17 00:00:00 2001 From: GiSeok Kang Date: Sat, 29 Nov 2025 21:11:45 +0900 Subject: [PATCH 09/17] =?UTF-8?q?chore:=20=EA=B0=9C=EB=B0=9C=20=EC=84=9C?= =?UTF-8?q?=EB=B2=84=20=EB=B0=B0=ED=8F=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=EC=A1=B0=EA=B1=B4=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-dev-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend-dev-cd.yml b/.github/workflows/backend-dev-cd.yml index eec9ce418..102133503 100644 --- a/.github/workflows/backend-dev-cd.yml +++ b/.github/workflows/backend-dev-cd.yml @@ -1,7 +1,7 @@ name: Backend Dev Server CD on: - push: + pull_request: branches: [ backend ] workflow_dispatch: From 50f5439f3848ffee09ab4b6b3912fc81550780d3 Mon Sep 17 00:00:00 2001 From: GiSeok Kang Date: Sat, 29 Nov 2025 21:15:01 +0900 Subject: [PATCH 10/17] =?UTF-8?q?refactor:=20ci/cd=20=EA=B3=BC=EC=A0=95=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-ci.yml | 2 ++ .github/workflows/backend-dev-cd.yml | 6 ------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/backend-ci.yml b/.github/workflows/backend-ci.yml index 39598c3fb..869359c8c 100644 --- a/.github/workflows/backend-ci.yml +++ b/.github/workflows/backend-ci.yml @@ -1,6 +1,8 @@ name: Backend CI on: + push: + branches: [ backend ] pull_request: branches: [ backend ] workflow_dispatch: diff --git a/.github/workflows/backend-dev-cd.yml b/.github/workflows/backend-dev-cd.yml index 102133503..86f8fb1ab 100644 --- a/.github/workflows/backend-dev-cd.yml +++ b/.github/workflows/backend-dev-cd.yml @@ -6,14 +6,8 @@ on: workflow_dispatch: jobs: - ci: - name: CI 실행 - uses: ./.github/workflows/backend-ci.yml - secrets: inherit - build: name: 도커 이미지 빌드 & 푸시 - needs: ci runs-on: ubuntu-latest defaults: run: From 2a50df91a54cf32e28869443017ca4f48536fcaa Mon Sep 17 00:00:00 2001 From: GiSeok Kang Date: Sat, 29 Nov 2025 21:18:20 +0900 Subject: [PATCH 11/17] =?UTF-8?q?fix:=20build=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-ci.yml | 3 +-- .github/workflows/backend-dev-cd.yml | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.github/workflows/backend-ci.yml b/.github/workflows/backend-ci.yml index 869359c8c..5898fdcb0 100644 --- a/.github/workflows/backend-ci.yml +++ b/.github/workflows/backend-ci.yml @@ -1,8 +1,7 @@ name: Backend CI on: - push: - branches: [ backend ] + workflow_call: pull_request: branches: [ backend ] workflow_dispatch: diff --git a/.github/workflows/backend-dev-cd.yml b/.github/workflows/backend-dev-cd.yml index 86f8fb1ab..4d3e2faa9 100644 --- a/.github/workflows/backend-dev-cd.yml +++ b/.github/workflows/backend-dev-cd.yml @@ -6,8 +6,14 @@ on: workflow_dispatch: jobs: + ci: + name: CI 실행 + uses: ./.github/workflows/backend-ci.yml + secrets: inherit + build: name: 도커 이미지 빌드 & 푸시 + needs: ci runs-on: ubuntu-latest defaults: run: @@ -17,6 +23,19 @@ jobs: - name: 레포지토리 불러오기 uses: actions/checkout@v4 + - name: JDK 21 설정 + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'corretto' + cache: 'gradle' + + - name: Gradle 실행 권한 부여 + run: chmod +x gradlew + + - name: Gradle 빌드 (jar 생성) + run: ./gradlew clean build -x test + - name: Docker 로그인 uses: docker/login-action@v3 with: From cf4eb457d4cef09be0d2524fb2bfc6b6d2e6573a Mon Sep 17 00:00:00 2001 From: GiSeok Kang Date: Sat, 29 Nov 2025 21:22:42 +0900 Subject: [PATCH 12/17] =?UTF-8?q?refactor:=20ci=20=EA=B3=BC=EC=A0=95?= =?UTF-8?q?=EA=B3=BC=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=ED=86=B5=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-dev-cd.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/backend-dev-cd.yml b/.github/workflows/backend-dev-cd.yml index 4d3e2faa9..6454228c8 100644 --- a/.github/workflows/backend-dev-cd.yml +++ b/.github/workflows/backend-dev-cd.yml @@ -30,10 +30,10 @@ jobs: distribution: 'corretto' cache: 'gradle' - - name: Gradle 실행 권한 부여 + - name: gradlew 실행 권한 부여 run: chmod +x gradlew - - name: Gradle 빌드 (jar 생성) + - name: 프로젝트 gradlew 빌드 run: ./gradlew clean build -x test - name: Docker 로그인 From 717c95fa8962acf5793cf7750194e8e80c7ff8d0 Mon Sep 17 00:00:00 2001 From: GiSeok Kang Date: Sat, 29 Nov 2025 21:27:14 +0900 Subject: [PATCH 13/17] =?UTF-8?q?refactor:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EB=A5=BC=20=EC=9C=84=ED=95=B4=20=EC=84=A4=EC=A0=95=ED=95=9C=20?= =?UTF-8?q?=EC=A1=B0=EA=B1=B4=20=EB=B3=B5=EC=9B=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-dev-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend-dev-cd.yml b/.github/workflows/backend-dev-cd.yml index 6454228c8..d5f26a8b7 100644 --- a/.github/workflows/backend-dev-cd.yml +++ b/.github/workflows/backend-dev-cd.yml @@ -1,7 +1,7 @@ name: Backend Dev Server CD on: - pull_request: + push: branches: [ backend ] workflow_dispatch: From 1b46a833689b3403f76b53f629762a3c949b566a Mon Sep 17 00:00:00 2001 From: GiSeok Kang Date: Sat, 29 Nov 2025 21:36:26 +0900 Subject: [PATCH 14/17] =?UTF-8?q?refactor:=20=EC=9A=B4=EC=98=81=EC=84=9C?= =?UTF-8?q?=EB=B2=84=20=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-prod-cd.yml | 59 +++++++++++++++++++++------ 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/.github/workflows/backend-prod-cd.yml b/.github/workflows/backend-prod-cd.yml index f1f6bc8eb..ed3b82dcc 100644 --- a/.github/workflows/backend-prod-cd.yml +++ b/.github/workflows/backend-prod-cd.yml @@ -1,7 +1,7 @@ name: Backend Prod Server CD on: - push: + pull_request: branches: [ backend ] paths: - 'backend/**' @@ -9,8 +9,14 @@ on: workflow_dispatch: jobs: + ci: + name: CI 실행 + uses: ./.github/workflows/backend-ci.yml + secrets: inherit + build: - name: 프로젝트 빌드 + name: 도커 이미지 빌드 & 푸시 + needs: ci runs-on: ubuntu-latest defaults: run: @@ -27,16 +33,11 @@ jobs: distribution: 'corretto' cache: 'gradle' - - name: 프로젝트 gradlew 빌드 - run: ./gradlew build + - name: gradlew 실행 권한 부여 + run: chmod +x gradlew - - name: 테스트 결과 보고서 작성 - uses: dorny/test-reporter@v1 - if: success() || failure() - with: - name: 테스트 결과 - path: backend/build/test-results/test/*.xml - reporter: java-junit + - name: 프로젝트 gradlew 빌드 + run: ./gradlew clean build -x test - name: Docker 로그인 uses: docker/login-action@v3 @@ -53,7 +54,7 @@ jobs: . deploy: - name: Prod 서버 배포 + name: 운영서버 배포 needs: build runs-on: ubuntu-latest @@ -66,4 +67,36 @@ jobs: key: ${{ secrets.SSH_PRIVATE_KEY }} script: | cd /home/ubuntu/coursepick - ./deploy.sh + + echo "🚀 운영 서버 배포 시작..." + + echo "📦 최신 이미지 Pull..." + sudo docker pull ${{ secrets.DOCKER_USERNAME }}/coursepick-backend:prod + + echo "🌳 .env 파일 생성..." + cat > .env <<'EOF' + ${{ secrets.PROD_ENV_FILE }} + EOF + chmod 600 .env + + echo "▶️ 새 서버 시작..." + sudo docker compose --env-file .env up -d --pull always backend + + echo "🧹 사용하지 않는 이미지 정리..." + sudo docker image prune -a -f + + echo "⛑️ 헬스 체크..." + for i in $(seq 1 10); do + SERVER_STATUS=$(curl -o /dev/null -w "%{http_code}" http://localhost:80/actuator/health || echo "000") + if [ "$SERVER_STATUS" -eq 200 ]; then + echo "✅ 배포 성공! 서버 동작 중..." + exit 0 + else + echo "Attempt $i/10: 헬스 체크 실패 (status=$SERVER_STATUS). 5초 후 재시도..." + sleep 5 + fi + done + + echo "❌ 배포 실패! 서버가 동작하지 않습니다." + sudo docker logs coursepick-backend --tail 50 + exit 1 From 57340934ce55385f4a2e1470f7a14d9e425e365f Mon Sep 17 00:00:00 2001 From: GiSeok Kang Date: Sat, 29 Nov 2025 21:47:08 +0900 Subject: [PATCH 15/17] =?UTF-8?q?refactor:=20=EC=9A=B4=EC=98=81=EC=84=9C?= =?UTF-8?q?=EB=B2=84=20=EB=B8=8C=EB=9E=9C=EC=B9=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-prod-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backend-prod-cd.yml b/.github/workflows/backend-prod-cd.yml index ed3b82dcc..be738b553 100644 --- a/.github/workflows/backend-prod-cd.yml +++ b/.github/workflows/backend-prod-cd.yml @@ -2,7 +2,7 @@ name: Backend Prod Server CD on: pull_request: - branches: [ backend ] + branches: [ main ] paths: - 'backend/**' - '.github/workflows/backend-prod-cd.yml' From 1f8b3338516cf2f8c69785d3a5bb266e9e55066a Mon Sep 17 00:00:00 2001 From: GiSeok Kang Date: Sat, 29 Nov 2025 21:48:41 +0900 Subject: [PATCH 16/17] =?UTF-8?q?test:=20=EC=9A=B4=EC=98=81=20=EC=84=9C?= =?UTF-8?q?=EB=B2=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-prod-cd.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/backend-prod-cd.yml b/.github/workflows/backend-prod-cd.yml index be738b553..0fc0b69dc 100644 --- a/.github/workflows/backend-prod-cd.yml +++ b/.github/workflows/backend-prod-cd.yml @@ -100,3 +100,4 @@ jobs: echo "❌ 배포 실패! 서버가 동작하지 않습니다." sudo docker logs coursepick-backend --tail 50 exit 1 + From ca1736df159614fbc2f0ff168b7744cf97cfae53 Mon Sep 17 00:00:00 2001 From: GiSeok Kang Date: Sat, 29 Nov 2025 21:59:30 +0900 Subject: [PATCH 17/17] =?UTF-8?q?refactor:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=EC=A1=B0=EA=B1=B4=20=EB=B3=B5?= =?UTF-8?q?=EC=9B=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-prod-cd.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/backend-prod-cd.yml b/.github/workflows/backend-prod-cd.yml index 0fc0b69dc..9fa51526d 100644 --- a/.github/workflows/backend-prod-cd.yml +++ b/.github/workflows/backend-prod-cd.yml @@ -1,7 +1,7 @@ name: Backend Prod Server CD on: - pull_request: + push: branches: [ main ] paths: - 'backend/**' @@ -100,4 +100,3 @@ jobs: echo "❌ 배포 실패! 서버가 동작하지 않습니다." sudo docker logs coursepick-backend --tail 50 exit 1 -