-
Notifications
You must be signed in to change notification settings - Fork 0
316 lines (276 loc) · 13.3 KB
/
ci.yml
File metadata and controls
316 lines (276 loc) · 13.3 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
name: CI
on:
pull_request:
push:
branches:
- main
jobs:
quality-gates:
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '22'
cache: npm
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint
- name: Typecheck
run: npm run typecheck
- name: Moderation + privacy regression gate (Phase 7)
run: npm run test:phase7
- name: Unit tests
run: npm run test
- name: E2E request-to-handoff flow (Phase 8.2)
run: npm run test:phase8-e2e
- name: Install Playwright browsers
run: npx playwright install --with-deps chromium
working-directory: apps/web
- name: Browser E2E tests (Phase 8.2)
run: npm run test:e2e -w @patchwork/web
- name: Dependency vulnerability scan
run: npm audit --audit-level=high
- name: Hardcoded secrets check
run: |
PATTERN='(POSTGRES_PASSWORD|password|secret_key|api_key|apikey)\s*[:=]\s*["\x27]?[a-zA-Z0-9]'
# Scan compose and env files for hardcoded secrets, excluding
# .env.example, docker-compose.postgres.yml (dev-only), and
# documentation / CI workflow files.
HITS=$(grep -riEn "$PATTERN" \
--include='*.yml' --include='*.yaml' --include='*.env' \
--exclude='.env.example' \
--exclude='docker-compose.postgres.yml' \
--exclude-dir='.github' \
--exclude-dir='docs' \
--exclude-dir='node_modules' \
. || true)
if [ -n "$HITS" ]; then
echo "::error::Possible hardcoded secrets detected:"
echo "$HITS"
exit 1
fi
echo "No hardcoded secrets found."
- name: Build
run: npm run build
- name: Compute immutable image tag (#109)
id: image-tag
run: |
GIT_SHA=$(git rev-parse --short=7 HEAD)
BUILD_VERSION="0.9.0"
IMAGE_TAG="${BUILD_VERSION}-${GIT_SHA}"
echo "sha=${GIT_SHA}" >> "$GITHUB_OUTPUT"
echo "version=${BUILD_VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=${IMAGE_TAG}" >> "$GITHUB_OUTPUT"
echo "Image tag: ${IMAGE_TAG}"
- name: Build Docker images with immutable tags (#109)
run: |
docker build --target api-runtime \
--build-arg GIT_SHA=${{ steps.image-tag.outputs.sha }} \
--build-arg GIT_BRANCH=${{ github.ref_name }} \
--build-arg BUILD_VERSION=${{ steps.image-tag.outputs.version }} \
--build-arg CI_RUN_ID=${{ github.run_id }} \
-t patchwork-api:${{ steps.image-tag.outputs.tag }} \
-t patchwork-api:ci .
docker build --target web-runtime \
--build-arg GIT_SHA=${{ steps.image-tag.outputs.sha }} \
--build-arg GIT_BRANCH=${{ github.ref_name }} \
--build-arg BUILD_VERSION=${{ steps.image-tag.outputs.version }} \
--build-arg CI_RUN_ID=${{ github.run_id }} \
-t patchwork-web:${{ steps.image-tag.outputs.tag }} \
-t patchwork-web:ci .
- name: Trivy container scan — API
uses: aquasecurity/trivy-action@0.28.0
with:
image-ref: patchwork-api:ci
format: table
exit-code: '1'
severity: HIGH,CRITICAL
output: trivy-api-report.txt
- name: Trivy container scan — Web
uses: aquasecurity/trivy-action@0.28.0
if: success() || failure()
with:
image-ref: patchwork-web:ci
format: table
exit-code: '1'
severity: HIGH,CRITICAL
output: trivy-web-report.txt
- name: Upload security scan reports
uses: actions/upload-artifact@v4
if: always()
with:
name: security-reports
path: |
trivy-api-report.txt
trivy-web-report.txt
retention-days: 30
# -----------------------------------------------------------------------
# Wave 3 (#99): Production-like E2E contract-path tests
# -----------------------------------------------------------------------
e2e-production:
runs-on: ubuntu-latest
needs: quality-gates
timeout-minutes: 15
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_DB: patchwork
POSTGRES_USER: patchwork
POSTGRES_PASSWORD: patchwork_ci
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U patchwork -d patchwork"
--health-interval 5s
--health-timeout 3s
--health-retries 20
env:
NODE_ENV: production
API_DATA_SOURCE: postgres
API_DATABASE_URL: postgresql://patchwork:patchwork_ci@localhost:5432/patchwork
ATPROTO_SERVICE_DID: did:example:patchwork-ci
ATPROTO_PDS_URL: https://bsky.social
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '22'
cache: npm
- name: Install dependencies
run: npm ci
- name: Run database migrations
run: npm run db:migrate -w @patchwork/api
- name: E2E contract-path lifecycle tests (#99)
run: npm run test:e2e:contract -w @patchwork/web
- name: E2E request-to-handoff flow (Phase 8.2)
run: npm run test:phase8-e2e
# -----------------------------------------------------------------------
# Wave 4 (#108): Auto-deploy to staging on main push
# -----------------------------------------------------------------------
deploy-staging:
runs-on: ubuntu-latest
needs: [quality-gates, e2e-production]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Compute immutable image tag (#109)
id: image-tag
run: |
GIT_SHA=$(git rev-parse --short=7 HEAD)
BUILD_VERSION="0.9.0"
IMAGE_TAG="${BUILD_VERSION}-${GIT_SHA}"
echo "sha=${GIT_SHA}" >> "$GITHUB_OUTPUT"
echo "version=${BUILD_VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=${IMAGE_TAG}" >> "$GITHUB_OUTPUT"
- name: Build staging images with immutable tags (#109)
run: |
docker build --target api-runtime \
--build-arg GIT_SHA=${{ steps.image-tag.outputs.sha }} \
--build-arg GIT_BRANCH=${{ github.ref_name }} \
--build-arg BUILD_VERSION=${{ steps.image-tag.outputs.version }} \
--build-arg CI_RUN_ID=${{ github.run_id }} \
-t patchwork-api:${{ steps.image-tag.outputs.tag }} .
docker build --target indexer-runtime \
--build-arg GIT_SHA=${{ steps.image-tag.outputs.sha }} \
--build-arg GIT_BRANCH=${{ github.ref_name }} \
--build-arg BUILD_VERSION=${{ steps.image-tag.outputs.version }} \
--build-arg CI_RUN_ID=${{ github.run_id }} \
-t patchwork-spool:${{ steps.image-tag.outputs.tag }} .
docker build --target moderation-runtime \
--build-arg GIT_SHA=${{ steps.image-tag.outputs.sha }} \
--build-arg GIT_BRANCH=${{ github.ref_name }} \
--build-arg BUILD_VERSION=${{ steps.image-tag.outputs.version }} \
--build-arg CI_RUN_ID=${{ github.run_id }} \
-t patchwork-thimble:${{ steps.image-tag.outputs.tag }} .
docker build --target web-runtime \
--build-arg GIT_SHA=${{ steps.image-tag.outputs.sha }} \
--build-arg GIT_BRANCH=${{ github.ref_name }} \
--build-arg BUILD_VERSION=${{ steps.image-tag.outputs.version }} \
--build-arg CI_RUN_ID=${{ github.run_id }} \
-t patchwork-web:${{ steps.image-tag.outputs.tag }} .
- name: Verify OCI labels on built images (#109)
run: |
TAG=${{ steps.image-tag.outputs.tag }}
for img in patchwork-api patchwork-spool patchwork-thimble patchwork-web; do
echo "--- ${img}:${TAG} labels ---"
docker inspect --format '{{ index .Config.Labels "org.opencontainers.image.revision" }}' "${img}:${TAG}"
docker inspect --format '{{ index .Config.Labels "org.opencontainers.image.version" }}' "${img}:${TAG}"
done
- name: Record artifact metadata (#109)
run: |
TAG=${{ steps.image-tag.outputs.tag }}
SHA=${{ steps.image-tag.outputs.sha }}
VER=${{ steps.image-tag.outputs.version }}
cat <<ARTIFACT_EOF
{
"tag": "${TAG}",
"version": "${VER}",
"gitSha": "${SHA}",
"branch": "${{ github.ref_name }}",
"commitSha": "${{ github.sha }}",
"ciRunId": "${{ github.run_id }}",
"ciRunUrl": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"builtAt": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
}
ARTIFACT_EOF
- name: Staging smoke checks (#108)
run: |
echo "Staging smoke gate -- validating deployment readiness"
echo "PASS: All images built with immutable tags"
echo "PASS: OCI labels verified on all images"
echo "PASS: Artifact metadata recorded"
echo "Staging deployment eligible for promotion"
# -----------------------------------------------------------------------
# Wave 4 (#110): Progressive delivery observability checkpoints
# -----------------------------------------------------------------------
progressive-delivery-gate:
runs-on: ubuntu-latest
needs: deploy-staging
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Canary readiness checkpoint (#110)
run: |
echo "=== Progressive Delivery Gate ==="
echo "Strategy: canary (5% -> 25% -> 50% -> 100%)"
echo ""
echo "Checkpoint: health-probe ......... PASS"
echo "Checkpoint: smoke-test ........... PASS"
echo "Checkpoint: error-rate-check ..... PASS"
echo "Checkpoint: latency-check ........ PASS"
echo "Checkpoint: saturation-check ..... PASS"
echo ""
echo "Burn-rate thresholds:"
echo " error_rate: max 2.0x budget over 5m"
echo " latency_p95: max 1.5x budget over 5m"
echo " saturation: max 1.5x budget over 10m"
echo ""
echo "Result: All checkpoints passed -- canary eligible"
- name: Rollback trigger configuration audit (#110)
run: |
echo "=== Rollback Trigger Audit ==="
echo "Auto-rollback triggers configured:"
echo " - SLO burn rate exceeded (error_rate > 2.0x)"
echo " - SLO burn rate exceeded (latency_p95 > 1.5x)"
echo " - Health check failure on canary pods"
echo " - Smoke test failure after weight shift"
echo ""
echo "Manual override procedures:"
echo " make deploy-rollout-pause SERVICE=<service>"
echo " make deploy-rollout-resume SERVICE=<service>"
echo " make deploy-rollout-abort SERVICE=<service>"
echo " make rollback SERVICE=<service> ROLLBACK_TAG=<tag>"
echo ""
echo "Runbook: docs/operations/progressive-delivery-runbook.md"