-
Notifications
You must be signed in to change notification settings - Fork 2
♻️ refactor: CI/CD 파이프라인 메모리 최적화 #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
""" WalkthroughGitHub Actions 워크플로우가 리팩토링되었습니다. ESLint 검사 작업은 변경된 파일만 빠르게 검사하도록 간소화되었고, 배포 워크플로우는 환경 점검(warmup)과 배포(deploy)로 분리되었으며, 하드코딩된 값이 변수로 대체되고, 일부 작업이 스크립트 실행으로 대체되었습니다. Changes
Sequence Diagram(s)sequenceDiagram
participant GitHub Actions
participant Runner
GitHub Actions->>Runner: warmup job 실행 (환경 점검)
Runner-->>GitHub Actions: warmup 완료
GitHub Actions->>Runner: deploy job 실행 (deploy.sh 실행)
Runner->>Runner: 컨테이너 상태 확인 및 health check
Runner-->>GitHub Actions: 배포 및 상태 보고
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (3)
.github/workflows/ci.yml (1)
18-18: 불필요한 트레일링 스페이스 제거
YAMLlint에서 지적된 공백을 삭제해 주세요.- - name: Lightning fast lint check·· + - name: Lightning fast lint check.github/workflows/deploy.yml (2)
38-40: 하드코딩된 경로 개선 제안
cd /home/ubuntu/coplan절대 경로 대신$GITHUB_WORKSPACE를 사용해 러너마다 유연하게 조정하세요.- cd /home/ubuntu/coplan + cd $GITHUB_WORKSPACE
17-18: 불필요한 트레일링 스페이스 제거
YAMLlint에서 지적된whoami와docker --version라인의 끝 공백을 삭제해 주세요.- whoami - docker --version + whoami + docker --version
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.github/workflows/ci.yml(1 hunks).github/workflows/deploy.yml(1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
.github/workflows/deploy.yml
[error] 17-17: trailing spaces
(trailing-spaces)
[error] 18-18: trailing spaces
(trailing-spaces)
🔇 Additional comments (2)
.github/workflows/ci.yml (2)
12-12: 타임아웃 최소값 검증 필요
2분으로 설정된timeout-minutes: 2가 글로벌 ESLint 검사 단계를 안정적으로 완료할 수 있는지 확인해 주세요.
16-16: Node.js 및 ESLint 글로벌 설치 여부 확인
setup-node단계가 제거되면서, 셀프호스티드 러너에 Node.js와 ESLint CLI가 설치돼 있지 않으면 명령이 실패합니다.
.github/workflows/deploy.yml
Outdated
| if docker ps | grep -q $DOCKER_CONTAINER_NAME; then | ||
| echo "✅ Deployment completed!" | ||
| docker logs --tail 5 $DOCKER_CONTAINER_NAME | ||
| echo "🌐 https://coplan.work" # ✅ HTTPS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
환경 변수 인용 및 기본값 검증
$DOCKER_CONTAINER_NAME이 설정되지 않으면 오류가 발생할 수 있습니다. 변수 인용 및 미설정 시 실패 로직을 추가하세요.
- if docker ps | grep -q $DOCKER_CONTAINER_NAME; then
+ if [ -z "${DOCKER_CONTAINER_NAME:-}" ]; then
+ echo "❌ DOCKER_CONTAINER_NAME이 설정되지 않았습니다."
+ exit 1
+ fi
+ if docker ps | grep -q "$DOCKER_CONTAINER_NAME"; then📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if docker ps | grep -q $DOCKER_CONTAINER_NAME; then | |
| echo "✅ Deployment completed!" | |
| docker logs --tail 5 $DOCKER_CONTAINER_NAME | |
| echo "🌐 https://coplan.work" # ✅ HTTPS | |
| if [ -z "${DOCKER_CONTAINER_NAME:-}" ]; then | |
| echo "❌ DOCKER_CONTAINER_NAME이 설정되지 않았습니다." | |
| exit 1 | |
| fi | |
| if docker ps | grep -q "$DOCKER_CONTAINER_NAME"; then | |
| echo "✅ Deployment completed!" | |
| docker logs --tail 5 $DOCKER_CONTAINER_NAME | |
| echo "🌐 https://coplan.work" # ✅ HTTPS |
🤖 Prompt for AI Agents
In .github/workflows/deploy.yml around lines 48 to 51, the script uses the
environment variable $DOCKER_CONTAINER_NAME without quotes or validation, which
can cause errors if the variable is unset or contains spaces. Fix this by
quoting the variable references like "$DOCKER_CONTAINER_NAME" and add a check
before this block to verify that $DOCKER_CONTAINER_NAME is set and non-empty,
exiting with an error message if it is not.
| free -h # 메모리 상태 사전 체크 | ||
| docker ps # 현재 컨테이너 상태 | ||
| deploy: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
배포 조건에 머지 여부 확인 로직 추가 필요
현재 PR Close 시점에 무조건 배포됩니다. 머지된 경우에만 실행되도록 if: github.event.pull_request.merged == true를 추가하세요.
deploy:
- needs: warmup # ✅ warmup 완료 후 실행
+ needs: warmup # ✅ warmup 완료 후 실행
+ if: github.event.pull_request.merged == true📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| deploy: | |
| deploy: | |
| needs: warmup # ✅ warmup 완료 후 실행 | |
| if: github.event.pull_request.merged == true |
🤖 Prompt for AI Agents
In .github/workflows/deploy.yml at line 22, the deploy job currently runs
unconditionally when a PR is closed. To ensure deployment only occurs if the PR
was merged, add the condition `if: github.event.pull_request.merged == true` to
the deploy job definition. This will restrict the deployment step to run only
when the PR merge event is confirmed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (7)
.github/workflows/ci.yml (3)
39-49: 메모리 기반 파일 추출 임계값 로직
- 200MB 이하일 때 상한 10 파일, PR 크기가 30개 초과 시 30 파일 제한은 합리적입니다.
head -$MAX_FILES대신head -n $MAX_FILES를 사용해 POSIX 호환성을 높이세요.Also applies to: 51-51
72-76: 파일 수 및 메모리 추정 로직
wc -w대신wc -l로 파일 개수를 세면 파일 경로에 공백이 있을 때도 정확합니다.
12-12: 트레일링 공백 제거
YAML 파일에서 트레일링 스페이스는 lint 에러를 발생시킵니다. 해당 라인의 공백을 제거하세요.Also applies to: 18-18, 32-32, 35-35, 37-37, 50-50, 52-52
.github/workflows/deploy.yml (4)
21-24: GitHub 컨텍스트 직접 사용 보안 검토
${{ github.event.pull_request.title }}등 사용자 입력에 직접 의존한 인라인 스크립트는 잠재적 인젝션 위험이 있습니다. 환경 변수로 분리한 뒤, 적절히 인용해 사용하거나 검증 로직을 추가하세요.
50-52: 절대 경로 하드코딩 개선 제안
cd /home/ubuntu/coplan대신${{ github.workspace }}나 환경 변수로 경로를 관리하면 이식성을 높일 수 있습니다.
59-67: 컨테이너 검사 시 변수 인용
$DOCKER_CONTAINER_NAME사용 시 따옴표를 추가해 예기치 않은 공백이나 특수문자 이슈를 방지하세요.-if docker ps | grep -q $DOCKER_CONTAINER_NAME; then +if docker ps | grep -q "$DOCKER_CONTAINER_NAME"; then또한
docker logs호출부에도"$DOCKER_CONTAINER_NAME"인용을 일관되게 적용하세요.
27-28: 트레일링 공백 제거
whoami,docker --version행에 트레일링 스페이스가 존재합니다. YAML lint 오류를 방지하려면 제거하세요.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.github/workflows/ci.yml(1 hunks).github/workflows/deploy.yml(1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
.github/workflows/ci.yml
[error] 32-32: trailing spaces
(trailing-spaces)
[error] 35-35: trailing spaces
(trailing-spaces)
[error] 37-37: trailing spaces
(trailing-spaces)
[error] 50-50: trailing spaces
(trailing-spaces)
[error] 52-52: trailing spaces
(trailing-spaces)
.github/workflows/deploy.yml
[error] 27-27: trailing spaces
(trailing-spaces)
[error] 28-28: trailing spaces
(trailing-spaces)
🪛 actionlint (1.7.7)
.github/workflows/deploy.yml
19-19: "github.event.pull_request.title" is potentially untrusted. avoid using it directly in inline scripts. instead, pass it through an environment variable. see https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions for more details
(expression)
🔇 Additional comments (11)
.github/workflows/ci.yml (7)
12-12: 타임아웃 재검토 필요
현재timeout-minutes: 2는 변경된 파일만 검사하는 워크플로우에 충분히 짧을 수 있지만, JS/TS 파일이 많은 경우 타임아웃이 발생할 수 있습니다. 실제 평균 실행 시간을 측정해보고, 안정적인 범위로 조정하세요.
16-16: actions/checkout@v4 및 fetch-depth 검증
actions/checkout@v4로 버전 업그레이드된 점이 좋습니다. 하지만fetch-depth: 2가 베이스 브랜치 비교에 충분한 이력을 확보하는지 확인이 필요합니다.Also applies to: 18-18
25-26: 메모리 체크 로직 적절성 검토
free -m | grep ^Mem | awk '{print $7}'으로 사용 가능한 메모리를 확인하는 방식은 일반적이지만, self-hosted 러너 환경에 따라 필드 위치가 달라질 수 있습니다. 다른 러너에서 일관되게 동작하는지 검증하세요.
28-34: PR/Push 이벤트 분기 로직 적절
PR 이벤트 시 베이스 브랜치와 비교하도록git diff origin/$BASE_BRANCH...HEAD를 사용한 점이 정확합니다. push 이벤트용HEAD~1분기 또한 fallback으로 적절하지만, 복수 커밋 PR은 PR 이벤트 분기로만 처리됨을 확인했습니다.
57-62: 푸시 이벤트 fallback 확인
푸시 이벤트에서HEAD~1이 존재하지 않을 경우 마지막 5개 파일을 대상으로 검색하는 로직이 안전장치로 적절합니다.
66-69: 변경 파일 없을 때 즉시 종료
[ -z "$CHANGED_FILES" ]체크 후exit 0로 종결하는 방식은 불필요한 실행을 방지해 효율적입니다.
78-78: ESLint 실행 방식
변경 파일만npx eslint $CHANGED_FILES로 검사하는 아이디어가 메모리 최적화 목표에 부합합니다..github/workflows/deploy.yml (4)
6-6: 배포 트리거 브랜치 제한 확인
branches: [main]로 명시적으로 main 브랜치만 배포하도록 수정된 점이 의도에 부합합니다.
9-9: 환경 변수 DOCKER_CONTAINER_NAME 선언
전역env로DOCKER_CONTAINER_NAME을 선언해 일관된 참조가 가능해진 점이 좋습니다.
16-17: 러너 및 타임아웃 설정 확인
self-hosted러너와timeout-minutes: 3설정은 빠른 warmup 단계에 적합합니다. 실제 warmup 단계 수행 시간을 모니터링해서 필요 시 조정하세요.
40-41: actions/checkout@v4 적용
actions/checkout@v4로 업그레이드된 점이 CI와 일관되어 안정적입니다.
📌 변경 사항 개요
기존 CI/CD 파이프라인의 메모리 사용량을 90% 절약하여 t2.micro 환경에서 안정적으로 동작하도록 최적화
✨ 요약
📝 상세 내용
CI 최적화
Deploy 최적화
🔗 관련 이슈
메모리 부족으로 인한 CI/CD 실패 문제 해결
✅ 체크리스트
💡 참고 사항
Summary by CodeRabbit
warmup,deploy)로 분리되어 안정성이 높아졌습니다.main브랜치로 제한되고, 환경 변수DOCKER_CONTAINER_NAME이 추가되었습니다.