forked from stackrox/stackrox
-
Notifications
You must be signed in to change notification settings - Fork 0
632 lines (531 loc) · 20.9 KB
/
build.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
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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
name: Build
on:
workflow_call:
push:
tags:
- '*-nightly-*'
branches:
- master
pull_request:
types:
- opened
- reopened
- synchronize
jobs:
define-job-matrix:
outputs:
matrix: ${{ steps.define-job-matrix.outputs.matrix }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Define the matrix for build jobs
id: define-job-matrix
run: |
source './scripts/ci/lib.sh'
matrix='{ "pre_build_go_binaries": { "name":[], "arch":[] }, "build_and_push_main": { "name":[], "arch":[] }, "push_main_multiarch_manifests": { "name":[] } }'
# The base matrix
matrix="$(jq '.pre_build_go_binaries.name += ["default"]' <<< "$matrix")"
matrix="$(jq '.pre_build_go_binaries.arch += ["amd64", "arm64", "ppc64le", "s390x"]' <<< "$matrix")"
matrix="$(jq '.build_and_push_main.name += ["STACKROX_BRANDING", "RHACS_BRANDING"]' <<< "$matrix")"
matrix="$(jq '.build_and_push_main.arch += ["amd64", "arm64", "ppc64le", "s390x"]' <<< "$matrix")"
matrix="$(jq '.push_main_multiarch_manifests.name += ["STACKROX_BRANDING", "RHACS_BRANDING"]' <<< "$matrix")"
# Conditionally add a prerelease build (binaries built with GOTAGS=release)
if ! is_tagged; then
if ! is_in_PR_context || pr_has_label ci-build-prerelease; then
matrix="$(jq '.pre_build_go_binaries.name += ["prerelease"]' <<< "$matrix")"
matrix="$(jq '.build_and_push_main.name += ["prerelease"]' <<< "$matrix")"
matrix="$(jq '.push_main_multiarch_manifests.name += ["prerelease"]' <<< "$matrix")"
fi
fi
# Conditionally add a -race debug build (binaries built with -race)
if ! is_in_PR_context || pr_has_label ci-build-race-condition-debug; then
matrix="$(jq '.pre_build_go_binaries.name += ["race-condition-debug"]' <<< "$matrix")"
matrix="$(jq '.build_and_push_main.name += ["race-condition-debug"]' <<< "$matrix")"
matrix="$(jq '.push_main_multiarch_manifests.name += ["race-condition-debug"]' <<< "$matrix")"
# Exclude "arm64", "ppc64le", "s390x"
matrix="$(jq '.pre_build_go_binaries.exclude = [{ "name": "race-condition-debug", "arch": "arm64" }]' <<< "$matrix")"
matrix="$(jq '.pre_build_go_binaries.exclude += [{ "name": "race-condition-debug", "arch": "ppc64le" }]' <<< "$matrix")"
matrix="$(jq '.pre_build_go_binaries.exclude += [{ "name": "race-condition-debug", "arch": "s390x" }]' <<< "$matrix")"
matrix="$(jq '.build_and_push_main.exclude = [{ "name": "race-condition-debug", "arch": "arm64" }]' <<< "$matrix")"
matrix="$(jq '.build_and_push_main.exclude += [{ "name": "race-condition-debug", "arch": "ppc64le" }]' <<< "$matrix")"
matrix="$(jq '.build_and_push_main.exclude += [{ "name": "race-condition-debug", "arch": "s390x" }]' <<< "$matrix")"
fi
echo "Job matrix after conditionals:"
jq <<< "$matrix"
condensed="$(jq -c <<< "$matrix")"
echo "matrix=$condensed" >> "$GITHUB_OUTPUT"
pre-build-ui:
strategy:
matrix:
branding: [ RHACS_BRANDING, STACKROX_BRANDING ]
env:
ROX_PRODUCT_BRANDING: ${{ matrix.branding }}
runs-on: ubuntu-latest
container:
image: quay.io/stackrox-io/apollo-ci:stackrox-test-0.3.61
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- uses: ./.github/actions/job-preamble
- uses: ./.github/actions/create-concatenated-ui-monorepo-lock
- uses: ./.github/actions/cache-ui-dependencies
- uses: ./.github/actions/handle-tagged-build
- name: Fetch UI deps
run: make -C ui deps
- name: Build UI
run: make -C ui build
- uses: actions/upload-artifact@v3
with:
name: ui-${{env.ROX_PRODUCT_BRANDING}}-build
path: |
ui/build
ui/monorepo.lock
pre-build-cli:
runs-on: ubuntu-latest
container:
image: quay.io/stackrox-io/apollo-ci:stackrox-test-0.3.61
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- uses: ./.github/actions/job-preamble
- name: Cache Go dependencies
uses: ./.github/actions/cache-go-dependencies
- uses: ./.github/actions/handle-tagged-build
- name: Build CLI
run: make cli
- name: Bundle build to preserve permissions
run: tar -cvzf cli-build.tgz bin
- uses: actions/upload-artifact@v3
with:
name: cli-build
path: cli-build.tgz
pre-build-go-binaries:
strategy:
# Supports three go binary builds:
# default - built with environment defaults (see handle-tagged-build & env.mk)
# prerelease - built with GOTAGS=release
# race-condition-debug - built with -race
matrix: ${{ fromJson(needs.define-job-matrix.outputs.matrix).pre_build_go_binaries }}
needs: define-job-matrix
runs-on: ubuntu-latest
container:
image: quay.io/stackrox-io/apollo-ci:stackrox-test-0.3.61
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- uses: ./.github/actions/job-preamble
- name: Cache Go dependencies
uses: ./.github/actions/cache-go-dependencies
- uses: ./.github/actions/handle-tagged-build
- name: PR labels
uses: joerick/[email protected]
- name: Setup Go build environment for release
if: |
contains(github.event.pull_request.labels.*.name, 'ci-release-build')
||
matrix.name == 'prerelease'
run: echo "GOTAGS=release" >> "$GITHUB_ENV"
- name: Setup Go build environment for -race
if: |
contains(github.event.pull_request.labels.*.name, 'ci-race-tests')
||
matrix.name == 'race-condition-debug'
run: echo "RACE=true" >> "$GITHUB_ENV"
- name: Build Go Binaries
run: |
if [[ "${{ matrix.arch }}" != "amd64" ]]; then
echo "Building non-amd binary"
GOOS=linux GOARCH=${{ matrix.arch }} CGO_ENABLED=0 make build-prep main-build-nodeps
else
echo "Building amd binary"
GOOS=linux GOARCH=${{ matrix.arch }} CGO_ENABLED=1 make build-prep main-build-nodeps
fi
- name: Bundle the build to preserve permissions
run: tar -cvzf go-binaries-build.tgz bin/linux_${{ matrix.arch }}
- uses: actions/upload-artifact@v3
with:
name: go-binaries-build-${{ matrix.arch }}-${{ matrix.name }}
path: go-binaries-build.tgz
pre-build-docs:
runs-on: ubuntu-latest
container:
image: quay.io/stackrox-io/apollo-ci:stackrox-test-0.3.61
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- uses: ./.github/actions/job-preamble
- name: Cache Go dependencies
uses: ./.github/actions/cache-go-dependencies
- uses: ./.github/actions/handle-tagged-build
- name: Resolve mods for protos
run: go mod tidy
- name: Generate the swagger docs
run: |
make swagger-docs
# Workarround to handle https://github.com/actions/cache/issues/753
rm -rf .proto
- uses: actions/upload-artifact@v3
with:
name: docs-build
path: |
image/rhel/docs
build-and-push-main:
runs-on: ubuntu-latest
needs:
- define-job-matrix
- pre-build-ui
- pre-build-cli
- pre-build-go-binaries
- pre-build-docs
strategy:
# Supports four image builds (see Setup build env):
# STACKROX_BRANDING
# RHACS_BRANDING
# prerelease
# race-condition-debug
fail-fast: false
matrix: ${{ fromJson(needs.define-job-matrix.outputs.matrix).build_and_push_main }}
env:
GO_BINARIES_BUILD_ARTIFACT: ""
ROX_PRODUCT_BRANDING: ""
container:
image: quay.io/stackrox-io/apollo-ci:stackrox-test-0.3.61
env:
QUAY_RHACS_ENG_RO_USERNAME: ${{ secrets.QUAY_RHACS_ENG_RO_USERNAME }}
QUAY_RHACS_ENG_RO_PASSWORD: ${{ secrets.QUAY_RHACS_ENG_RO_PASSWORD }}
QUAY_RHACS_ENG_RW_USERNAME: ${{ secrets.QUAY_RHACS_ENG_RW_USERNAME }}
QUAY_RHACS_ENG_RW_PASSWORD: ${{ secrets.QUAY_RHACS_ENG_RW_PASSWORD }}
QUAY_STACKROX_IO_RW_USERNAME: ${{ secrets.QUAY_STACKROX_IO_RW_USERNAME }}
QUAY_STACKROX_IO_RW_PASSWORD: ${{ secrets.QUAY_STACKROX_IO_RW_PASSWORD }}
steps:
- name: Setup build env
run: |
case "${{ matrix.name }}" in
STACKROX_BRANDING)
go_binaries="default"
brand="STACKROX_BRANDING"
;;
RHACS_BRANDING)
go_binaries="default"
brand="RHACS_BRANDING"
;;
race-condition-debug)
go_binaries="race-condition-debug"
brand="RHACS_BRANDING"
;;
prerelease)
go_binaries="prerelease"
brand="RHACS_BRANDING"
;;
*)
echo "Unsupported build: ${{ matrix.name }}"
exit 1
esac
{
echo "GO_BINARIES_BUILD_ARTIFACT=go-binaries-build-${{ matrix.arch }}-${go_binaries}"
echo "ROX_PRODUCT_BRANDING=${brand}"
} >> "$GITHUB_ENV"
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- uses: ./.github/actions/job-preamble
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Checkout submodules
run: |
git submodule update --init
- uses: ./.github/actions/handle-tagged-build
- uses: actions/download-artifact@v3
with:
name: ui-${{ env.ROX_PRODUCT_BRANDING }}-build
path: ui
- uses: actions/download-artifact@v3
with:
name: cli-build
- name: Unpack cli build
run: |
tar xvzf cli-build.tgz
- uses: actions/download-artifact@v3
with:
name: ${{ env.GO_BINARIES_BUILD_ARTIFACT }}
- name: Unpack Go binaries build
run: |
tar xvzf go-binaries-build.tgz
- uses: actions/download-artifact@v3
with:
name: docs-build
path: image/rhel/docs
- uses: ./.github/actions/create-concatenated-ui-monorepo-lock
# needed to restore node_modules for ossls-nostice
- uses: ./.github/actions/cache-ui-dependencies
# explicitly fetch deps just in case cache was not ready
- name: Fetch UI deps
run: make -C ui deps
- name: Generate OSS notice
run: make ossls-notice
- name: Set build tag for prerelease images
if: matrix.name == 'prerelease'
run: echo "BUILD_TAG=$(make --quiet --no-print-directory tag)-prerelease" >> "$GITHUB_ENV"
- name: Set build tag for race condition images
if: matrix.name == 'race-condition-debug'
run: echo "BUILD_TAG=$(make --quiet --no-print-directory tag)-rcd" >> "$GITHUB_ENV"
- name: Build main images
run: |
GOOS=linux GOARCH=${{ matrix.arch }} make docker-build-main-image
- name: Check debugger presence in the main image
run: make check-debugger
- name: Build roxctl image
run: |
GOOS=linux GOARCH=${{ matrix.arch }} make docker-build-roxctl-image
# needed for docs ensure_image.sh initial pull with RHACS_BRANDING
- name: Docker login
# Skip for external contributions.
if: |
github.event_name == 'push' || !github.event.pull_request.head.repo.fork
run: |
docker login -u "${QUAY_RHACS_ENG_RO_USERNAME}" --password-stdin quay.io <<<"${QUAY_RHACS_ENG_RO_PASSWORD}"
- name: Push images
# Skip for external contributions.
if: |
github.event_name == 'push' || !github.event.pull_request.head.repo.fork
run: |
source ./scripts/ci/lib.sh
echo "Will determine context from: ${{ github.event_name }} & ${{ github.ref_name }}"
push_context=""
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref_name }}" == "master" ]]; then
push_context="merge-to-master"
fi
push_main_image_set "$push_context" "${{ env.ROX_PRODUCT_BRANDING }}" "${{ matrix.arch }}"
- name: Push matching collector and scanner images
# Skip for external contributions.
if: |
github.event_name == 'push' || !github.event.pull_request.head.repo.fork
run: |
# Need to free up some space before push_matching_collector_scanner_images() does its pull.
docker system prune --all --force
source ./scripts/ci/lib.sh
push_matching_collector_scanner_images "${{ env.ROX_PRODUCT_BRANDING }}" "${{ matrix.arch }}"
push-main-manifests:
runs-on: ubuntu-latest
needs:
- define-job-matrix
- build-and-push-main
strategy:
# Supports four image builds (see Setup build env):
# STACKROX_BRANDING
# RHACS_BRANDING
# prerelease
# race-condition-debug
fail-fast: false
matrix: ${{ fromJson(needs.define-job-matrix.outputs.matrix).push_main_multiarch_manifests }}
env:
ROX_PRODUCT_BRANDING: ""
container:
image: quay.io/stackrox-io/apollo-ci:stackrox-test-0.3.61
env:
QUAY_RHACS_ENG_RO_USERNAME: ${{ secrets.QUAY_RHACS_ENG_RO_USERNAME }}
QUAY_RHACS_ENG_RO_PASSWORD: ${{ secrets.QUAY_RHACS_ENG_RO_PASSWORD }}
QUAY_RHACS_ENG_RW_USERNAME: ${{ secrets.QUAY_RHACS_ENG_RW_USERNAME }}
QUAY_RHACS_ENG_RW_PASSWORD: ${{ secrets.QUAY_RHACS_ENG_RW_PASSWORD }}
QUAY_STACKROX_IO_RW_USERNAME: ${{ secrets.QUAY_STACKROX_IO_RW_USERNAME }}
QUAY_STACKROX_IO_RW_PASSWORD: ${{ secrets.QUAY_STACKROX_IO_RW_PASSWORD }}
steps:
- name: Setup build env
run: |
case "${{ matrix.name }}" in
STACKROX_BRANDING)
brand="STACKROX_BRANDING"
;;
RHACS_BRANDING)
brand="RHACS_BRANDING"
;;
race-condition-debug)
brand="RHACS_BRANDING"
;;
prerelease)
brand="RHACS_BRANDING"
;;
*)
echo "Unsupported build: ${{ matrix.name }}"
exit 1
esac
{
echo "ROX_PRODUCT_BRANDING=${brand}"
} >> "$GITHUB_ENV"
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- uses: ./.github/actions/job-preamble
- name: Checkout submodules
run: |
git submodule update --init
- uses: ./.github/actions/handle-tagged-build
- name: Set build tag for prerelease images
if: matrix.name == 'prerelease'
run: echo "BUILD_TAG=$(make --quiet --no-print-directory tag)-prerelease" >> "$GITHUB_ENV"
- name: Set build tag for race condition images
if: matrix.name == 'race-condition-debug'
run: echo "BUILD_TAG=$(make --quiet --no-print-directory tag)-rcd" >> "$GITHUB_ENV"
- name: Build and push manifest lists
# Skip for external contributions.
if: |
github.event_name == 'push' || !github.event.pull_request.head.repo.fork
run: |
source ./scripts/ci/lib.sh
echo "Will determine context from: ${{ github.event_name }} & ${{ github.ref_name }}"
push_context=""
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref_name }}" == "master" ]]; then
push_context="merge-to-master"
fi
architectures="amd64,arm64,ppc64le,s390x"
if [[ "${{ matrix.name }}" == "race-condition-debug" ]]; then
architectures="amd64"
fi
push_image_manifest_lists "$push_context" "${{ env.ROX_PRODUCT_BRANDING }}" "$architectures"
- name: Comment on the PR
# Skip for external contributions.
if: |
github.event_name == 'push' || !github.event.pull_request.head.repo.fork
env:
GITHUB_TOKEN: "${{ secrets.ROBOT_ROX_GITHUB_TOKEN }}"
run: |
source ./scripts/ci/lib.sh
add_build_comment_to_pr
build-and-push-operator:
runs-on: ubuntu-latest
container:
image: quay.io/stackrox-io/apollo-ci:stackrox-test-0.3.61
env:
QUAY_RHACS_ENG_RW_USERNAME: ${{ secrets.QUAY_RHACS_ENG_RW_USERNAME }}
QUAY_RHACS_ENG_RW_PASSWORD: ${{ secrets.QUAY_RHACS_ENG_RW_PASSWORD }}
strategy:
matrix:
branding: [ RHACS_BRANDING ]
env:
ROX_PRODUCT_BRANDING: ${{ matrix.branding }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- uses: ./.github/actions/job-preamble
- name: Cache Go dependencies
uses: ./.github/actions/cache-go-dependencies
- uses: ./.github/actions/handle-tagged-build
- name: Resolve mods for protos
run: go mod tidy
- name: PR labels
uses: joerick/[email protected]
- name: Setup Go build environment
if: contains(github.event.pull_request.labels.*.name, 'ci-release-build')
run: echo "GOTAGS=release" >> "$GITHUB_ENV"
- name: Docker login
# Skip for external contributions.
if: |
github.event_name == 'push' || !github.event.pull_request.head.repo.fork
run: |
docker login -u "${QUAY_RHACS_ENG_RW_USERNAME}" --password-stdin quay.io <<<"${QUAY_RHACS_ENG_RW_PASSWORD}"
- name: Build Operator Bundle image
run: |
make -C operator/ bundle bundle-build
- name: Build Operator image
run: make -C operator/ build docker-build
- name: Check that Operator image is runnable
run: docker run --rm "quay.io/rhacs-eng/stackrox-operator:$(make --quiet --no-print-directory -C operator tag)" --help
- name: Push images
# Skip for external contributions.
if: |
github.event_name == 'push' || !github.event.pull_request.head.repo.fork
run: |
make -C operator/ docker-push docker-push-bundle | cat
# Index image can only be built once bundle was pushed
- name: Build index
# Skip for external contributions as the build relies on the previous image to be pushed.
if: |
github.event_name == 'push' || !github.event.pull_request.head.repo.fork
run: |
make -C operator/ index-build
- name: Push index image
# Skip for external contributions.
if: |
github.event_name == 'push' || !github.event.pull_request.head.repo.fork
run: |
make -C operator/ docker-push-index | cat
scan-images-with-roxctl:
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs:
- build-and-push-main
container:
image: quay.io/stackrox-io/apollo-ci:stackrox-test-0.3.61
env:
STACKROX_CI_INSTANCE_API_KEY: ${{ secrets.STACKROX_CI_INSTANCE_API_KEY }}
STACKROX_CI_INSTANCE_CENTRAL_HOST: ${{ secrets.STACKROX_CI_INSTANCE_CENTRAL_HOST }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- uses: ./.github/actions/job-preamble
- name: Checkout submodules
run: |
git submodule update --init
- uses: ./.github/actions/handle-tagged-build
- uses: actions/download-artifact@v3
with:
name: cli-build
- name: Unpack cli build
run: |
tar xvzf cli-build.tgz
- name: Install roxctl
run: |
make cli-install
roxctl version
- name: Scan images
run: |
./release/scripts/scan-images-with-roxctl.sh
slack-on-build-failure:
if: github.event_name == 'push' && failure()
name: Post failure message to Slack
runs-on: ubuntu-latest
needs:
- pre-build-ui
- pre-build-cli
- pre-build-go-binaries
- pre-build-docs
- build-and-push-main
- build-and-push-operator
- scan-images-with-roxctl
permissions:
actions: read
steps:
- name: Slack Workflow Notification
uses: Gamesight/slack-workflow-status@26a36836c887f260477432e4314ec3490a84f309
with:
include_commit_message: true
include_jobs: on-failure
repo_token: ${{secrets.GITHUB_TOKEN}}
slack_webhook_url: ${{secrets.TEST_FAILURES_NOTIFY_WEBHOOK}}