Skip to content

Commit 41090e2

Browse files
authored
Merge pull request #110 from CoPlay-FE/refactor/chanho
♻️ refactor: CI/CD 파이프라인 메모리 최적화
2 parents 6c170a2 + a230106 commit 41090e2

File tree

2 files changed

+110
-43
lines changed

2 files changed

+110
-43
lines changed

.github/workflows/ci.yml

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,71 @@ on:
99
jobs:
1010
eslint-check:
1111
runs-on: self-hosted
12-
timeout-minutes: 10
12+
timeout-minutes: 2
1313

1414
steps:
15-
# 코드 가져오기
1615
- name: Checkout code
17-
uses: actions/checkout@v3
18-
19-
# Node.js 환경 설정
20-
- name: Setup Node.js
21-
uses: actions/setup-node@v4
16+
uses: actions/checkout@v4
2217
with:
23-
node-version: '18'
24-
cache: 'npm'
18+
fetch-depth: 2 # HEAD와 베이스 브랜치 히스토리 확보
19+
20+
- name: Lightning fast lint check
21+
run: |
22+
echo "⚡ Quick lint check..."
23+
24+
# 메모리 상태 사전 체크
25+
AVAILABLE_MB=$(free -m | grep ^Mem | awk '{print $7}')
26+
echo "💾 Available memory: ${AVAILABLE_MB}MB"
27+
28+
if [ "${{ github.event_name }}" = "pull_request" ]; then
29+
# PR인 경우: 베이스 브랜치와 비교
30+
BASE_BRANCH="${{ github.base_ref }}"
31+
git fetch origin $BASE_BRANCH --depth=1
32+
33+
ALL_CHANGED=$(git diff --name-only origin/$BASE_BRANCH...HEAD -- '*.ts' '*.tsx' '*.js' '*.jsx')
34+
FILE_COUNT=$(echo "$ALL_CHANGED" | wc -w)
35+
36+
echo "📊 Base: $BASE_BRANCH, Changed files: $FILE_COUNT"
37+
38+
# 🛡️ 메모리 기반 안전장치
39+
if [ "$AVAILABLE_MB" -lt 200 ]; then
40+
MAX_FILES=10
41+
echo "⚠️ Low memory mode: checking $MAX_FILES files only"
42+
elif [ "$FILE_COUNT" -gt 30 ]; then
43+
MAX_FILES=30
44+
echo "⚠️ Large PR detected: checking first $MAX_FILES files for memory safety"
45+
echo "ℹ️ Note: Full project will be built during deployment"
46+
else
47+
MAX_FILES="$FILE_COUNT"
48+
echo "✅ Normal mode: checking all $FILE_COUNT files"
49+
fi
50+
51+
CHANGED_FILES=$(echo "$ALL_CHANGED" | head -$MAX_FILES)
52+
53+
else
54+
# Push인 경우: 이전 커밋과 비교
55+
echo "🔍 Push event detected"
56+
if git rev-parse --verify HEAD~1 >/dev/null 2>&1; then
57+
CHANGED_FILES=$(git diff --name-only HEAD~1 -- '*.ts' '*.tsx' '*.js' '*.jsx')
58+
echo "📝 Checking files changed since last commit"
59+
else
60+
echo "🔍 First commit or shallow clone, checking recent files"
61+
CHANGED_FILES=$(find . -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" | grep -v node_modules | head -5)
62+
fi
63+
fi
64+
65+
# 변경사항 없으면 즉시 종료
66+
if [ -z "$CHANGED_FILES" ]; then
67+
echo "✅ No JS/TS files to check"
68+
exit 0
69+
fi
2570
26-
# 의존성 설치
27-
- name: Install dependencies
28-
run: npm ci
71+
# 최종 실행 정보
72+
FINAL_COUNT=$(echo $CHANGED_FILES | wc -w)
73+
ESTIMATED_MB=$((FINAL_COUNT * 2))
74+
echo "🧠 Checking $FINAL_COUNT files (~${ESTIMATED_MB}MB estimated)"
75+
echo "📝 Files: $CHANGED_FILES"
2976
30-
# ESLint 실행
31-
- name: Run ESLint
32-
run: npm run lint
77+
# 글로벌 ESLint 실행
78+
npx eslint $CHANGED_FILES
79+
echo "✅ Lint check passed!"

.github/workflows/deploy.yml

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,74 @@ name: Deploy to EC2
33
on:
44
pull_request:
55
types: [closed]
6-
branches: [main, develop]
6+
branches: [main] # main 브랜치만 배포
7+
8+
env:
9+
DOCKER_CONTAINER_NAME: coplan-app
710

811
jobs:
9-
deploy:
12+
warmup:
13+
# 🛡️ 머지된 경우에만 실행
1014
if: github.event.pull_request.merged == true
1115
runs-on: self-hosted
12-
timeout-minutes: 15
16+
timeout-minutes: 3
17+
steps:
18+
- name: Environment check
19+
run: |
20+
echo "=== Deployment System Check ==="
21+
echo "📋 Merged PR: ${{ github.event.pull_request.title }}"
22+
echo "👤 Author: ${{ github.event.pull_request.user.login }}"
23+
echo "🔄 From: ${{ github.event.pull_request.head.ref }} → ${{ github.event.pull_request.base.ref }}"
24+
echo "📝 Commit: ${{ github.event.pull_request.merge_commit_sha }}"
25+
echo ""
26+
echo "🖥️ System Status:"
27+
whoami
28+
docker --version
29+
free -h
30+
echo ""
31+
echo "🐳 Container Status:"
32+
docker ps
1333
34+
deploy:
35+
needs: warmup
36+
runs-on: self-hosted
37+
timeout-minutes: 10
1438
steps:
1539
- name: Checkout code
16-
uses: actions/checkout@v3
40+
uses: actions/checkout@v4
1741

18-
- name: Deploy to EC2
42+
- name: Execute deployment script
1943
run: |
2044
echo "🚀 Starting deployment..."
2145
echo "🔄 Branch: ${{ github.ref_name }}"
2246
echo "🔄 Commit: ${{ github.sha }}"
47+
echo "📦 PR: #${{ github.event.pull_request.number }}"
2348
24-
# 메모리 정리
25-
echo "🧹 Cleaning up memory..."
26-
docker system prune -f
27-
28-
# 앱 디렉토리로 코드 복사
29-
echo "📂 Copying files..."
30-
rsync -av --delete \
31-
--exclude='.git' \
32-
--exclude='node_modules' \
33-
--exclude='.next' \
34-
./ /home/ubuntu/coplan/app/
35-
36-
# 배포 디렉토리로 이동
49+
# deploy.sh 실행
3750
cd /home/ubuntu/coplan
51+
chmod +x ./deploy.sh
52+
./deploy.sh
3853
39-
# Docker 컨테이너 재시작
40-
echo "🔄 Restarting containers..."
41-
docker compose down
42-
docker compose up -d --build
43-
44-
# 헬스체크
54+
- name: Health check
55+
run: |
4556
echo "🏥 Health checking..."
4657
sleep 15
4758
48-
if docker ps | grep -q coplan-app; then
59+
if docker ps | grep -q $DOCKER_CONTAINER_NAME; then
4960
echo "✅ Deployment completed successfully!"
50-
docker logs --tail 10 coplan-app
51-
echo "🌐 Service available at: http://15.164.127.149"
61+
echo "📊 Container status:"
62+
docker ps | grep $DOCKER_CONTAINER_NAME
63+
echo ""
64+
echo "📝 Recent logs:"
65+
docker logs --tail 5 $DOCKER_CONTAINER_NAME
66+
echo ""
67+
echo "🌐 Service available at: https://coplan.work"
5268
else
5369
echo "❌ Deployment failed!"
54-
docker logs coplan-app
70+
echo "🔍 Checking container logs..."
71+
docker logs $DOCKER_CONTAINER_NAME 2>/dev/null || echo "No container logs available"
72+
echo "🔍 Checking system status..."
73+
docker ps -a
74+
free -h
5575
exit 1
5676
fi

0 commit comments

Comments
 (0)