-
Notifications
You must be signed in to change notification settings - Fork 0
432 lines (377 loc) · 14.3 KB
/
ci.yaml
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
name: ci
on:
push:
branches: [master]
release:
types: [created]
pull_request:
branches: [master]
# Declare default permissions as read only.
permissions: read-all
env:
IMAGE_NAME: ghcr.io/${{ github.repository }}
jobs:
build:
name: build
runs-on: ubuntu-22.04
permissions:
packages: write
contents: read
pull-requests: write
outputs:
api-image-tags: ${{ steps.container_meta.outputs.tags }}
api-image-version: ${{ steps.container_meta.outputs.version }}
api-image-digest: ${{ steps.build.outputs.digest }}
api-image-name: ${{ env.IMAGE_NAME }}
steps:
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
with:
fetch-depth: 0
- name: Container meta for api image
id: container_meta
uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 # v4
with:
images: |
${{ env.IMAGE_NAME }}
- name: Container meta for the unit test image
id: container_tests_meta
uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 # v4
with:
images: |
ghcr.io/${{ github.repository }}-tests
- name: Set up QEMU
uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 # v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@885d1462b80bc1c1c7f0b00334ad271f09369c55 # v2
- name: Login to GitHub Container Registry
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2
if: ${{ github.event_name != 'pull_request' }}
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# ran first to avoid pushing failing images when running on master.
- name: Run unit tests
uses: docker/build-push-action@1104d471370f9806843c095c1db02b5a90c5f8b6 # v3
with:
push: false
load: true
tags: ${{ steps.container_tests_meta.outputs.tags }}
labels: ${{ steps.container_tests_meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
target: unit-test
# can't use `load` and `push` at the same time, so differentiate by whether its a PR or not
- name: Build and push api image
uses: docker/build-push-action@1104d471370f9806843c095c1db02b5a90c5f8b6 # v3
id: build
with:
load: ${{ github.event_name == 'pull_request' }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.container_meta.outputs.tags }}
labels: ${{ steps.container_meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@fbd16365eb88e12433951383f5e99bd901fc618f # 0.12.0
with:
image-ref: ${{ fromJson(steps.container_meta.outputs.json).tags[0] }}
severity: "CRITICAL,HIGH"
exit-code: "1"
ignore-unfixed: "true"
- name: Copy unit test coverage reports from container
env:
UNIT_TEST_IMAGE: ${{ fromJson(steps.container_tests_meta.outputs.json).tags[0] }}
run: |
docker create --name=unit-test-container "${UNIT_TEST_IMAGE}"
docker cp unit-test-container:/build/src/Vfps.Tests/coverage ./coverage
- name: Code Coverage Report
uses: irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # tag=v1.3.0
with:
filename: coverage/**/coverage.cobertura.xml
badge: true
fail_below_min: true
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: "60 80"
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@efaaab3fd41a9c3de579aba759d2552635e590fd # v2.8.0
if: ${{ github.event_name == 'pull_request' }}
with:
recreate: true
path: code-coverage-results.md
- name: Save container images as tar archives
if: ${{ github.event_name == 'pull_request' }}
env:
API_IMAGE: ${{ fromJson(steps.container_meta.outputs.json).tags[0] }}
run: |
docker save "$API_IMAGE" -o /tmp/api-image.tar
- name: Upload container images
if: ${{ github.event_name == 'pull_request' }}
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: container-image-artifacts
path: |
/tmp/api-image.tar
test-api-container:
name: test api container
runs-on: ubuntu-22.04
needs:
- build
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@885d1462b80bc1c1c7f0b00334ad271f09369c55 # v2
- name: Download container images
if: ${{ github.event_name == 'pull_request' }}
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: container-image-artifacts
path: /tmp
- name: Load images
if: ${{ github.event_name == 'pull_request' }}
run: |
ls -lar /tmp
docker load --input /tmp/api-image.tar
docker image ls -a
- name: Install grpcurl
working-directory: /tmp
env:
GRPCURL_URL: https://github.com/fullstorydev/grpcurl/releases/download/v1.8.7/grpcurl_1.8.7_linux_x86_64.tar.gz
run: |
curl -LSs "$GRPCURL_URL" | tar xz && \
mv ./grpcurl /usr/local/bin/grpcurl && \
chmod +x /usr/local/bin/grpcurl && \
grpcurl --version
- name: Install ghz
working-directory: /tmp
env:
GHZ_URL: https://github.com/bojand/ghz/releases/download/v0.110.0/ghz-linux-x86_64.tar.gz
run: |
curl -LSs "$GHZ_URL" | tar xz && \
mv ./ghz /usr/local/bin/ghz && \
chmod +x /usr/local/bin/ghz && \
ghz --version
- name: Start compose deployment
env:
VFPS_IMAGE_TAG: ${{ needs.build.outputs.api-image-version }}
run: |
echo "Using VFPS image tag ${VFPS_IMAGE_TAG}"
docker compose -f docker-compose.yaml --profile=test up -d
- name: Wait for the healthz endpoint to be ready
run: |
curl --fail --retry 5 --retry-all-errors --connect-timeout 30 --max-time 60 --retry-delay 10 http://127.0.0.1:8080/healthz
- name: Create a namespace for testing
run: |
grpcurl \
-plaintext \
-import-path src/Vfps/ \
-proto src/Vfps/Protos/vfps/api/v1/namespaces.proto \
-d '{"name": "test", "pseudonymGenerationMethod": "PSEUDONYM_GENERATION_METHOD_SECURE_RANDOM_BASE64URL_ENCODED", "pseudonymLength": 32}' \
127.0.0.1:8081 \
vfps.api.v1.NamespaceService/Create
- name: Create pseudonyms from random inputs
run: |
ghz -n 5000 \
--cpus 1 \
--insecure \
--import-paths src/Vfps/ \
--proto src/Vfps/Protos/vfps/api/v1/pseudonyms.proto \
--call vfps.api.v1.PseudonymService/Create \
-d '{"originalValue": "{{randomString 32}}", "namespace": "test"}' \
127.0.0.1:8081 | tee ghz-output.txt
- name: Enhance ghz output for use as a PR comment
run: |
GHZ_OUTPUT_TXT=$(cat ghz-output.txt)
{
echo -e '---';
echo -e '## ghz run statistics';
echo -e '```console';
echo -e "${GHZ_OUTPUT_TXT}";
echo -e '```'
} >> ghz-output.md
- name: Append sticky comment with ghz output
uses: marocchino/sticky-pull-request-comment@efaaab3fd41a9c3de579aba759d2552635e590fd # v2.8.0
if: ${{ github.event_name == 'pull_request' }}
with:
append: true
path: ghz-output.md
- name: Print compose logs
if: always()
run: |
docker compose --profile=test -f docker-compose.yaml logs
docker compose --profile=test down --volumes --remove-orphans
test-migrations:
name: test migrations
runs-on: ubuntu-22.04
permissions:
contents: read
needs:
- build
steps:
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
- name: Download container images
if: ${{ github.event_name == 'pull_request' }}
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: container-image-artifacts
path: /tmp
- name: Load migrations image
if: ${{ github.event_name == 'pull_request' }}
run: |
docker load --input /tmp/api-image.tar
docker image ls -a
- name: Install .NET
uses: actions/setup-dotnet@a351d9ea84bc76ec7508debf02a39d88f8b6c0c0 # tag=v2
with:
dotnet-version: "7.0.x"
include-prerelease: true
- name: Run migrations tests
env:
VFPS_IMAGE_TAG: ${{ needs.build.outputs.api-image-version }}
run: dotnet test src/Vfps.IntegrationTests --configuration=Release -l "console;verbosity=detailed"
run-iter8-tests:
name: run iter8 tests
runs-on: ubuntu-22.04
if: ${{ github.event_name == 'pull_request' }}
needs:
- build
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
- uses: iter8-tools/iter8@9b867240dcaa77858d2458f52a3845e47ea2c657 # v0.13.17
- name: Create KinD cluster
uses: helm/kind-action@dda0770415bac9fc20092cacbc54aa298604d140 # v1.8.0
with:
cluster_name: kind
- name: Download container images
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: container-image-artifacts
path: /tmp
- name: Load images into KinD
run: |
# vfps api image
kind load image-archive /tmp/api-image.tar
- name: List images in cluster
run: docker exec kind-control-plane crictl images
- name: Install vfps
env:
IMAGE_TAG: ${{ needs.build.outputs.api-image-version }}
run: |
helm repo add miracum https://miracum.github.io/charts
helm repo update
helm install \
--set="image.tag=${IMAGE_TAG}" \
-f tests/iter8/values.yaml \
--wait \
--timeout=15m \
--version=^1.0.0 \
vfps miracum/vfps
- name: Launch iter8 experiment
run: kubectl apply -f tests/iter8/experiment.yaml
- name: Wait for experiment completion
run: iter8 k assert -c completed --timeout 10m
- name: Assert no failures and SLOs are satisfied
run: iter8 k assert -c nofailure,slos
- name: Create iter8 reports
if: always()
run: |
iter8 k report | tee iter8-report.txt
iter8 k report -o html > iter8-report.html
- name: Enhance iter8 report output for use as a PR comment
run: |
ITER8_REPORT_TXT=$(cat iter8-report.txt)
{
echo -e '---';
echo -e '## iter8 report';
echo -e '```console';
echo -e "${ITER8_REPORT_TXT}";
echo -e '```'
} >> iter8-output.md
- name: Append sticky comment with iter8 report
uses: marocchino/sticky-pull-request-comment@efaaab3fd41a9c3de579aba759d2552635e590fd # v2.8.0
if: ${{ github.event_name == 'pull_request' }}
with:
append: true
path: iter8-output.md
- name: Upload report
if: always()
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: iter8-report.html
path: |
iter8-report.html
- name: Print cluster and iter8 logs
if: always()
run: |
kubectl cluster-info dump -o yaml | tee kind-cluster-dump.txt
iter8 k log -l trace
- name: Upload cluster dump
if: always()
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: kind-cluster-dump.txt
path: |
kind-cluster-dump.txt
sign-images:
name: sign images
runs-on: ubuntu-22.04
if: ${{ github.event_name != 'pull_request' }}
needs:
- build
- test-migrations
- test-api-container
permissions:
contents: read
id-token: write
packages: write
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install Cosign
uses: sigstore/cosign-installer@c85d0e205a72a294fe064f618a87dbac13084086 # v2.8.1
- name: Sign vfps image
env:
COSIGN_EXPERIMENTAL: "true"
IMAGES: ${{ needs.build.outputs.api-image-tags }}
run: |
while read -r image; do
echo "Signing '$image' using keyless approach"
cosign sign "$image"
done <<< "$IMAGES"
container-provenance:
if: ${{ startsWith(github.ref, 'refs/tags/') }}
needs:
- build
- test-migrations
- test-api-container
permissions:
actions: read # for detecting the Github Actions environment.
id-token: write
packages: write # for uploading attestations.
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
with:
image: ${{ needs.build.outputs.api-image-name }}
digest: ${{ needs.build.outputs.api-image-digest }}
registry-username: ${{ github.actor }}
# TODO(https://github.com/slsa-framework/slsa-github-generator/issues/492): Remove after GA release.
compile-generator: true
secrets:
registry-password: ${{ secrets.GITHUB_TOKEN }}