-
Notifications
You must be signed in to change notification settings - Fork 0
284 lines (241 loc) · 8.07 KB
/
quantum-ci-cd-enhanced.yml
File metadata and controls
284 lines (241 loc) · 8.07 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
name: Quantum Infrastructure CI/CD Enhanced
on:
push:
branches: [ main, develop, 'feature/*' ]
paths:
- 'src/**'
- 'deploy/**'
- 'tests/**'
- 'pyproject.toml'
- 'requirements*.txt'
pull_request:
branches: [ main, develop ]
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy to'
required: true
default: 'staging'
type: choice
options:
- staging
- production
strategy:
description: 'Deployment strategy'
required: false
default: 'canary'
type: choice
options:
- canary
- blue-green
- rolling
env:
DOCKER_IMAGE: ghcr.io/${{ github.repository }}/quantum-node
HELM_VERSION: 3.14.0
KUBE_VERSION: 1.28.0
PYTHON_VERSION: '3.10'
DOCKER_BUILDKIT: 1
# Feature flags
FEATURE_FLAG_MANAGER: true
ENABLE_CHAOS_TESTING: false
ENABLE_PERFORMANCE_TESTING: true
jobs:
# Previous jobs (test, build) remain the same...
security-scan:
name: Security Scan
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.DOCKER_IMAGE }}:sha-${{ github.sha }}
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
- name: Upload Trivy scan results
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results.sarif'
- name: Run Bandit (Python security)
run: |
pip install bandit
bandit -r src/ -f json -o bandit-results.json || true
- name: Run Kubesec
uses: controlplaneio/kubectl-kubesec/v2@v2.11.1
with:
kubeconfig: ${{ secrets.KUBECONFIG }}
path: 'deploy/helm/quantum-infra-zero/templates/*.yaml'
deploy-staging:
name: Deploy to Staging
needs: [build, security-scan]
if: github.ref == 'refs/heads/develop' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
environment: staging
strategy:
matrix:
strategy: ['canary', 'blue-green', 'rolling']
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Kubernetes tools
uses: azure/setup-helm@v3
with:
version: ${{ env.HELM_VERSION }}
- name: Set up kubectl
uses: azure/setup-kubectl@v3
with:
version: ${{ env.KUBE_VERSION }}
- name: Deploy with ${{ matrix.strategy }} strategy
uses: ./.github/actions/deploy
with:
environment: staging
strategy: ${{ matrix.strategy }}
image-tag: ${{ github.sha }}
- name: Run integration tests
run: |
# Run integration tests against staging
pytest tests/integration/test_staging.py -v
- name: Run performance tests
if: env.ENABLE_PERFORMANCE_TESTING == 'true'
uses: k6io/action@v0.3.0
with:
filename: tests/performance/load-test.js
flags: '--vus 10 --duration 30s'
- name: Run chaos tests
if: env.ENABLE_CHAOS_TESTING == 'true'
run: |
# Run chaos engineering tests using Litmus or Gremlin
echo "Running chaos tests..."
deploy-production:
name: Deploy to Production
needs: [deploy-staging, security-scan]
if: github.ref == 'refs/heads/main' || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'production')
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Kubernetes tools
uses: azure/setup-helm@v3
with:
version: ${{ env.HELM_VERSION }}
- name: Set up kubectl
uses: azure/setup-kubectl@v3
with:
version: ${{ env.KUBE_VERSION }}
- name: Deploy with canary strategy
uses: ./.github/actions/deploy
with:
environment: production
strategy: canary
image-tag: ${{ github.sha }}
canary-percentage: 10
- name: Run canary tests
run: |
# Run canary-specific tests
pytest tests/integration/test_canary.py -v
- name: Monitor canary metrics
run: |
# Monitor error rates, latency, etc.
echo "Monitoring canary metrics..."
- name: Promote canary to full deployment
if: success()
run: |
# Scale up canary to 100%
kubectl scale deployment quantum-node-canary -n production --replicas=3
# Update the main service to point to canary
kubectl patch svc quantum-node -n production -p '{"spec":{"selector":{"app.kubernetes.io/instance":"quantum-node-canary"}}}'
- name: Rollback on failure
if: failure()
run: |
# Rollback to previous version
helm rollback quantum-node -n production
monitoring:
name: Monitoring and Alerting
needs: [deploy-staging, deploy-production]
runs-on: ubuntu-latest
steps:
- name: Deploy monitoring stack
run: |
# Deploy Prometheus, Grafana, and Alertmanager
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm upgrade --install monitoring prometheus-community/kube-prometheus-stack \
--create-namespace \
--namespace monitoring \
--values deploy/monitoring/values.yaml
- name: Configure alerts
run: |
# Apply custom alert rules
kubectl apply -f deploy/monitoring/alerts/
- name: Deploy logging stack
run: |
# Deploy EFK or Loki stack
helm upgrade --install loki grafana/loki-stack \
--namespace monitoring \
--set promtail.enabled=true \
--set loki.persistence.enabled=true \
--set loki.persistence.size=10Gi
disaster-recovery:
name: Disaster Recovery
needs: [deploy-production]
runs-on: ubuntu-latest
steps:
- name: Create backup
run: |
# Create etcd backup
kubectl exec -n kube-system etcd-$(kubectl get pods -n kube-system | grep etcd | awk '{print $1}') -- sh -c "ETCDCTL_API=3 etcdctl \
--cert=/etc/kubernetes/pki/etcd/peer.crt \
--key=/etc/kubernetes/pki/etcd/peer.key \
--cacert=/etc/kubernetes/pki/etcd/ca.crt \
snapshot save /backup/etcd-snapshot-$(date +%Y%m%d).db"
# Backup persistent volumes
# ...
- name: Test restore procedure
run: |
# Test restoring from backup
echo "Testing restore procedure..."
# ...
- name: Schedule regular backups
run: |
# Create a CronJob for regular backups
kubectl apply -f deploy/backup/cronjob.yaml
# Post-deployment checks
post-deployment:
name: Post-Deployment Checks
needs: [deploy-production, monitoring, disaster-recovery]
runs-on: ubuntu-latest
steps:
- name: Run smoke tests
run: |
# Run smoke tests against production
pytest tests/smoke/test_production.py -v
- name: Check application health
run: |
# Check all pods are running
kubectl get pods -n production
# Check service endpoints
# ...
- name: Generate deployment report
run: |
# Generate a deployment report
echo "# Deployment Report" > deployment-report.md
echo "- Version: ${{ github.sha }}" >> deployment-report.md
echo "- Status: Success" >> deployment-report.md
echo "- Timestamp: $(date)" >> deployment-report.md
# Add more deployment metrics
# Upload as artifact
mkdir -p ./artifacts
cp deployment-report.md ./artifacts/
- name: Upload deployment report
uses: actions/upload-artifact@v3
with:
name: deployment-report
path: ./artifacts/deployment-report.md
retention-days: 7
# Reusable workflow for deployments
# .github/workflows/deploy.yml
# This can be referenced by other workflows for consistent deployments