CollabOps

Phase 파이프라인

phase 메타데이터를 활용한 단계별 파이프라인 — source, deps, build, test, deploy

phase 필드를 활용하여 대시보드에서 파이프라인 단계를 시각적으로 구분하는 예제입니다. 9개 Job이 source → deps → build → test → deploy 순서로 진행됩니다.

전체 코드

name: phase-full-pipeline

triggers:
  push:
    branches: [main]

jobs:
  # ═══════════════════════════════════════
  # Phase: source — 소스코드 체크아웃
  # ═══════════════════════════════════════

  source-checkout:
    phase: source
    steps:
      # 코드 체크아웃
      - name: checkout-code
        uses: "collabops/checkout@v2"
        with:
          repo-url: "https://<collabops-host>/<workspace>/<repository>.git"
          submodules: "recursive"

  # ═══════════════════════════════════════
  # Phase: deps — 의존성 설치 + 캐시
  # ═══════════════════════════════════════

  deps-install:
    phase: deps
    needs: [source-checkout]
    steps:
      - name: install-dependencies
        image: node:18
        run: npm ci
        env:
          NODE_ENV: production

      - name: cache-dependencies
        image: node:18
        run: npm cache verify

  # ═══════════════════════════════════════
  # Phase: build — 앱 빌드 + Docker 이미지
  # ═══════════════════════════════════════

  build-app:
    phase: build
    needs: [deps-install]
    services:
      - docker
    steps:
      - name: compile-app
        image: node:18
        run: npm run build
        env:
          BUILD_ENV: production

      - name: build-docker-image
        image: docker:27.5-cli
        run: docker build -t myapp:latest .

  # ═══════════════════════════════════════
  # Phase: test — 단위/통합 테스트 (병렬)
  # ═══════════════════════════════════════

  # 단위 테스트 + 커버리지
  test-unit:
    phase: test
    needs: [build-app]
    steps:
      - name: run-unit-tests
        image: node:18
        run: npm run test:unit

      - name: generate-coverage
        image: node:18
        run: npm run coverage

  # 통합 테스트
  test-integration:
    phase: test
    needs: [build-app]                # test-unit과 병렬 실행
    steps:
      - name: run-integration-tests
        image: node:18
        run: npm run test:integration

  # ═══════════════════════════════════════
  # Phase: test — 보안 스캔 (테스트와 병렬)
  # ═══════════════════════════════════════

  security-scan:
    phase: test
    needs: [build-app]                # 테스트와 병렬 실행
    steps:
      # 의존성 취약점 스캔
      - name: vulnerability-scan
        image: node:18
        run: npm audit --audit-level=high

      # 정적 분석 보안 스캔
      - name: sast-scan
        image: node:18
        run: npm run security:scan

      # 라이선스 호환성 검사
      - name: license-check
        image: node:18
        run: npm run license:check

  # 보안 승인 대기
  security-approval:
    phase: test
    needs: [security-scan]
    steps:
      - name: wait-for-approval
        run: echo "Security scan passed — proceeding to deploy"

  # ═══════════════════════════════════════
  # Phase: deploy — 스테이징 → 프로덕션
  # ═══════════════════════════════════════

  # 스테이징 배포 — 테스트 + 보안 모두 통과 후
  deploy-staging:
    phase: deploy
    needs: [test-unit, test-integration, security-approval]
    steps:
      - name: deploy-to-staging
        run: kubectl apply -f k8s/staging/
        env:
          DEPLOY_ENV: staging

      - name: health-check
        run: |
          echo "Running health check..."
          curl -f http://staging.example.com/health

  # 프로덕션 배포 — 스테이징 검증 후
  deploy-production:
    phase: deploy
    needs: [deploy-staging]
    if: "collabops.ref == 'refs/heads/main' && collabops.event_name == 'push'"
    steps:
      - name: deploy-to-production
        run: kubectl apply -f k8s/production/
        env:
          DEPLOY_ENV: production

      - name: health-check
        run: curl -f http://production.example.com/health

      - name: notify-deployment
        uses: "collabops/slack-notify@v1"
        with:
          webhook-url: ${{ secrets.SLACK_WEBHOOK }}
          message: "프로덕션 배포 완료: ${{ collabops.sha }}"
          color: good

Phase 단계별 Job 매핑

PhaseJobs설명
sourcesource-checkout소스코드 체크아웃
depsdeps-install의존성 설치 및 캐시
buildbuild-app앱 빌드 + Docker 이미지
testtest-unit, test-integration, security-scan, security-approval테스트 + 보안 (병렬)
deploydeploy-staging, deploy-production스테이징 → 프로덕션

실행 흐름

source-checkout
  └── deps-install
        └── build-app
              ├── test-unit ──────────────┐
              ├── test-integration ────────┼── deploy-staging ── deploy-production
              └── security-scan           │
                    └── security-approval ┘

포인트

phase는 대시보드에서 단계를 시각적으로 구분하기 위한 메타데이터입니다.

실행 순서는 needs로 제어합니다. phase는 실행 동작에 영향을 주지 않습니다.

같은 phase의 Job이라도 needs가 다르면 다른 시점에 실행됩니다.

사용 가능한 phase: source, deps, build, test, security, deploy

목차