-
Notifications
You must be signed in to change notification settings - Fork 0
500 lines (435 loc) · 17 KB
/
Copy pathci.yml
File metadata and controls
500 lines (435 loc) · 17 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
499
500
name: CI
on:
pull_request:
push:
branches:
- "**"
tags:
- "v*"
permissions:
contents: read
env:
IMAGE_NAME: ghcr.io/${{ github.repository }}
RELAY_IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/stream-ingress
jobs:
test:
name: Go tests
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Run go vet
run: go vet ./...
- name: Run tests
run: go test -covermode=atomic -coverprofile=coverage.out ./...
- name: Summarize coverage
run: |
{
echo "### Go coverage"
echo '```text'
go tool cover -func=coverage.out
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
- name: Upload coverage artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: go-coverage
path: coverage.out
if-no-files-found: error
postgres-integration:
name: PostgreSQL metadata tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:18-alpine@sha256:96d56f7f57c6aacd1fcb908bc83b345ec5f83231ee486dd66a1baadce274db88
env:
POSTGRES_DB: proofline_test
POSTGRES_USER: proofline
POSTGRES_PASSWORD: proofline
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U proofline -d proofline_test"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Check out repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Run PostgreSQL metadata integration tests
env:
SAFE_POSTGRES_TEST_DSN: postgres://proofline:proofline@127.0.0.1:5432/proofline_test?sslmode=disable
run: go test ./internal/postgresdb -count=1
govulncheck:
name: Go vulnerability scan
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Run govulncheck
run: go run golang.org/x/vuln/cmd/govulncheck@v1.3.0 ./...
build-binary:
name: Build Linux binary
runs-on: ubuntu-latest
needs: test
steps:
- name: Check out repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Build binary
run: |
mkdir -p dist
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" -o dist/proofline-server-linux-amd64 ./cmd/api
- name: Smoke-test binary startup
env:
SAFE_MAIN_BIND_ADDRS: 127.0.0.1:18080
SAFE_ADMIN_BIND_ADDRS: 127.0.0.1:18081
SAFE_AUTH_BOOTSTRAP_SECRET: ci-smoke-bootstrap-secret
run: |
set -euo pipefail
data_dir="$RUNNER_TEMP/proofline-binary-smoke-data"
log_file="$RUNNER_TEMP/proofline-binary-smoke.log"
rm -rf "$data_dir"
mkdir -p "$data_dir"
SAFE_DATA_DIR="$data_dir" \
SAFE_DB_PATH="$data_dir/safety.db" \
./dist/proofline-server-linux-amd64 >"$log_file" 2>&1 &
server_pid="$!"
cleanup() {
kill "$server_pid" 2>/dev/null || true
wait "$server_pid" 2>/dev/null || true
}
trap cleanup EXIT
for _ in {1..30}; do
if curl --fail --silent --show-error --output /dev/null "http://127.0.0.1:18080/static/styles.css" &&
curl --fail --silent --show-error --output /dev/null "http://127.0.0.1:18081/admin/static/styles.css"; then
exit 0
fi
if ! kill -0 "$server_pid" 2>/dev/null; then
cat "$log_file"
exit 1
fi
sleep 1
done
cat "$log_file"
exit 1
- name: Upload binary artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: proofline-server-linux-amd64
path: dist/proofline-server-linux-amd64
if-no-files-found: error
attest-binary:
name: Attest Linux binary
runs-on: ubuntu-latest
needs:
- build-binary
- govulncheck
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
permissions:
contents: read
id-token: write
attestations: write
steps:
- name: Download binary artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: proofline-server-linux-amd64
path: dist
- name: Generate binary artifact attestation
uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # v4
with:
subject-path: dist/proofline-server-linux-amd64
upload-release-binary:
name: Upload release binary
runs-on: ubuntu-latest
needs: attest-binary
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
permissions:
contents: write
steps:
- name: Download binary artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: proofline-server-linux-amd64
path: dist
- name: Create release if missing and upload binary
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
TAG_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
prerelease_args=()
if [[ "$TAG_NAME" == *"-rc."* || "$TAG_NAME" == *"-rc" || "$TAG_NAME" == *"-alpha" || "$TAG_NAME" == *"-beta" ]]; then
prerelease_args+=(--prerelease --latest=false)
fi
if ! gh release view "$TAG_NAME" --repo "$REPO" >/dev/null 2>&1; then
gh release create "$TAG_NAME" \
--repo "$REPO" \
--verify-tag \
--title "$TAG_NAME" \
--notes "Automated release shell for $TAG_NAME. Maintainers should review and replace these notes before relying on this release." \
"${prerelease_args[@]}"
fi
gh release upload "$TAG_NAME" dist/proofline-server-linux-amd64 --repo "$REPO"
docker:
name: Build Docker image
runs-on: ubuntu-latest
needs: test
steps:
- name: Check out repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4
- name: Normalize Docker image name
id: image-name
run: |
image_name="$(printf '%s' "$IMAGE_NAME" | tr '[:upper:]' '[:lower:]')"
echo "value=$image_name" >> "$GITHUB_OUTPUT"
- name: Generate Docker metadata
id: meta
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6
with:
images: ${{ steps.image-name.outputs.value }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=sha-
- name: Build Docker image
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7
with:
context: .
file: ./Dockerfile
push: false
load: true
tags: |
proofline-server:ci-smoke
${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Smoke-test Docker image startup
run: |
set -euo pipefail
volume_name="proofline-ci-smoke-${GITHUB_RUN_ID:-local}-${GITHUB_RUN_ATTEMPT:-0}"
docker volume create "$volume_name" >/dev/null
cleanup() {
if [ -n "${container_id:-}" ]; then
docker rm -f "$container_id" >/dev/null 2>&1 || true
fi
docker volume rm "$volume_name" >/dev/null 2>&1 || true
}
trap cleanup EXIT
container_id="$(docker run --detach \
--env SAFE_AUTH_BOOTSTRAP_SECRET=ci-smoke-bootstrap-secret \
--publish 127.0.0.1:18082:8080 \
--publish 127.0.0.1:18083:8081 \
--volume "$volume_name:/var/lib/proofline" \
proofline-server:ci-smoke)"
for _ in {1..30}; do
if curl --fail --silent --show-error --output /dev/null "http://127.0.0.1:18082/static/styles.css" &&
curl --fail --silent --show-error --output /dev/null "http://127.0.0.1:18083/admin/static/styles.css"; then
exit 0
fi
if ! docker container inspect "$container_id" --format '{{.State.Running}}' 2>/dev/null | grep -q true; then
docker logs "$container_id"
exit 1
fi
sleep 1
done
docker logs "$container_id"
exit 1
docker-relay:
name: Build stream-ingress Docker image
runs-on: ubuntu-latest
needs: test
steps:
- name: Check out repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4
- name: Normalize stream-ingress image name
id: image-name
run: |
image_name="$(printf '%s' "$RELAY_IMAGE_NAME" | tr '[:upper:]' '[:lower:]')"
echo "value=$image_name" >> "$GITHUB_OUTPUT"
- name: Generate stream-ingress Docker metadata
id: meta
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6
with:
images: ${{ steps.image-name.outputs.value }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=sha-
- name: Build stream-ingress Docker image
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7
with:
context: .
file: ./Dockerfile.ingress
push: false
load: true
tags: |
proofline-stream-ingress:ci-smoke
${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Smoke-test stream-ingress Docker image startup
run: |
set -euo pipefail
volume_name="proofline-ingress-ci-smoke-${GITHUB_RUN_ID:-local}-${GITHUB_RUN_ATTEMPT:-0}"
docker volume create "$volume_name" >/dev/null
cleanup() {
if [ -n "${container_id:-}" ]; then
docker rm -f "$container_id" >/dev/null 2>&1 || true
fi
docker volume rm "$volume_name" >/dev/null 2>&1 || true
}
trap cleanup EXIT
container_id="$(docker run --detach \
--env SAFE_STREAM_INGRESS_READY=true \
--env SAFE_STREAM_INGRESS_RELAY_ID=ci-relay \
--env SAFE_STREAM_INGRESS_REGION=ci \
--env SAFE_STREAM_INGRESS_CORE_BASE_URL=http://127.0.0.1:8080 \
--env SAFE_STREAM_INGRESS_CORE_SERVICE_AUTH_TOKEN=ci-local-relay-service-token-12345 \
--publish 127.0.0.1:18090:8090 \
--volume "$volume_name:/var/lib/proofline-stream-ingress" \
proofline-stream-ingress:ci-smoke)"
for _ in {1..30}; do
if curl --fail --silent --show-error --output /dev/null "http://127.0.0.1:18090/health/live" &&
curl --fail --silent --show-error --output /dev/null "http://127.0.0.1:18090/health/ready"; then
for path in /admin /admin/api/accounts /v1/incidents /i/viewer-token /metrics; do
status="$(curl --silent --show-error --output /dev/null --write-out "%{http_code}" "http://127.0.0.1:18090${path}")"
if [ "$status" != "404" ]; then
echo "stream-ingress route ${path} returned HTTP ${status}, want 404" >&2
exit 1
fi
done
exit 0
fi
if ! docker container inspect "$container_id" --format '{{.State.Running}}' 2>/dev/null | grep -q true; then
docker logs "$container_id"
exit 1
fi
sleep 1
done
docker logs "$container_id"
exit 1
docker-publish:
name: Publish Docker image
runs-on: ubuntu-latest
needs:
- test
- govulncheck
- docker
- docker-relay
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/v')) }}
permissions:
contents: read
id-token: write
attestations: write
packages: write
steps:
- name: Check out repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4
- name: Normalize Docker image name
id: image-name
run: |
image_name="$(printf '%s' "$IMAGE_NAME" | tr '[:upper:]' '[:lower:]')"
echo "value=$image_name" >> "$GITHUB_OUTPUT"
- name: Generate Docker metadata
id: meta
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6
with:
images: ${{ steps.image-name.outputs.value }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=sha-
- name: Log in to GitHub Container Registry
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and publish Docker image
id: build-and-publish
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate Docker image attestation
uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # v4
with:
subject-name: ${{ steps.image-name.outputs.value }}
subject-digest: ${{ steps.build-and-publish.outputs.digest }}
push-to-registry: true
create-storage-record: false
- name: Normalize stream-ingress image name
id: relay-image-name
run: |
image_name="$(printf '%s' "$RELAY_IMAGE_NAME" | tr '[:upper:]' '[:lower:]')"
echo "value=$image_name" >> "$GITHUB_OUTPUT"
- name: Generate stream-ingress Docker metadata
id: relay-meta
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6
with:
images: ${{ steps.relay-image-name.outputs.value }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=sha-
- name: Build and publish stream-ingress Docker image
id: relay-build-and-publish
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7
with:
context: .
file: ./Dockerfile.ingress
push: true
tags: ${{ steps.relay-meta.outputs.tags }}
labels: ${{ steps.relay-meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate stream-ingress Docker image attestation
uses: actions/attest@59d89421af93a897026c735860bf21b6eb4f7b26 # v4
with:
subject-name: ${{ steps.relay-image-name.outputs.value }}
subject-digest: ${{ steps.relay-build-and-publish.outputs.digest }}
push-to-registry: true
create-storage-record: false