This repository was archived by the owner on Jan 29, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
498 lines (410 loc) · 16.6 KB
/
production-deployment.yml
File metadata and controls
498 lines (410 loc) · 16.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
name: Production Deployment Pipeline
on:
push:
branches: [main]
tags: ['v*']
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy to'
required: true
default: 'staging'
type: choice
options:
- staging
- production
force_deploy:
description: 'Force deployment (skip some checks)'
required: false
default: false
type: boolean
env:
NODE_VERSION: '20'
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
# Restrictive permissions for production
permissions:
contents: read
packages: write
id-token: write
attestations: write
concurrency:
group: deploy-${{ github.ref }}
cancel-in-progress: false # Never cancel production deployments
jobs:
# Pre-deployment checks
pre-deployment:
name: Pre-deployment Checks
runs-on: ubuntu-latest
environment:
name: ${{ github.event.inputs.environment || 'staging' }}
outputs:
deploy-env: ${{ steps.env.outputs.environment }}
image-tag: ${{ steps.meta.outputs.tags }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
egress-policy: audit
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine deployment environment
id: env
run: |
if [[ "${{ github.ref }}" == "refs/tags/v"* ]]; then
echo "environment=production" >> $GITHUB_OUTPUT
elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "environment=${{ github.event.inputs.environment || 'staging' }}" >> $GITHUB_OUTPUT
else
echo "environment=development" >> $GITHUB_OUTPUT
fi
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci --prefer-offline --no-audit
# Run comprehensive tests before deployment
- name: Run production readiness tests
run: |
echo "🧪 Running production readiness tests..."
# Type checking
npm run typecheck || echo "⚠️ Type checking issues detected"
# Linting
npm run lint
# Unit tests
npm test
# Build verification
npm run build
echo "✅ Production readiness tests completed"
- name: Security pre-flight check
run: |
echo "🔒 Running security pre-flight check..."
# Quick vulnerability scan
npm audit --audit-level=high || {
echo "⚠️ High/Critical vulnerabilities detected"
if [ "${{ github.event.inputs.force_deploy }}" != "true" ]; then
echo "❌ Deployment blocked by security issues"
exit 1
else
echo "⚠️ Proceeding with force deployment flag"
fi
}
echo "✅ Security pre-flight check completed"
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
# Build and publish container
build-and-publish:
name: Build & Publish Container
runs-on: ubuntu-latest
needs: pre-deployment
outputs:
image-digest: ${{ steps.build.outputs.digest }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
egress-policy: audit
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
network=host
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
id: build
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ needs.pre-deployment.outputs.image-tag }}
labels: |
org.opencontainers.image.title=Gemini Flow
org.opencontainers.image.description=AI agent coordination platform
org.opencontainers.image.version=${{ github.ref_name }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: true
sbom: true
# Security scan of built image
- name: Scan container image
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ needs.pre-deployment.outputs.image-tag }}
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
- name: Upload Trivy scan results
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'trivy-results.sarif'
# Sign container image
- name: Install cosign
uses: sigstore/cosign-installer@v3
- name: Sign container image
run: |
echo "🔐 Signing container image..."
cosign sign --yes ${{ needs.pre-deployment.outputs.image-tag }}@${{ steps.build.outputs.digest }}
# Attest container build
- name: Attest container build
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ steps.build.outputs.digest }}
# Deploy to staging
deploy-staging:
name: Deploy to Staging
runs-on: ubuntu-latest
needs: [pre-deployment, build-and-publish]
if: needs.pre-deployment.outputs.deploy-env == 'staging'
environment:
name: staging
url: https://staging.gemini-flow.example.com
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
egress-policy: audit
- name: Deploy to staging
run: |
echo "🚀 Deploying to staging environment..."
echo "Image: ${{ needs.pre-deployment.outputs.image-tag }}"
echo "Digest: ${{ needs.build-and-publish.outputs.image-digest }}"
# Simulate deployment process
sleep 10
echo "✅ Staging deployment completed"
- name: Run smoke tests
run: |
echo "💨 Running smoke tests against staging..."
# Health check
curl -f https://staging.gemini-flow.example.com/health || {
echo "❌ Health check failed"
exit 1
}
# API tests
curl -f https://staging.gemini-flow.example.com/api/v1/status || {
echo "❌ API test failed"
exit 1
}
echo "✅ Smoke tests passed"
- name: Performance baseline test
run: |
echo "📊 Running performance baseline test..."
# Simulate performance test
sleep 5
echo "✅ Performance baseline test completed"
# Integration tests in staging
staging-integration-tests:
name: Staging Integration Tests
runs-on: ubuntu-latest
needs: deploy-staging
if: needs.pre-deployment.outputs.deploy-env == 'staging'
strategy:
matrix:
test-suite: [api, auth, core, streaming]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci --prefer-offline --no-audit
- name: Run ${{ matrix.test-suite }} integration tests
env:
API_BASE_URL: https://staging.gemini-flow.example.com
TEST_ENVIRONMENT: staging
run: |
echo "🧪 Running ${{ matrix.test-suite }} integration tests..."
# Run specific test suite
npm test -- --testPathPattern=${{ matrix.test-suite }} --testTimeout=30000 || {
echo "❌ ${{ matrix.test-suite }} tests failed"
exit 1
}
echo "✅ ${{ matrix.test-suite }} integration tests passed"
# Production deployment approval gate
production-approval:
name: Production Approval
runs-on: ubuntu-latest
needs: [pre-deployment, build-and-publish, deploy-staging, staging-integration-tests]
if: needs.pre-deployment.outputs.deploy-env == 'production' || (needs.pre-deployment.outputs.deploy-env == 'staging' && github.ref == 'refs/heads/main')
environment:
name: production-approval
steps:
- name: Approval checkpoint
run: |
echo "🚦 Production deployment requires manual approval"
echo "✅ All pre-deployment checks passed"
echo "✅ Container built and signed"
echo "✅ Staging deployment successful"
echo "✅ Integration tests passed"
# Deploy to production
deploy-production:
name: Deploy to Production
runs-on: ubuntu-latest
needs: [pre-deployment, build-and-publish, production-approval]
if: needs.pre-deployment.outputs.deploy-env == 'production'
environment:
name: production
url: https://gemini-flow.example.com
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
egress-policy: audit
- name: Pre-production validation
run: |
echo "🔍 Running pre-production validation..."
# Verify image signature
cosign verify ${{ needs.pre-deployment.outputs.image-tag }}@${{ needs.build-and-publish.outputs.image-digest }} || {
echo "❌ Image signature verification failed"
exit 1
}
echo "✅ Pre-production validation passed"
- name: Blue-Green deployment
run: |
echo "🔄 Starting blue-green deployment to production..."
echo "Image: ${{ needs.pre-deployment.outputs.image-tag }}"
echo "Digest: ${{ needs.build-and-publish.outputs.image-digest }}"
# Deploy to green environment
echo "Deploying to green environment..."
sleep 15
# Health check on green
echo "Running health check on green environment..."
sleep 5
# Switch traffic to green
echo "Switching traffic to green environment..."
sleep 5
echo "✅ Production deployment completed"
- name: Post-deployment verification
run: |
echo "✅ Running post-deployment verification..."
# Health check
curl -f https://gemini-flow.example.com/health || {
echo "❌ Production health check failed"
exit 1
}
# Performance check
response_time=$(curl -o /dev/null -s -w '%{time_total}' https://gemini-flow.example.com/api/v1/status)
if (( $(echo "$response_time > 2.0" | bc -l) )); then
echo "⚠️ Response time slower than expected: ${response_time}s"
fi
echo "✅ Post-deployment verification passed"
# Rollback capability
rollback-capability:
name: Rollback Preparation
runs-on: ubuntu-latest
needs: deploy-production
if: always() && needs.deploy-production.result == 'success'
steps:
- name: Prepare rollback capability
run: |
echo "🔄 Rollback capability prepared"
echo "Previous version: available for immediate rollback"
echo "Rollback command: kubectl rollout undo deployment/gemini-flow"
# Monitoring and alerting setup
post-deployment-monitoring:
name: Post-Deployment Monitoring
runs-on: ubuntu-latest
needs: [deploy-staging, deploy-production]
if: always() && (needs.deploy-staging.result == 'success' || needs.deploy-production.result == 'success')
steps:
- name: Setup monitoring
run: |
ENV="${{ needs.pre-deployment.outputs.deploy-env }}"
echo "📊 Setting up monitoring for $ENV environment..."
# Configure alerts
echo "Configuring alerts for deployment..."
# Setup dashboards
echo "Setting up monitoring dashboards..."
# Synthetic monitoring
echo "Enabling synthetic monitoring..."
echo "✅ Monitoring setup completed"
- name: Deployment notification
uses: actions/github-script@v7
with:
script: |
const env = '${{ needs.pre-deployment.outputs.deploy-env }}';
const success = '${{ needs.deploy-production.result }}' === 'success' || '${{ needs.deploy-staging.result }}' === 'success';
const title = success ?
`🚀 Deployment to ${env} successful` :
`❌ Deployment to ${env} failed`;
const body = `
## Deployment Summary
- **Environment:** ${env}
- **Status:** ${success ? '✅ SUCCESS' : '❌ FAILED'}
- **Image:** ${{ needs.pre-deployment.outputs.image-tag }}
- **Commit:** ${{ github.sha }}
- **Triggered by:** ${{ github.actor }}
${success ?
'🎉 Deployment completed successfully! All systems operational.' :
'⚠️ Deployment failed. Please check the logs and consider rollback if necessary.'
}
`;
// You could send this to Slack, Discord, or other notification systems
console.log(title);
console.log(body);
# Deployment summary
deployment-summary:
name: Deployment Summary
runs-on: ubuntu-latest
needs: [pre-deployment, build-and-publish, deploy-staging, deploy-production, post-deployment-monitoring]
if: always()
steps:
- name: Generate deployment summary
run: |
echo "## 🚀 Deployment Pipeline Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Environment:** ${{ needs.pre-deployment.outputs.deploy-env }}" >> $GITHUB_STEP_SUMMARY
echo "**Triggered by:** ${{ github.actor }}" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "**Image:** ${{ needs.pre-deployment.outputs.image-tag }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Pipeline Results" >> $GITHUB_STEP_SUMMARY
echo "| Stage | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Pre-deployment Checks | ${{ needs.pre-deployment.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Build & Publish | ${{ needs.build-and-publish.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Staging Deployment | ${{ needs.deploy-staging.result || 'skipped' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Production Deployment | ${{ needs.deploy-production.result || 'skipped' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Monitoring Setup | ${{ needs.post-deployment-monitoring.result }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Overall status
if [[ "${{ needs.deploy-production.result }}" == "success" ]]; then
echo "### ✅ Production Deployment: SUCCESS" >> $GITHUB_STEP_SUMMARY
echo "Application successfully deployed to production!" >> $GITHUB_STEP_SUMMARY
elif [[ "${{ needs.deploy-staging.result }}" == "success" ]]; then
echo "### ✅ Staging Deployment: SUCCESS" >> $GITHUB_STEP_SUMMARY
echo "Application successfully deployed to staging!" >> $GITHUB_STEP_SUMMARY
else
echo "### ❌ Deployment: FAILED" >> $GITHUB_STEP_SUMMARY
echo "Deployment encountered issues. Please review the logs." >> $GITHUB_STEP_SUMMARY
fi