stack-analysis
CHAPTER 55 / 90
읽기 약 2분
FUNCTION
CI/CD: GitHub Actions 실전
핵심 개념
워크플로우·매트릭스·시크릿·환경별 배포 — main push → 5분 후 프로덕션.
본문
기본 CI 워크플로우
# .github/workflows/ci.yml
name: CI
on:
pull_request:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_PASSWORD: test
POSTGRES_DB: test
ports: ['5432:5432']
options: >-
--health-cmd pg_isready --health-interval 5s
--health-timeout 5s --health-retries 5
redis:
image: redis:7-alpine
ports: ['6379:6379']
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- name: Lint
run: pnpm lint
- name: Type Check
run: pnpm typecheck
- name: Migrate
env:
DATABASE_URL: postgresql://postgres:test@localhost:5432/test
run: pnpm dlx prisma migrate deploy
- name: Test
env:
DATABASE_URL: postgresql://postgres:test@localhost:5432/test
REDIS_URL: redis://localhost:6379
run: pnpm test --coverage
- name: Upload coverage
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Build
run: pnpm build매트릭스 빌드
strategy:
matrix:
node: [18, 20, 22]
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
# ... 9개 조합 동시 실행환경별 배포
# .github/workflows/deploy.yml
name: Deploy
on:
push:
branches: [main, staging]
jobs:
deploy:
runs-on: ubuntu-latest
environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}
steps:
- uses: actions/checkout@v4
- name: Deploy to Vercel
uses: amondnet/vercel-action@v25
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
vercel-args: ${{ github.ref == 'refs/heads/main' && '--prod' || '' }}
- name: Notify Slack
if: always()
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,ref
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}시크릿 관리
GitHub Settings → Environments → production
- DATABASE_URL (production)
- AWS_ACCESS_KEY
- VERCEL_TOKEN
→ environment 보호 규칙:
- Required reviewers (PR 승인 필요)
- Deployment branches (main만)
- Wait timer (5분 cooling)
→ Pull Request에서 시크릿 접근 불가
→ main push 시점에만 사용Docker 이미지 빌드 + Push
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64E2E 테스트 — Playwright
- name: Install Playwright
run: pnpm dlx playwright install --with-deps chromium
- name: E2E
run: pnpm test:e2e
env:
BASE_URL: http://localhost:3000
- name: Upload artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: playwright-report/Lighthouse CI (성능)
- name: Lighthouse CI
uses: treosh/lighthouse-ci-action@v11
with:
urls: |
https://staging.example.com
https://staging.example.com/posts
budgetPath: ./lighthouse-budget.json
uploadArtifacts: true
# lighthouse-budget.json
[{
"path": "/*",
"resourceSizes": [
{ "resourceType": "script", "budget": 300 },
{ "resourceType": "image", "budget": 500 }
],
"timings": [
{ "metric": "lcp", "budget": 2500 }
]
}]자동 PR 라벨링
# .github/workflows/label.yml
- uses: actions/labeler@v5
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
# .github/labeler.yml
frontend:
- 'app/**/*'
- 'components/**/*'
backend:
- 'server/**/*'
- 'api/**/*'
docs:
- '**/*.md'다음 챕터
CH.56 "환경 변수와 시크릿 관리".
AI 프롬프트
🤖 AI에게 잘 물어보는 법 — 모델·전략별 프롬프트
Claude
무료: Sonnet 4.6 / Pro $20/mo: Opus 4.6
내 코드의 CI/CD 부분을 분석해서 실전 분석 + 개선 우선순위를 알려줘.
ChatGPT
무료: GPT-5.5 / Plus $20/mo: GPT-5.5 Pro
CI/CD 관련 인기 라이브러리/패턴 5개를 비교 분석해서 패턴 추출를 알려줘.
Gemini
무료: 2.5 Flash / Pro $19.99/mo: 3.1 Pro
내 프로젝트 전체에서 CI/CD 최적화 가능 위치를 보고해줘.
Grok
무료: Grok 4.1 / SuperGrok $30/mo
2026년 한국 백엔드 시장의 CI/CD 트렌드를 솔직히 알려줘.
⭐ 이것만 기억하세요
CI/CD: GitHub Actions 실전은 이 3가지만 확실히 잡으세요
1.GitHub Actions = 표준 CI/CD — 무료 사용량 충분 (2,000분/월)
2.Environment 보호 규칙으로 production 배포 통제
3.matrix·docker buildx로 다중 환경 동시 검증
공유하기
진행도 55 / 90