Skip to content

인프라 이사를 위한 CD 스크립트 수정#571

Merged
kkiseug merged 17 commits intobackendfrom
feat/570-server-move
Dec 3, 2025
Merged

인프라 이사를 위한 CD 스크립트 수정#571
kkiseug merged 17 commits intobackendfrom
feat/570-server-move

Conversation

@kkiseug
Copy link
Contributor

@kkiseug kkiseug commented Nov 27, 2025

🛠️ 주요 변경 사항

  • 운영 및 개발 서버 이사를 위해 CD 스크립트 작성했습니다.

🔗 관련 이슈

Summary by CodeRabbit

  • Chores
    • CI/CD 통합 및 간소화: 여러 배포 워크플로우를 정리하고 배포 흐름을 중앙화된 원격 SSH 배포 스크립트로 전환했습니다.
    • 빌드·배포 흐름 재구성: 별도 CI 단계 추가, 빌드 실행 방식 변경(테스트 생략), 로컬 테스트/헬스체크 제거 및 원격에서 이미지 풀·시작·정리·헬스체크 수행하도록 변경했습니다.
    • 트리거·런너 조정: 워크플로우 트리거 확장 및 실행 환경 정비로 배포 프로세스를 단순화했습니다.

✏️ Tip: You can customize this high-level summary in your review settings.

@kkiseug kkiseug requested a review from dompoo November 27, 2025 08:08
@kkiseug kkiseug self-assigned this Nov 27, 2025
@kkiseug kkiseug added refactor 기존 기능 수정 setup 프로젝트 세팅 backend labels Nov 27, 2025
@coderabbitai
Copy link

coderabbitai bot commented Nov 27, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

백엔드 CI/CD 워크플로우들을 로컬 실행에서 SSH 원격 실행으로 전환하고, 프로덕션 앱 CD 워크플로우를 삭제하며 CI 트리거와 job 구조를 단순화했습니다. (50자 이내)

Changes

Cohort / File(s) 변경 요약
개발 CD 워크플로우 변경
\.github/workflows/backend-dev-cd.yml
ci job 추가, Gradle 실행파일 권한 부여 및 테스트 제외 빌드로 빌드 단계 간소화. 로컬 env/컨테이너 시작/헬스체크 제거 후 appleboy/ssh-action 기반 원격 배포 스크립트 실행으로 대체. runs-on 및 working-directory 조정.
프로덕션 앱 CD 파일 삭제
\.github/workflows/backend-prod-app-cd.yml
파일 전체 삭제 — 기존의 로컬 이미지 빌드·로그인·.env 생성·docker compose up --pull·헬스체크·Nginx 업데이트·서버 종료 로직 제거.
프로덕션 CD 단순화
\.github/workflows/backend-prod-cd.yml
ci job 추가, 빌드 job에 needs: ci 추가 및 gradlew 권한/clean build(no-tests)로 변경. 다중 idle 감지·복수 배포 잡 제거하고 단일 deploy job으로 축소, SSH로 원격 배포 스크립트 실행(이미지 풀·원격 .env 생성·docker compose up·이미지 정리·헬스체크 포함).
CI 트리거 추가
\.github/workflows/backend-ci\.yml
기존 pull_request/workflow_dispatch 외에 workflow_call 추가(호출 가능) 및 backend 브랜치 연동(동작상 큰 변경 없음).

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant GHA as GitHub Actions
    participant SSHAction as appleboy/ssh-action
    participant Remote as Remote Server

    rect rgba(220,235,255,0.5)
    Note over GHA,SSHAction: SSH 기반 원격 배포 흐름
    GHA->>SSHAction: 워크플로우 실행 및 시크릿 전달
    SSHAction->>Remote: SSH 접속 및 원격 배포 스크립트 실행
    Remote->>Remote: 이미지 풀, 원격 .env 생성/갱신, docker compose up, 이미지 정리, 헬스체크 반복
    Remote-->>SSHAction: 로그와 종료 코드 반환
    SSHAction-->>GHA: 실행 결과 보고 (성공/실패)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • 검토 시 집중할 항목:
    • backend-dev-cd.yml/backend-prod-cd.ymlci job 의도와 needs 관계 및 working-directory: backend 영향
    • SSH 액션에 전달되는 시크릿 이름(HOST/USER/SSH_KEY 등)과 전달 방식의 정확성 및 노출 위험
    • 삭제된 backend-prod-app-cd.yml에 있던 배포 로직이 원격 deploy 스크립트로 완전 이전되었는지(스크립트 경로·권한)
    • 원격 스크립트의 헬스체크 재시도/타임아웃/종료 코드 정책 및 로그 출력 처리

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive 연결된 이슈 #570의 구체적인 요구사항이 제공되지 않아, CD 스크립트 변경사항이 이슈 요구사항을 충족하는지 검증할 수 없습니다. 이슈 #570의 상세한 요구사항을 확인하여 변경사항이 모든 목표를 충족하는지 검증해 주세요.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목은 인프라 이사를 위한 CD 스크립트 수정으로, 변경사항의 주요 목적을 명확하게 요약하고 있습니다.
Description check ✅ Passed PR 설명은 주요 변경 사항과 관련 이슈를 포함하고 있으나, 템플릿의 필수 섹션 중 일부(테스트 완료 사항, 체크리스트, 스크린샷, 리뷰 요청사항)가 누락되어 있습니다.
Out of Scope Changes check ✅ Passed 모든 변경사항은 GitHub Actions 워크플로우 파일 수정으로 인프라 이사 관련 CD 스크립트 변경에 범위 내에 있습니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ae97b1a and ca1736d.

📒 Files selected for processing (4)
  • .github/workflows/backend-ci.yml (1 hunks)
  • .github/workflows/backend-dev-cd.yml (3 hunks)
  • .github/workflows/backend-prod-app-cd.yml (0 hunks)
  • .github/workflows/backend-prod-cd.yml (3 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8541b43 and bd4a695.

📒 Files selected for processing (1)
  • .github/workflows/backend-dev-cd.yml (1 hunks)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
.github/workflows/backend-prod-cd.yml (2)

60-69: 배포 성공 검증 및 에러 처리 부족

원격 배포 스크립트 실행 후 성공/실패 여부를 검증하거나 로깅하는 단계가 없습니다. 다음을 추가하는 것을 고려하세요:

  1. 배포 결과 확인: deploy.sh 스크립트가 실패할 경우 워크플로우에서 감지할 수 있는지 확인
  2. 타임아웃 설정: SSH 연결이 무한 대기하지 않도록 타임아웃 추가 (현재: 미지정)
  3. 스크립트 검증: 배포 스크립트가 이미 적절한 에러 처리를 포함하고 있는지 확인

예시 개선:

- name: SSH로 배포 스크립트 실행
  uses: appleboy/ssh-action@v1.0.0
  with:
    host: ${{ secrets.PROD_SERVER_HOST }}
    username: ubuntu
    key: ${{ secrets.SSH_PRIVATE_KEY }}
    script_stop: true
    command_timeout: 10m
    script: |
      cd /home/ubuntu/coursepick
      ./deploy.sh || exit 1

65-65: SSH 사용자명을 환경 변수로 관리

SSH 사용자명 ubuntu가 하드코딩되어 있습니다. 이를 secret으로 관리하면 서버 구성 변경 시 유연성이 높아집니다:

username: ${{ secrets.SSH_USERNAME }}

필요에 따라 SSH_USERNAME secret을 생성하세요.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd4a695 and a4c291e.

📒 Files selected for processing (2)
  • .github/workflows/backend-prod-app-cd.yml (0 hunks)
  • .github/workflows/backend-prod-cd.yml (2 hunks)
💤 Files with no reviewable changes (1)
  • .github/workflows/backend-prod-app-cd.yml
🔇 Additional comments (2)
.github/workflows/backend-prod-cd.yml (2)

47-53: Docker 이미지 빌드와 배포 스크립트의 중복 여부 확인

build 잡에서 Docker 이미지를 빌드하고 레지스트리에 푸시하는 동안, deploy 잡의 ./deploy.sh 스크립트도 유사한 작업을 수행할 수 있습니다. 배포 스크립트의 내용을 확인하여 다음을 검증하세요:

  1. 배포 스크립트가 이미 Docker 이미지를 레지스트리에서 가져오는지 여부
  2. 불필요한 중복 빌드가 있는지 여부
  3. 빌드 단계의 필요성과 효율성

프로덕션 워크플로우의 효율성을 위해 확인해주세요.


4-5: I'll help you verify the review comment about the workflow trigger change. Let me examine the workflow file and understand its context.
<function_calls>


#!/bin/bash

First, read the full workflow file to understand context

cat -n .github/workflows/backend-prod-cd.yml


</function_calls>

Now let me check if there are other similar workflow files to compare the deployment strategy:
<function_calls>


#!/bin/bash

List all workflow files to understand the deployment strategy

fd -e yml -e yaml .github/workflows/ | sort


</function_calls>

Let me also check the git history of this file to understand what changed:
<function_calls>


#!/bin/bash

Check recent changes to this workflow file

git log --oneline -10 .github/workflows/backend-prod-cd.yml 2>/dev/null || echo "Git history not available"


</function_calls>

Let me get the diff to see what actually changed in this PR:
<function_calls>


#!/bin/bash

Show the diff for this file in the current PR

git diff HEAD^ .github/workflows/backend-prod-cd.yml 2>/dev/null || git diff .github/workflows/backend-prod-cd.yml 2>/dev/null || echo "Git diff not available"


</function_calls>

Let me check the repository structure to understand the branch strategy:
<function_calls>


#!/bin/bash

Check if there's documentation about deployment strategy

cat README.md 2>/dev/null | head -100
echo "---"

Check for any deployment or CI docs

fd -e md . .github/ | head -20


</function_calls>

Copy link
Contributor

@dompoo dompoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

배포 스크립트를 수정하고 싶으면 결국 ec2 내부로 들어가야 하는게 단점 같아요.

github action 수준에서 그냥 모든 작업을 수행하게 해주는 것도 좋을 것 같고,
아니면 github의 배포 스크립트를 ssh로 복붙한 후에, 실행시키면 동적으로 스크립트 수정도 가능할 것 같은데 어떠신가요?

@kkiseug kkiseug changed the title 개발 서버 이사를 위한 CD 스크립트 수정 인프라 이사를 위한 CD 스크립트 수정 Nov 29, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
.github/workflows/backend-dev-cd.yml (1)

46-51: ⚠️ SSH 배포 에러 처리 누락: script_stop: true 필수 추가

현재 SSH 액션 설정에는 에러 처리 플래그가 없어서, 배포 스크립트 실패 시에도 워크플로우 스텝이 성공으로 표시될 수 있습니다. script_stop: true를 추가하여 스크립트 오류 시 즉시 중단하도록 설정해야 합니다.

- name: SSH로 배포 스크립트 실행
  uses: appleboy/ssh-action@v1.0.0
  with:
    host: ${{ secrets.DEV_SERVER_HOST }}
    username: ubuntu
    key: ${{ secrets.SSH_PRIVATE_KEY }}
+   script_stop: true
    script: |

또한 스크립트 내부에서도 에러 발생 시 즉시 실패하도록 set -e 또는 set -o pipefail을 추가 권장:

script: |
  set -e  # 또는 set -o pipefail
  cd /home/ubuntu/coursepick
  ...
🧹 Nitpick comments (1)
.github/workflows/backend-prod-cd.yml (1)

55-69: 프로덕션 배포 후 헬스 체크 추가 권장

개발 서버 배포에는 /actuator/health 엔드포인트를 통한 헬스 체크 로직이 있으나, 프로덕션 배포에는 배포 후 서버 상태를 검증하는 단계가 없습니다. 배포 성공을 확인하기 위해 다음과 같이 별도 스텝을 추가하거나, 원격 서버의 deploy.sh에 포함시키기를 권장합니다:

- name: 배포 후 헬스 체크
  run: |
    for i in $(seq 1 10); do
      HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://${{ secrets.PROD_SERVER_HOST }}/actuator/health || echo "000")
      if [ "$HTTP_CODE" -eq 200 ]; then
        echo "✅ 프로덕션 배포 성공"
        exit 0
      fi
      echo "시도 $i/10: 헬스 체크 실패 (HTTP $HTTP_CODE). 5초 후 재시도..."
      sleep 5
    done
    echo "❌ 배포 실패: 서버 응답 없음"
    exit 1
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a4c291e and d89024f.

📒 Files selected for processing (2)
  • .github/workflows/backend-dev-cd.yml (2 hunks)
  • .github/workflows/backend-prod-cd.yml (2 hunks)
🧰 Additional context used
🪛 actionlint (1.7.9)
.github/workflows/backend-dev-cd.yml

11-11: error while parsing reusable workflow "./.github/workflows/backend-ci.yml": "workflow_call" event trigger is not found in "on:" at line:4, column:3

(workflow-call)

🔇 Additional comments (1)
.github/workflows/backend-prod-cd.yml (1)

55-69: I'll help you verify the review comment about the production deployment workflow. Let me start by investigating the key concerns.
<function_calls>

appleboy/ssh-action v1.0.0 script_stop parameter documentation

</function_calls>

I also need to check the repository for the deploy.sh script and understand the workflow better:
<function_calls>

Check if deploy.sh exists and examine the workflow file

fd -type f -name "deploy.sh" | head -20


</function_calls>

<function_calls>

Read the complete workflow file to understand context

cat -n .github/workflows/backend-prod-cd.yml 2>/dev/null || echo "File not found"


</function_calls>

<function_calls>

appleboy ssh-action github action error handling script failure

</function_calls>

Please wait while I gather information to verify the concerns raised in this review comment.

@kkiseug kkiseug changed the base branch from backend to main November 29, 2025 12:47
@kkiseug kkiseug changed the base branch from main to backend November 29, 2025 12:59
@kkiseug
Copy link
Contributor Author

kkiseug commented Nov 29, 2025

@dompoo 맞는 말입니다~ 수정했어요! 기존 스크립트 로직과 동일하게 구성했습니다.

@kkiseug kkiseug requested a review from dompoo November 29, 2025 13:02
Copy link
Contributor

@dompoo dompoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다~~!!

@kkiseug kkiseug requested a review from jhpark1227 December 2, 2025 02:57
Copy link
Member

@jhpark1227 jhpark1227 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@kkiseug kkiseug force-pushed the feat/570-server-move branch from d80f31d to ca1736d Compare December 3, 2025 08:38
@kkiseug kkiseug merged commit 93876aa into backend Dec 3, 2025
2 of 3 checks passed
@kkiseug kkiseug deleted the feat/570-server-move branch December 3, 2025 08:40
dompoo pushed a commit that referenced this pull request Dec 16, 2025
* chore: dev 서버 스크립트 변경

* chore: 테스트를 위해 바꾼 조건 재변경

* chore: prod cd 스크립트 수정

* fix: cd 스크립트 픽스

* refactor: 배포 스크립트 girhub actions script로 통일

* refactor: 배포 과정에서 CI 과정 ci 스크립트로 수행하도록 변경

* refactor: env 파일 생성 과정 추가

* chore: prod 테스트를 위한 조건 원복

* chore: 개발 서버 배포 테스트를 위한 조건 변경

* refactor: ci/cd 과정 분리

* fix: build 문제 해결

* refactor: ci 과정과 네이밍 통합

* refactor: 테스트를 위해 설정한 조건 복원

* refactor: 운영서버 스크립트 수정

* refactor: 운영서버 브랜치 수정

* test: 운영 서버 테스트

* refactor: 테스트를 위한 조건 복원
dompoo pushed a commit that referenced this pull request Dec 16, 2025
* chore: dev 서버 스크립트 변경

* chore: 테스트를 위해 바꾼 조건 재변경

* chore: prod cd 스크립트 수정

* fix: cd 스크립트 픽스

* refactor: 배포 스크립트 girhub actions script로 통일

* refactor: 배포 과정에서 CI 과정 ci 스크립트로 수행하도록 변경

* refactor: env 파일 생성 과정 추가

* chore: prod 테스트를 위한 조건 원복

* chore: 개발 서버 배포 테스트를 위한 조건 변경

* refactor: ci/cd 과정 분리

* fix: build 문제 해결

* refactor: ci 과정과 네이밍 통합

* refactor: 테스트를 위해 설정한 조건 복원

* refactor: 운영서버 스크립트 수정

* refactor: 운영서버 브랜치 수정

* test: 운영 서버 테스트

* refactor: 테스트를 위한 조건 복원
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend refactor 기존 기능 수정 setup 프로젝트 세팅

Projects

None yet

Development

Successfully merging this pull request may close these issues.

서버 이사

3 participants