GitHub Actions λΉλΒ·ν μ€νΈΒ·λ³΄μ μ€μΊ μν¬νλ‘μ° μμ
PR λ¨κ³ λ¦°νΈΒ·λ¨μ ν μ€νΈΒ·Trivy 컨ν μ΄λ/νμΌμμ€ν μ·¨μ½μ μ€μΊκ³Ό main λΈλμΉ μλ λΉλΒ·λ°°ν¬λ₯Ό λ°λ‘ μ μ©ν μ μλ νμ€ GitHub Actions YAML μμμ λλ€.
π μμ κ°μ
μ μ₯μμ .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μμ§ λ±λ‘λ μκ²¬μ΄ μμ΅λλ€. 첫 λ²μ§Έ λκΈμ λ¨κ²¨λ³΄μΈμ!
λκΈ μμ
λκΈ μμ