βš™οΈ

GitHub Actions λΉŒλ“œΒ·ν…ŒμŠ€νŠΈΒ·λ³΄μ•ˆ μŠ€μΊ” μ›Œν¬ν”Œλ‘œμš° μ„œμ‹

PR 단계 λ¦°νŠΈΒ·λ‹¨μœ„ ν…ŒμŠ€νŠΈΒ·Trivy μ»¨ν…Œμ΄λ„ˆ/νŒŒμΌμ‹œμŠ€ν…œ 취약점 μŠ€μΊ”κ³Ό main 브랜치 μžλ™ λΉŒλ“œΒ·λ°°ν¬λ₯Ό λ°”λ‘œ μ μš©ν•  수 μžˆλŠ” ν‘œμ€€ GitHub Actions YAML μ„œμ‹μž…λ‹ˆλ‹€.

GitHub & CI/CDYAMLμ—…λ°μ΄νŠΈ: 2026-11-15

πŸ“‹ μ„œμ‹ κ°œμš”

μ €μž₯μ†Œμ˜ .github/workflows/ci-cd.yml에 λ°”λ‘œ 볡사해 μ‚¬μš©ν•  수 μžˆλŠ” ν‘œμ€€ CI/CD + λ³΄μ•ˆ μŠ€μΊ”(DevSecOps) μ›Œν¬ν”Œλ‘œμš° μ„œμ‹μž…λ‹ˆλ‹€.
PRμ—μ„œλŠ” λΉ λ₯Έ 검증(LintΒ·TestΒ·Trivy μŠ€μΊ”)을 μˆ˜ν–‰ν•˜κ³ , main 브랜치 ν‘Έμ‹œ μ‹œμ—λ§Œ μ»¨ν…Œμ΄λ„ˆ 이미지λ₯Ό λΉŒλ“œΒ·ν‘Έμ‹œν•©λ‹ˆλ‹€.


# .github/workflows/ci-cd.yml
name: CI/CD & Security Pipeline

on:
  pull_request:
    branches: [main]
  push:
    branches: [main]

# 동일 PR에 μƒˆ 컀밋이 ν‘Έμ‹œλ˜λ©΄ 이전 μ‹€ν–‰ μžλ™ μ·¨μ†Œ
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

permissions:
  contents: read
  packages: write
  security-events: write

jobs:
  lint-and-test:
    name: Lint & Unit Test
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "22"
          cache: "npm"

      - name: Install dependencies
        run: npm ci

      - name: Run linter & typecheck
        run: npm run lint --if-present && npm run typecheck --if-present

      - name: Run tests
        run: npm test --if-present

      - name: Build application
        run: npm run build

  security-scan:
    name: Trivy FS & Secret Scan
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Run Trivy vulnerability & secret scan
        uses: aquasecurity/trivy-action@0.28.0
        with:
          scan-type: "fs"
          scan-ref: "."
          scanners: "vuln,secret,misconfig"
          severity: "CRITICAL,HIGH"
          exit-code: "1"
          format: "sarif"
          output: "trivy-results.sarif"

      - name: Upload Trivy SARIF to GitHub Security tab
        if: always()
        uses: github/codeql-action/upload-sarif@v3
        with:
          sarif_file: "trivy-results.sarif"

  build-and-push:
    name: Build & Push Container Image
    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
    needs: [lint-and-test, security-scan]
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Login to GitHub Container Registry (GHCR)
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Setup Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Build and push Docker image
        uses: docker/build-push-action@v6
        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
πŸ’¬

의견 및 질문

0
0 / 1500