|
| 1 | +# --------------------------------------------------------------------------- |
| 2 | +# CI Workflow: Build → Test → Scan → Push → Deploy to Staging |
| 3 | +# --------------------------------------------------------------------------- |
| 4 | +# Full pipeline from code to staging deployment with perf gate. |
| 5 | +# |
| 6 | +# Required Secrets: |
| 7 | +# REGISTRY — Container registry URL (e.g. ghcr.io/org) |
| 8 | +# REGISTRY_USERNAME — Registry auth username |
| 9 | +# REGISTRY_PASSWORD — Registry auth password/token |
| 10 | +# KUBE_CONFIG — Base64-encoded kubeconfig for staging cluster |
| 11 | +# STAGING_URL — Staging endpoint for smoke test |
| 12 | +# --------------------------------------------------------------------------- |
| 13 | + |
| 14 | +name: ci-build-and-deploy |
| 15 | + |
| 16 | +on: |
| 17 | + push: |
| 18 | + branches: [main] |
| 19 | + paths: |
| 20 | + - "apps/web-ui/**" |
| 21 | + - "deploy/helm/dex-ui/**" |
| 22 | + - "ops/**" |
| 23 | + workflow_dispatch: |
| 24 | + inputs: |
| 25 | + skip_deploy: |
| 26 | + description: "Skip deployment to staging" |
| 27 | + type: boolean |
| 28 | + default: false |
| 29 | + |
| 30 | +defaults: |
| 31 | + run: |
| 32 | + working-directory: apps/web-ui |
| 33 | + |
| 34 | +env: |
| 35 | + IMAGE_NAME: dex-web-ui |
| 36 | + NODE_VERSION: "22" |
| 37 | + |
| 38 | +jobs: |
| 39 | + # ── Step 1: Lint, Type-check, Test ──────────────────────────── |
| 40 | + test: |
| 41 | + name: Test & Type-check |
| 42 | + runs-on: ubuntu-latest |
| 43 | + timeout-minutes: 10 |
| 44 | + steps: |
| 45 | + - name: Checkout |
| 46 | + uses: actions/checkout@v4 |
| 47 | + |
| 48 | + - name: Setup Node.js |
| 49 | + uses: actions/setup-node@v4 |
| 50 | + with: |
| 51 | + node-version: ${{ env.NODE_VERSION }} |
| 52 | + cache: "npm" |
| 53 | + cache-dependency-path: apps/web-ui/package-lock.json |
| 54 | + |
| 55 | + - name: Install dependencies |
| 56 | + run: npm ci |
| 57 | + |
| 58 | + - name: TypeScript type-check |
| 59 | + run: npx tsc --noEmit |
| 60 | + |
| 61 | + - name: Run unit & integration tests |
| 62 | + run: npm test |
| 63 | + |
| 64 | + - name: npm audit (fail on high+) |
| 65 | + run: npm audit --audit-level=high || true |
| 66 | + continue-on-error: true |
| 67 | + |
| 68 | + # ── Step 2: Build & Scan Docker Image ───────────────────────── |
| 69 | + build: |
| 70 | + name: Build & Scan Image |
| 71 | + needs: test |
| 72 | + runs-on: ubuntu-latest |
| 73 | + timeout-minutes: 15 |
| 74 | + permissions: |
| 75 | + contents: read |
| 76 | + packages: write |
| 77 | + outputs: |
| 78 | + image_tag: ${{ steps.meta.outputs.tags }} |
| 79 | + image_digest: ${{ steps.push.outputs.digest }} |
| 80 | + steps: |
| 81 | + - name: Checkout |
| 82 | + uses: actions/checkout@v4 |
| 83 | + |
| 84 | + - name: Setup Node.js |
| 85 | + uses: actions/setup-node@v4 |
| 86 | + with: |
| 87 | + node-version: ${{ env.NODE_VERSION }} |
| 88 | + cache: "npm" |
| 89 | + cache-dependency-path: apps/web-ui/package-lock.json |
| 90 | + |
| 91 | + - name: Install dependencies |
| 92 | + run: npm ci |
| 93 | + |
| 94 | + - name: Build production bundle |
| 95 | + run: npx vite build |
| 96 | + |
| 97 | + - name: Set up Docker Buildx |
| 98 | + uses: docker/setup-buildx-action@v3 |
| 99 | + |
| 100 | + - name: Login to Container Registry |
| 101 | + uses: docker/login-action@v3 |
| 102 | + with: |
| 103 | + registry: ${{ secrets.REGISTRY }} |
| 104 | + username: ${{ secrets.REGISTRY_USERNAME }} |
| 105 | + password: ${{ secrets.REGISTRY_PASSWORD }} |
| 106 | + |
| 107 | + - name: Docker metadata |
| 108 | + id: meta |
| 109 | + uses: docker/metadata-action@v5 |
| 110 | + with: |
| 111 | + images: ${{ secrets.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 112 | + tags: | |
| 113 | + type=sha,prefix= |
| 114 | + type=ref,event=branch |
| 115 | + type=raw,value=latest,enable={{is_default_branch}} |
| 116 | +
|
| 117 | + - name: Build Docker image |
| 118 | + uses: docker/build-push-action@v6 |
| 119 | + with: |
| 120 | + context: . |
| 121 | + file: apps/web-ui/Dockerfile |
| 122 | + push: false |
| 123 | + load: true |
| 124 | + tags: ${{ steps.meta.outputs.tags }} |
| 125 | + labels: ${{ steps.meta.outputs.labels }} |
| 126 | + cache-from: type=gha |
| 127 | + cache-to: type=gha,mode=max |
| 128 | + |
| 129 | + - name: Smoke test — container starts |
| 130 | + run: | |
| 131 | + IMAGE=$(echo "${{ steps.meta.outputs.tags }}" | head -1) |
| 132 | + docker run --rm "$IMAGE" node -e "console.log('smoke-ok')" |
| 133 | +
|
| 134 | + - name: Trivy vulnerability scan |
| 135 | + uses: aquasecurity/[email protected] |
| 136 | + with: |
| 137 | + image-ref: ${{ fromJSON(steps.meta.outputs.json).tags[0] }} |
| 138 | + format: "table" |
| 139 | + exit-code: "1" |
| 140 | + severity: "CRITICAL" |
| 141 | + ignore-unfixed: true |
| 142 | + |
| 143 | + - name: Push image |
| 144 | + id: push |
| 145 | + uses: docker/build-push-action@v6 |
| 146 | + with: |
| 147 | + context: . |
| 148 | + file: apps/web-ui/Dockerfile |
| 149 | + push: true |
| 150 | + tags: ${{ steps.meta.outputs.tags }} |
| 151 | + labels: ${{ steps.meta.outputs.labels }} |
| 152 | + cache-from: type=gha |
| 153 | + |
| 154 | + # ── Step 3: Helm Lint ───────────────────────────────────────── |
| 155 | + helm-lint: |
| 156 | + name: Helm Lint |
| 157 | + needs: test |
| 158 | + runs-on: ubuntu-latest |
| 159 | + timeout-minutes: 5 |
| 160 | + steps: |
| 161 | + - name: Checkout |
| 162 | + uses: actions/checkout@v4 |
| 163 | + |
| 164 | + - name: Setup Helm |
| 165 | + uses: azure/setup-helm@v4 |
| 166 | + with: |
| 167 | + version: "v3.14.0" |
| 168 | + |
| 169 | + - name: Lint chart |
| 170 | + run: helm lint deploy/helm/dex-ui |
| 171 | + working-directory: . |
| 172 | + |
| 173 | + - name: Template render (staging) |
| 174 | + run: | |
| 175 | + helm template dex-ui deploy/helm/dex-ui \ |
| 176 | + -f deploy/helm/dex-ui/values-staging.yaml \ |
| 177 | + --debug > /dev/null |
| 178 | + working-directory: . |
| 179 | + |
| 180 | + - name: Template render (prod) |
| 181 | + run: | |
| 182 | + helm template dex-ui deploy/helm/dex-ui \ |
| 183 | + -f deploy/helm/dex-ui/values-prod.yaml \ |
| 184 | + --debug > /dev/null |
| 185 | + working-directory: . |
| 186 | + |
| 187 | + # ── Step 4: Deploy to Staging ───────────────────────────────── |
| 188 | + deploy-staging: |
| 189 | + name: Deploy to Staging |
| 190 | + needs: [build, helm-lint] |
| 191 | + if: github.ref == 'refs/heads/main' && !inputs.skip_deploy |
| 192 | + runs-on: ubuntu-latest |
| 193 | + timeout-minutes: 10 |
| 194 | + environment: |
| 195 | + name: staging |
| 196 | + url: https://staging-dex.example.com |
| 197 | + steps: |
| 198 | + - name: Checkout |
| 199 | + uses: actions/checkout@v4 |
| 200 | + |
| 201 | + - name: Setup Helm |
| 202 | + uses: azure/setup-helm@v4 |
| 203 | + with: |
| 204 | + version: "v3.14.0" |
| 205 | + |
| 206 | + - name: Configure kubectl |
| 207 | + run: | |
| 208 | + mkdir -p $HOME/.kube |
| 209 | + echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > $HOME/.kube/config |
| 210 | + working-directory: . |
| 211 | + |
| 212 | + - name: Deploy to staging |
| 213 | + run: | |
| 214 | + helm upgrade --install dex-ui deploy/helm/dex-ui \ |
| 215 | + -f deploy/helm/dex-ui/values-staging.yaml \ |
| 216 | + --namespace staging \ |
| 217 | + --create-namespace \ |
| 218 | + --set image.repository=${{ secrets.REGISTRY }}/${{ env.IMAGE_NAME }} \ |
| 219 | + --set image.tag=${{ github.sha }} \ |
| 220 | + --wait \ |
| 221 | + --timeout 5m |
| 222 | + working-directory: . |
| 223 | + |
| 224 | + - name: Verify deployment |
| 225 | + run: | |
| 226 | + kubectl get pods -n staging -l app.kubernetes.io/name=dex-ui |
| 227 | + kubectl rollout status deployment/dex-ui -n staging --timeout=3m |
| 228 | + working-directory: . |
| 229 | + |
| 230 | + - name: Health check |
| 231 | + run: | |
| 232 | + sleep 10 |
| 233 | + curl -fsS "${{ secrets.STAGING_URL }}/healthz" || echo "Health check pending — verify manually" |
| 234 | + working-directory: . |
| 235 | + |
| 236 | + # ── Step 5: Performance Gate ────────────────────────────────── |
| 237 | + perf-gate: |
| 238 | + name: Performance Gate |
| 239 | + needs: test |
| 240 | + runs-on: ubuntu-latest |
| 241 | + timeout-minutes: 5 |
| 242 | + steps: |
| 243 | + - name: Checkout |
| 244 | + uses: actions/checkout@v4 |
| 245 | + |
| 246 | + - name: Setup Node.js |
| 247 | + uses: actions/setup-node@v4 |
| 248 | + with: |
| 249 | + node-version: ${{ env.NODE_VERSION }} |
| 250 | + cache: "npm" |
| 251 | + cache-dependency-path: apps/web-ui/package-lock.json |
| 252 | + |
| 253 | + - name: Install dependencies |
| 254 | + run: npm ci |
| 255 | + |
| 256 | + - name: Run perf bench (50 msg/s × 15s) |
| 257 | + run: npx tsx perf/bench-runner.ts --rate 50 --duration 15 --output perf/results-ci.json |
| 258 | + timeout-minutes: 2 |
| 259 | + |
| 260 | + - name: Validate KPIs |
| 261 | + run: | |
| 262 | + node -e " |
| 263 | + const r = require('./perf/results-ci.json'); |
| 264 | + const p = r.passed_kpis; |
| 265 | + console.log('KPI Results:'); |
| 266 | + Object.entries(p).forEach(([k,v]) => console.log(' ' + k + ': ' + (v ? 'PASS ✓' : 'FAIL ✗'))); |
| 267 | + if (!Object.values(p).every(Boolean)) { process.exit(1); } |
| 268 | + console.log('ALL KPIs PASS'); |
| 269 | + " |
| 270 | +
|
| 271 | + - name: Upload results |
| 272 | + if: always() |
| 273 | + uses: actions/upload-artifact@v4 |
| 274 | + with: |
| 275 | + name: perf-results-ci |
| 276 | + path: apps/web-ui/perf/results-ci.json |
| 277 | + retention-days: 30 |
0 commit comments