forked from inspektor-gadget/inspektor-gadget
-
Notifications
You must be signed in to change notification settings - Fork 0
2132 lines (2049 loc) · 86 KB
/
inspektor-gadget.yml
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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: Inspektor Gadget CI
env:
REGISTRY: ghcr.io
CONTAINER_REPO: ${{ github.repository }}
GO_VERSION: 1.22.0
# controller-gen with go >1.21 panics, but we can't update controller-gen itself
GO_VERSION_DOC_CHECK: 1.21.3
AZURE_AKS_CLUSTER_PREFIX: ig-ci-aks-
DEFAULT_DNSTESTER_IMAGE: ghcr.io/inspektor-gadget/dnstester:latest
DEFAULT_EBPF_BUILDER_IMAGE: ghcr.io/inspektor-gadget/ebpf-builder:latest
concurrency:
group: ${{ github.ref }}
# We do not want to cancel job in progress on main to be sure to catch new
# regression as soon as they are introduced.
cancel-in-progress: ${{ github.ref_name != 'main' }}
on:
pull_request:
push:
branches:
- main
- 'release-*'
- 'citest/**'
tags:
- 'v*'
permissions: read-all
# Jobs are given a level in a comment.
# Jobs of the same level run in parallel.
# Jobs of level N depend of, at least, one job on level N - 1 expect job whom
# level is 0.
jobs:
documentation-checks:
name: Documentation checks
# level: 0
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION_DOC_CHECK }}
cache: true
id: go
- name: Check if generated files are updated
run: |
make manifests generate generate-documentation
git diff --exit-code HEAD --
- name: Check that there are not broken links
uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
use-quiet-mode: 'yes'
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
docs:
- 'docs/**'
- name: Setup Hugo
if: steps.filter.outputs.docs == 'true'
uses: peaceiris/actions-hugo@v3
with:
hugo-version: '0.89.0'
extended: true
- name: Check website build
if: steps.filter.outputs.docs == 'true'
run: |
cd $RUNNER_TEMP
git clone https://github.com/inspektor-gadget/website/
cd website
mkdir -p external-docs/
ln -s $GITHUB_WORKSPACE external-docs/inspektor-gadget.git_mainlatest
make
actionlint:
name: Lint GitHub Actions workflows
# level: 0
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check workflow files
shell: bash
run: |
# As advised from:
# https://github.com/rhysd/actionlint/blob/main/docs/usage.md#use-actionlint-on-github-actions
curl -o download-actionlint.bash https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash
bash download-actionlint.bash
# For now, we do not use shellcheck, we may activate it later.
./actionlint -color -shellcheck=
lint:
name: Lint
# level: 0
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
id: go
- name: Lint
uses: golangci/[email protected]
with:
# This version number must be kept in sync with Makefile lint one.
version: v1.54.2
working-directory: /home/runner/work/inspektor-gadget/inspektor-gadget
# Workaround to display the output:
# https://github.com/golangci/golangci-lint-action/issues/119#issuecomment-981090648
args: "--out-${NO_FUTURE}format colored-line-number"
skip-pkg-cache: true
semgrep:
name: semgrep
runs-on: ubuntu-latest
container:
image: returntocorp/semgrep
# Skip any PR created by dependabot to avoid permission issues:
if: (github.actor != 'dependabot[bot]')
steps:
# Fetch project source with GitHub Actions Checkout.
- uses: actions/checkout@v4
# Run the "semgrep ci" command on the command line of the docker image.
- run: cd $GITHUB_WORKSPACE && semgrep ci --config $GITHUB_WORKSPACE/.semgrep_rules.yaml
ebpf-objects-checks:
name: eBPF Object checks
# level: 1
needs: build-helper-images
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check ebpf formatting
run: |
sudo apt-get update && sudo apt-get install -y clang-format
make clang-format
changes="$(git status --porcelain)"
if [ -n "$changes" ] ; then
>&2 echo "Use 'make clang-format' to fix the style in the eBPF code:"
>&2 git diff
exit 1
fi
- name: Detect changes for ebpf objects
run: |
make EBPF_BUILDER=${{ needs.build-helper-images.outputs.ebpf_builder_image }} ebpf-objects
changes="$(git status --porcelain)"
if [ -n "$changes" ] ; then
>&2 echo "$changes"
exit 1
fi
- name: Check that testdata is updated
run: |
make testdata
changes="$(git status --porcelain)"
if [ -n "$changes" ] ; then
>&2 echo "$changes"
exit 1
fi
pr-dependencies-checks:
name: PR dependencies checks
# level: 0
# We need to run this action only on PR.
# Otherwise, for other cases like pushing to main, it will fail because it
# searches for base_ref and head_ref which only exists in PR context.
if: ${{ github.event.pull_request }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check if added dependencies do not contain CVE.
uses: actions/dependency-review-action@v4
build-clients:
name: clients
# level: 0
runs-on: ubuntu-latest
permissions:
security-events: write
strategy:
fail-fast: false
matrix:
client: [kubectl-gadget, gadgetctl]
os: [linux, darwin, windows]
arch: [amd64, arm64]
exclude:
- os: windows
arch: arm64
steps:
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
id: go
- name: Set container repository and determine image tag
id: set-repo-determine-image-tag
uses: ./.github/actions/set-container-repo-and-determine-image-tag
with:
registry: ${{ env.REGISTRY }}
container-image: ${{ env.CONTAINER_REPO }}
- uses: github/codeql-action/init@v3
with:
languages: go
- name: Build ${{ matrix.client }}-${{ matrix.os }}-${{ matrix.arch }}
run: |
git checkout
# Prevent releases with -dirty suffix due to forgotten entries in
# .gitignore.
changes="$(git status --porcelain)"
if [ -n "$changes" ] ; then
echo "$changes"
exit 1
fi
client=${{ matrix.client }}-${{ matrix.os }}-${{ matrix.arch }}
CONTAINER_REPO=${{ steps.set-repo-determine-image-tag.outputs.container-repo }} \
IMAGE_TAG=${{ steps.set-repo-determine-image-tag.outputs.image-tag }} \
make $client
# We need to append .exe to windows binaries...
dot_exe=$(test ${{ matrix.os }} = 'windows' && echo '.exe' || echo '')
# Prepare assets for release and actions artifacts
platform='${{ matrix.os }}-${{ matrix.arch }}'
mkdir $platform
cp "${client}${dot_exe}" "${platform}/${{ matrix.client }}${dot_exe}"
cp LICENSE $platform/
tar --sort=name --owner=root:0 --group=root:0 \
-czf ${client}.tar.gz -C $platform \
${{ matrix.client }}${dot_exe} LICENSE
rm -rf $platform
- name: CWE checks for ${{ matrix.client }}-${{ matrix.os }}-${{ matrix.arch }}
uses: github/codeql-action/analyze@v3
with:
category: ${{ matrix.client }}-${{ matrix.os }}-${{ matrix.arch }}
- name: Add ${{ matrix.client }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz as artifact.
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.client }}-${{ matrix.os }}-${{ matrix.arch }}-tar-gz
path: /home/runner/work/inspektor-gadget/inspektor-gadget/${{ matrix.client }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz
btfgen:
name: btfgen
# level: 0
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform: [amd64, arm64]
steps:
- uses: actions/checkout@v4
- name: Get btfhub-archive last commmit
id: get-btfhub-head
run: |
echo "head=$(git ls-remote https://github.com/aquasecurity/btfhub-archive/ HEAD | cut -f1)" >> $GITHUB_OUTPUT
shell: bash
- name: Cache BTFGen
id: cache-btfgen
uses: actions/[email protected]
with:
path: pkg/btfgen/btfs
# key is composed by
# - arch: amd64 or arm64
# - latest commit of btfhub
# - hash of all bpf objects
key: btfgen-${{ matrix.platform }}-${{ steps.get-btfhub-head.outputs.head }}-${{ hashFiles('pkg/**/*.o') }}
- name: BTFGen
if: ${{ steps.cache-btfgen.outputs.cache-hit != 'true' }}
run: |
./tools/getbtfhub.sh
./tools/getbpftool.sh
make btfgen BPFTOOL=/tmp/bpftool \
ARCH=${{ matrix.platform }} BTFHUB_ARCHIVE=$HOME/btfhub-archive/ -j$(nproc)
build-ig:
name: ig
# level: 1
needs:
- btfgen
- build-helper-images
runs-on: ubuntu-latest
permissions:
security-events: write
strategy:
fail-fast: false
matrix:
platform: [amd64, arm64]
steps:
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
id: go
- name: Get btfhub-archive last commmit
id: get-btfhub-head
run: |
echo "head=$(git ls-remote https://github.com/aquasecurity/btfhub-archive/ HEAD | cut -f1)" >> $GITHUB_OUTPUT
shell: bash
- name: Cache BTFGen
id: cache-btfgen
uses: actions/[email protected]
with:
path: pkg/btfgen/btfs
# key is composed by
# - arch: amd64 or arm64
# - latest commit of btfhub
# - hash of all bpf objects
key: btfgen-${{ matrix.platform }}-${{ steps.get-btfhub-head.outputs.head }}-${{ hashFiles('pkg/**/*.o') }}
- name: Build ig-linux-${{ matrix.platform }}
run: |
if [ "${{ matrix.platform }}" = 'arm64' ]; then
sudo apt-get update
sudo apt-get install qemu-user-static
fi
make EBPF_BUILDER=${{ needs.build-helper-images.outputs.ebpf_builder_image }} ig-linux-${{ matrix.platform }}
# Prepare assets for release and actions artifacts
mkdir ${{ matrix.platform }}
cp ig-linux-${{ matrix.platform }} ${{ matrix.platform }}/ig
cp LICENSE ${{ matrix.platform }}/
tar --sort=name --owner=root:0 --group=root:0 \
-czf ig-linux-${{ matrix.platform }}.tar.gz -C ${{ matrix.platform }} \
ig LICENSE
rm -rf ${{ matrix.platform }}
- name: Add ig-linux-${{ matrix.platform }}.tar.gz as artifact.
uses: actions/upload-artifact@v3
with:
name: ig-linux-${{ matrix.platform }}-tar-gz
path: /home/runner/work/inspektor-gadget/inspektor-gadget/ig-linux-${{ matrix.platform }}.tar.gz
build-ig-cwe:
name: Check ig CWE
# level: 0
runs-on: ubuntu-latest
permissions:
security-events: write
strategy:
fail-fast: false
matrix:
platform: [amd64, arm64]
steps:
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
id: go
- uses: github/codeql-action/init@v3
with:
languages: go
- name: Build ig-linux-${{ matrix.platform }} for CWE checks
run: |
# We need to build ig using go build otherwise CodeQL will not detect
# that the binary was built and will try to autobuild it which adds
# extra time in the CI pipeline.
CGO_ENABLED=0 GOARCH=${{ matrix.platform }} go build \
-ldflags "-extldflags '-static'" \
github.com/inspektor-gadget/inspektor-gadget/cmd/ig
- name: CWE checks for ig-linux-${{ matrix.platform }}
uses: github/codeql-action/analyze@v3
with:
category: ig-linux-${{ matrix.platform }}
build-gadget-container-deps:
# We only build this dependencies to check if they do not contain CWE.
name: Build gadget-container-deps
# level: 0
runs-on: ubuntu-latest
permissions:
security-events: write
steps:
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
id: go
- uses: github/codeql-action/init@v3
with:
languages: go
- name: Build gadget-container-deps
run: |
make -C gadget-container
- name: CWE checks for gadget-container-deps
uses: github/codeql-action/analyze@v3
with:
category: gadget-container-deps
build-gadget-container-images:
name: gadget img
# level: 1
needs: btfgen
runs-on: ubuntu-latest
permissions:
# allow publishing container image
# in case of public fork repo/packages permissions will always be read
contents: read
packages: write
outputs:
digest-amd64: ${{ steps.published-gadget-container-images.outputs.amd64 }}
digest-arm64: ${{ steps.published-gadget-container-images.outputs.arm64 }}
sbom-digest-amd64: ${{ steps.gadget-container-images-attach-sbom.outputs.sbom-amd64 }}
sbom-digest-arm64: ${{ steps.gadget-container-images-attach-sbom.outputs.sbom-arm64 }}
strategy:
fail-fast: false
matrix:
os: [ linux ]
# For the moment, we only support these two platforms.
platform: [ arm64, amd64 ]
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/[email protected]
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-${{ matrix.platform }}-${{ hashFiles('Dockerfiles/gadget.Dockerfile') }}
restore-keys: |
${{ runner.os }}-docker-${{ matrix.platform }}-
- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set container repository and determine image tag
id: set-repo-determine-image-tag
uses: ./.github/actions/set-container-repo-and-determine-image-tag
with:
registry: ${{ env.REGISTRY }}
container-image: ${{ env.CONTAINER_REPO }}
- name: Get btfhub-archive last commmit
id: get-btfhub-head
run: |
echo "head=$(git ls-remote https://github.com/aquasecurity/btfhub-archive/ HEAD | cut -f1)" >> $GITHUB_OUTPUT
shell: bash
- name: Cache BTFGen
id: cache-btfgen
uses: actions/[email protected]
with:
path: pkg/btfgen/btfs
# key is composed by
# - arch: amd64 or arm64
# - latest commit of btfhub
# - hash of all bpf objects
key: btfgen-${{ matrix.platform }}-${{ steps.get-btfhub-head.outputs.head }}-${{ hashFiles('pkg/**/*.o') }}
# we are using cache-to mode=min (default) implying that only final image layers are cached, using cache
# mode=max results in builder image layer of ~7GB because of btfhub files in a layer, which is too
# large (gloabal limit 10GB) to work with GH caches. (TODO: if we can work with mode=max in future?)
- name: Build gadget ${{ matrix.os }} ${{ matrix.platform }} container image as artifacts
uses: docker/build-push-action@v5
with:
context: /home/runner/work/inspektor-gadget/inspektor-gadget/
file: /home/runner/work/inspektor-gadget/inspektor-gadget/Dockerfiles/gadget.Dockerfile
outputs: type=docker,dest=/tmp/gadget-container-image-${{ matrix.os }}-${{ matrix.platform }}.tar
tags: ${{ steps.set-repo-determine-image-tag.outputs.container-repo }}:${{ steps.set-repo-determine-image-tag.outputs.image-tag }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
platforms: ${{ matrix.os }}/${{ matrix.platform }}
build-args: |
VERSION=${{ steps.set-repo-determine-image-tag.outputs.image-tag }}
- name: Publish gadget ${{ matrix.os }} ${{ matrix.platform }} container image as artifacts
uses: actions/upload-artifact@v3
with:
name: gadget-container-image-${{ matrix.os }}-${{ matrix.platform }}.tar
path: /tmp/gadget-container-image-${{ matrix.os }}-${{ matrix.platform }}.tar
retention-days: 1
- name: Generate SBOM for gadget ${{ matrix.os }} ${{ matrix.platform }} image
uses: docker/build-push-action@v5
with:
context: /home/runner/work/inspektor-gadget/inspektor-gadget/
file: /home/runner/work/inspektor-gadget/inspektor-gadget/Dockerfiles/gadget.Dockerfile
outputs: type=local,dest=/tmp/gadget-container-image-${{ matrix.os }}-${{ matrix.platform }}
tags: ${{ steps.set-repo-determine-image-tag.outputs.container-repo }}:${{ steps.set-repo-determine-image-tag.outputs.image-tag }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
platforms: ${{ matrix.os }}/${{ matrix.platform }}
# The following permits to generate SBOM:
# https://github.com/moby/buildkit/issues/2773#issue-1194754388
build-args: BUILDKIT_SYNTAX=crazymax/dockerfile:sbom
# build time will not be increased with this workflow because of internal cache
# buildx is used here since it allows push-by-digest to avoid platform specific tags
- name: Publish gadget ${{ matrix.os }} ${{ matrix.platform }} container image to registry
id: publish-gadget-container-images
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v5
with:
context: /home/runner/work/inspektor-gadget/inspektor-gadget/
file: /home/runner/work/inspektor-gadget/inspektor-gadget/Dockerfiles/gadget.Dockerfile
outputs: type=registry,name=${{ steps.set-repo-determine-image-tag.outputs.container-repo }},push=true,push-by-digest=true
cache-from: type=local,src=/tmp/.buildx-cache-new
platforms: ${{ matrix.os }}/${{ matrix.platform }}
build-args: |
VERSION=${{ steps.set-repo-determine-image-tag.outputs.image-tag }}
- name: Setup oras
if: github.event_name != 'pull_request'
uses: oras-project/setup-oras@v1
- name: Attach SBOM to container image
if: github.event_name != 'pull_request'
id: gadget-container-images-attach-sbom
run: |
# We need to get the image digest from the manifest.
# Otherwise, we will attach the SBOM to the manifest and the SBOM will
# be lost when using imagetools as this command creates a new manifest
# and attaches only the images, not the existing manifests.
# This way, we are sure the new manifest will point to the images which
# have SBOM attached.
manifest=$(oras manifest fetch ${{ steps.set-repo-determine-image-tag.outputs.container-repo }}@${{ steps.publish-gadget-container-images.outputs.digest }})
image_digest=$(echo $manifest | jq -e '[.manifests[] | select ( .platform.architecture == "${{ matrix.platform }}" and .platform.os == "${{ matrix.os }}" )] | if length != 1 then empty else .[0].digest end')
image_digest=$(echo "$image_digest" | tr -d '"')
sbom_digest=$(oras attach ${{ steps.set-repo-determine-image-tag.outputs.container-repo }}@${image_digest} /tmp/gadget-container-image-${{ matrix.os }}-${{ matrix.platform }}/sbom_cyclonedx.json --disable-path-validation --artifact-type example/sbom | grep 'Digest:' | awk '{ print $2 }')
echo "sbom-${{ matrix.platform }}=${sbom_digest}" >> $GITHUB_OUTPUT
- name: Save gadget ${{ matrix.os }} ${{ matrix.platform }} container image digest output
id: published-gadget-container-images
if: github.event_name != 'pull_request'
run: |
echo "${{ matrix.platform }}=${{ steps.publish-gadget-container-images.outputs.digest }}" >> $GITHUB_OUTPUT
# old cache entries aren’t deleted, so the cache size keeps growing
# remove old cache and move new cache to cache path to workaround the issue
# https://github.com/docker/build-push-action/issues/252
- name: Move gadget ${{ matrix.os }} ${{ matrix.platform }} container image cache to correct location
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
build-ig-container-images:
name: ig img
# level: 1
needs:
- btfgen
- build-helper-images
runs-on: ubuntu-latest
permissions:
# allow publishing container image
# in case of public fork repo/packages permissions will always be read
contents: read
packages: write
outputs:
digest-amd64: ${{ steps.published-ig-container-images.outputs.amd64 }}
digest-arm64: ${{ steps.published-ig-container-images.outputs.arm64 }}
sbom-digest-amd64: ${{ steps.ig-container-images-attach-sbom.outputs.sbom-amd64 }}
sbom-digest-arm64: ${{ steps.ig-container-images-attach-sbom.outputs.sbom-arm64 }}
strategy:
fail-fast: false
matrix:
os: [ linux ]
# For the moment, we only support these two platforms.
platform: [ arm64, amd64 ]
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/[email protected]
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-${{ matrix.platform }}-${{ hashFiles('Dockerfiles/ig.Dockerfile') }}
restore-keys: |
${{ runner.os }}-docker-${{ matrix.platform }}-
- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set container repository and determine image tag
id: set-repo-determine-image-tag
uses: ./.github/actions/set-container-repo-and-determine-image-tag
with:
registry: ${{ env.REGISTRY }}
container-image: ${{ github.repository_owner }}/ig
- name: Get btfhub-archive last commmit
id: get-btfhub-head
run: |
echo "head=$(git ls-remote https://github.com/aquasecurity/btfhub-archive/ HEAD | cut -f1)" >> $GITHUB_OUTPUT
shell: bash
- name: Cache BTFGen
id: cache-btfgen
uses: actions/[email protected]
with:
path: pkg/btfgen/btfs
# key is composed by
# - arch: amd64 or arm64
# - latest commit of btfhub
# - hash of all bpf objects
key: btfgen-${{ matrix.platform }}-${{ steps.get-btfhub-head.outputs.head }}-${{ hashFiles('pkg/**/*.o') }}
- name: Build ig ${{ matrix.os }} ${{ matrix.platform }} container image as artifacts
uses: docker/build-push-action@v5
with:
context: /home/runner/work/inspektor-gadget/inspektor-gadget/
file: /home/runner/work/inspektor-gadget/inspektor-gadget/Dockerfiles/ig.Dockerfile
outputs: type=docker,dest=/tmp/ig-container-image-${{ matrix.os }}-${{ matrix.platform }}.tar
tags: ${{ steps.set-repo-determine-image-tag.outputs.container-repo }}:${{ steps.set-repo-determine-image-tag.outputs.image-tag }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
platforms: ${{ matrix.os }}/${{ matrix.platform }}
build-args: |
VERSION=${{ steps.set-repo-determine-image-tag.outputs.image-tag }}
EBPF_BUILDER=${{ needs.build-helper-images.outputs.ebpf_builder_image }}
- name: Publish ig ${{ matrix.os }} ${{ matrix.platform }} container image as artifacts
uses: actions/upload-artifact@v3
with:
name: ig-container-image-${{ matrix.os }}-${{ matrix.platform }}.tar
path: /tmp/ig-container-image-${{ matrix.os }}-${{ matrix.platform }}.tar
retention-days: 1
- name: Generate ig ${{ matrix.os }} ${{ matrix.platform }} container image SBOM
uses: docker/build-push-action@v5
with:
context: /home/runner/work/inspektor-gadget/inspektor-gadget/
file: /home/runner/work/inspektor-gadget/inspektor-gadget/Dockerfiles/ig.Dockerfile
outputs: type=local,dest=/tmp/ig-container-image-${{ matrix.os }}-${{ matrix.platform }}
tags: ${{ steps.set-repo-determine-image-tag.outputs.container-repo }}:${{ steps.set-repo-determine-image-tag.outputs.image-tag }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
platforms: ${{ matrix.os }}/${{ matrix.platform }}
build-args: |
VERSION=${{ steps.set-repo-determine-image-tag.outputs.image-tag }}
EBPF_BUILDER=${{ needs.build-helper-images.outputs.ebpf_builder_image }}
BUILDKIT_SYNTAX=crazymax/dockerfile:sbom
# build time will not be increased with this workflow because of internal cache
# buildx is used here since it allows push-by-digest to avoid platform specific tags
- name: Publish ig ${{ matrix.os }} ${{ matrix.platform }} container image to registry
id: publish-ig-container-images
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v5
with:
context: /home/runner/work/inspektor-gadget/inspektor-gadget/
file: /home/runner/work/inspektor-gadget/inspektor-gadget/Dockerfiles/ig.Dockerfile
outputs: type=registry,name=${{ steps.set-repo-determine-image-tag.outputs.container-repo }},push=true,push-by-digest=true
cache-from: type=local,src=/tmp/.buildx-cache-new
platforms: ${{ matrix.os }}/${{ matrix.platform }}
build-args: |
VERSION=${{ steps.set-repo-determine-image-tag.outputs.image-tag }}
EBPF_BUILDER=${{ needs.build-helper-images.outputs.ebpf_builder_image }}
- name: Setup oras
if: github.event_name != 'pull_request'
uses: oras-project/setup-oras@v1
- name: Attach SBOM to container image
if: github.event_name != 'pull_request'
id: ig-container-images-attach-sbom
run: |
# We need to get the image digest from the manifest.
# Otherwise, we will attach the SBOM to the manifest and the SBOM will
# be lost when using imagetools as this command creates a new manifest
# and attaches only the images, not the existing manifests.
# This way, we are sure the new manifest will point to the images which
# have SBOM attached.
manifest=$(oras manifest fetch ${{ steps.set-repo-determine-image-tag.outputs.container-repo }}@${{ steps.publish-ig-container-images.outputs.digest }})
image_digest=$(echo $manifest | jq -e '[.manifests[] | select ( .platform.architecture == "${{ matrix.platform }}" and .platform.os == "${{ matrix.os }}" )] | if length != 1 then empty else .[0].digest end')
image_digest=$(echo "$image_digest" | tr -d '"')
sbom_digest=$(oras attach ${{ steps.set-repo-determine-image-tag.outputs.container-repo }}@${image_digest} /tmp/ig-container-image-${{ matrix.os }}-${{ matrix.platform }}/sbom_cyclonedx.json --disable-path-validation --artifact-type example/sbom | grep 'Digest:' | awk '{ print $2 }')
echo "sbom-${{ matrix.platform }}=${sbom_digest}" >> $GITHUB_OUTPUT
- name: Save ig ${{ matrix.os }} ${{ matrix.platform }} container image digest output
id: published-ig-container-images
if: github.event_name != 'pull_request'
run: |
echo "${{ matrix.platform }}=${{ steps.publish-ig-container-images.outputs.digest }}" >> $GITHUB_OUTPUT
# old cache entries aren’t deleted, so the cache size keeps growing
# remove old cache and move new cache to cache path to workaround the issue
# https://github.com/docker/build-push-action/issues/252
- name: Move ig ${{ matrix.os }} ${{ matrix.platform }} container image cache to correct location
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
scan-gadget-container-images:
name: Scan gadget img
# level: 2
needs: build-gadget-container-images
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ linux ]
platform: [ amd64 ]
steps:
- name: Download gadget ${{ matrix.os }} ${{ matrix.platform }} container image as artifacts
uses: actions/download-artifact@v3
with:
name: gadget-container-image-${{ matrix.os }}-${{ matrix.platform }}.tar
path: ${{ github.workspace }}
- name: Scan gadget ${{ matrix.os }} ${{ matrix.platform }} container image
uses: aquasecurity/trivy-action@b2933f565dbc598b29947660e66259e3c7bc8561 # v0.20.0
with:
input: gadget-container-image-${{ matrix.os }}-${{ matrix.platform }}.tar
format: 'table'
exit-code: 1
severity: CRITICAL,HIGH
# uncomment to ignore vulnerabilities
ignore-unfixed: true
# ignore-policy: .github/trivy/ignore-policy.yaml
publish-gadget-images-manifest:
name: Publish gadget img manifest
# level: 2
if: github.event_name != 'pull_request'
needs:
- build-gadget-container-images
- public-key-check
- check-secrets
runs-on: ubuntu-latest
permissions:
# allow publishing container image
# in case of public fork repo/packages permissions will always be read
contents: read
packages: write
strategy:
fail-fast: false
outputs:
image-digest: ${{ steps.publish-manifest-list.outputs.image-digest }}
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set container repository and determine image tag
id: set-repo-determine-image-tag
uses: ./.github/actions/set-container-repo-and-determine-image-tag
with:
registry: ${{ env.REGISTRY }}
container-image: ${{ env.CONTAINER_REPO }}
- name: Publish the manifest list
id: publish-manifest-list
run: |
IMAGE_TAG=${{ steps.set-repo-determine-image-tag.outputs.container-repo }}:${{ steps.set-repo-determine-image-tag.outputs.image-tag }}
IMAGE_SOURCE="https://github.com/inspektor-gadget/inspektor-gadget"
IMAGE_DOCUMENTATION="https://inspektor-gadget.io/docs"
IMAGE_LICENSES="Apache-2.0"
IMAGE_TITLE="Inspektor Gadget k8s DaemonSet"
IMAGE_DESCRIPTION="Inspektor Gadget is a collection of tools (or gadgets) to debug and inspect Kubernetes resources and applications. This image is used as a long-running DaemonSet in Kubernetes via the kubectl-gadget deploy command or via the Helm charts."
docker buildx imagetools create \
-t $IMAGE_TAG \
--annotation index:org.opencontainers.image.documentation="$IMAGE_DOCUMENTATION" \
--annotation index:org.opencontainers.image.description="$IMAGE_DESCRIPTION" \
--annotation index:org.opencontainers.image.licenses="$IMAGE_LICENSES" \
--annotation index:org.opencontainers.image.source="$IMAGE_SOURCE" \
--annotation index:org.opencontainers.image.title="$IMAGE_TITLE" \
${{ steps.set-repo-determine-image-tag.outputs.container-repo }}@${{ needs.build-gadget-container-images.outputs.digest-amd64 }} \
${{ steps.set-repo-determine-image-tag.outputs.container-repo }}@${{ needs.build-gadget-container-images.outputs.sbom-digest-amd64 }} \
${{ steps.set-repo-determine-image-tag.outputs.container-repo }}@${{ needs.build-gadget-container-images.outputs.digest-arm64 }} \
${{ steps.set-repo-determine-image-tag.outputs.container-repo }}@${{ needs.build-gadget-container-images.outputs.sbom-digest-arm64 }}
image_digest=$(docker buildx imagetools inspect $IMAGE_TAG | grep 'Digest' | awk '{ print $2 }')
echo "image-digest=${image_digest}" >> $GITHUB_OUTPUT
- name: Install Cosign
if: needs.check-secrets.outputs.cosign == 'true'
uses: sigstore/cosign-installer@main
- name: Sign the manifest list
if: needs.check-secrets.outputs.cosign == 'true'
env:
COSIGN_PASSWORD: '${{ secrets.COSIGN_PASSWORD }}'
COSIGN_PRIVATE_KEY: '${{ secrets.COSIGN_PRIVATE_KEY }}'
run: |
cosign sign --key env://COSIGN_PRIVATE_KEY --yes --recursive "${{ steps.set-repo-determine-image-tag.outputs.container-repo }}@${{ steps.publish-manifest-list.outputs.image-digest }}"
publish-ig-images-manifest:
name: Publish ig img manifest
# level: 2
if: github.event_name != 'pull_request'
needs: build-ig-container-images
runs-on: ubuntu-latest
permissions:
# allow publishing container image
# in case of public fork repo/packages permissions will always be read
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set container repository and determine image tag
id: set-repo-determine-image-tag
uses: ./.github/actions/set-container-repo-and-determine-image-tag
with:
registry: ${{ env.REGISTRY }}
container-image: ${{ github.repository_owner }}/ig
- name: Publish the manifest list
run: |
IMAGE_SOURCE="https://github.com/inspektor-gadget/inspektor-gadget"
IMAGE_DOCUMENTATION="https://inspektor-gadget.io/docs"
IMAGE_LICENSES="Apache-2.0"
IMAGE_TITLE="Inspektor Gadget ig tool"
IMAGE_DESCRIPTION="Inspektor Gadget is a collection of tools (or gadgets) to debug and inspect Kubernetes resources and applications. This image only includes the ig binary, a standalone tool to run the gadgets."
docker buildx imagetools create \
-t ${{ steps.set-repo-determine-image-tag.outputs.container-repo }}:${{ steps.set-repo-determine-image-tag.outputs.image-tag }} \
${{ steps.set-repo-determine-image-tag.outputs.container-repo }}@${{ needs.build-ig-container-images.outputs.digest-amd64 }} \
${{ steps.set-repo-determine-image-tag.outputs.container-repo }}@${{ needs.build-ig-container-images.outputs.sbom-digest-amd64 }} \
${{ steps.set-repo-determine-image-tag.outputs.container-repo }}@${{ needs.build-ig-container-images.outputs.digest-arm64 }} \
${{ steps.set-repo-determine-image-tag.outputs.container-repo }}@${{ needs.build-ig-container-images.outputs.sbom-digest-arm64 }} \
--annotation index:org.opencontainers.image.documentation="$IMAGE_DOCUMENTATION" \
--annotation index:org.opencontainers.image.description="$IMAGE_DESCRIPTION" \
--annotation index:org.opencontainers.image.licenses="$IMAGE_LICENSES" \
--annotation index:org.opencontainers.image.source="$IMAGE_SOURCE" \
--annotation index:org.opencontainers.image.title="$IMAGE_TITLE"
build-helper-images:
# level: 0
name: helper images
runs-on: ubuntu-latest
outputs:
dnstester_image: ${{ steps.image-tag.outputs.dnstester }}
ebpf_builder_image: ${{ steps.image-tag.outputs.ebpf-builder }}
permissions:
# allow publishing container image
# in case of public fork repo/packages permissions will always be read
contents: read
packages: write
strategy:
fail-fast: false
matrix:
image:
- name: "dnstester"
context: "tools/dnstester"
dockerfile: "tools/dnstester/Dockerfile"
platform: "linux/amd64,linux/arm64"
filter-patterns:
- "tools/dnstester/*"
- name: "ebpf-builder"
context: "/home/runner/work/inspektor-gadget/inspektor-gadget"
dockerfile: "Dockerfiles/ebpf-builder.Dockerfile"
platform: "linux/amd64,linux/arm64"
filter-patterns:
- "include/**"
- "Dockerfiles/ebpf-builder.Dockerfile"
- "cmd/common/image/Makefile.build"
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
# https://github.com/rhysd/actionlint/blob/main/docs/checks.md#check-type-check-expression
filters: |
pattern: ${{ toJson(matrix.image.filter-patterns) }}
- name: Check if we should build helpers
id: check-build-helpers
# always build the images on release, merge to main or to a release branch
if: steps.filter.outputs.pattern == 'true' || startsWith(github.ref_name, 'v') || startsWith(github.ref_name, 'release-') || github.ref_name == 'main'
run: |
echo "build=true" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
if: steps.check-build-helpers.outputs.build == 'true'
uses: docker/setup-buildx-action@v3
- name: Login to Container Registry
if: steps.check-build-helpers.outputs.build == 'true'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set container repository and determine image tag
if: steps.check-build-helpers.outputs.build == 'true'
id: set-repo-determine-image-tag
uses: ./.github/actions/set-container-repo-and-determine-image-tag
with:
registry: ${{ env.REGISTRY }}
container-image: ${{ github.repository_owner }}/${{ matrix.image.name }}
- name: Build ${{ matrix.image.name }} image
id: build-image
if: steps.check-build-helpers.outputs.build == 'true'
uses: docker/build-push-action@v5
with:
context: ${{ matrix.image.context }}
file: ${{ matrix.image.dockerfile }}
push: ${{ vars.PUSH_HELPERS == 'ENABLE_PUSH_HELPERS' }}
tags: ${{ steps.set-repo-determine-image-tag.outputs.container-repo }}:${{ steps.set-repo-determine-image-tag.outputs.image-tag }}
platforms: ${{ matrix.image.platform }}
- name: Save ${{ matrix.image.name }} image tag output
id: image-tag
run: |
if [ -n "${{ steps.build-image.outputs.digest }}" ]; then
image="${{ steps.set-repo-determine-image-tag.outputs.container-repo }}:${{ steps.set-repo-determine-image-tag.outputs.image-tag }}"
else
if [ ${{ matrix.image.name }} == "dnstester" ]; then
image=${{ env.DEFAULT_DNSTESTER_IMAGE }}
elif [ ${{ matrix.image.name }} == "ebpf-builder" ]; then
image=${{ env.DEFAULT_EBPF_BUILDER_IMAGE }}
else
>&2 echo "No default image for ${{ matrix.image.name }}!"
exit 1
fi
fi
echo "${{ matrix.image.name }}=${image}" >> $GITHUB_OUTPUT
build-examples:
name: example
# level: 0
runs-on: ubuntu-latest
permissions:
# allow publishing container image
# in case of public fork repo/packages permissions will always be read
contents: read
packages: write
strategy:
fail-fast: false
matrix:
example: [runc-hook, kube-container-collection]
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set container repository and determine image tag
id: set-repo-determine-image-tag
uses: ./.github/actions/set-container-repo-and-determine-image-tag
with:
registry: ${{ env.REGISTRY }}
container-image: ${{ env.CONTAINER_REPO }}
- name: Build example container
uses: docker/build-push-action@v5
with:
context: /home/runner/work/inspektor-gadget/inspektor-gadget
file: /home/runner/work/inspektor-gadget/inspektor-gadget/examples/${{ matrix.example }}/Dockerfile
push: ${{ secrets.PUSH_EXAMPLES == 'ENABLE_PUSH_EXAMPLES' }}
tags: ${{ steps.set-repo-determine-image-tag.outputs.container-repo }}-${{ matrix.example }}:${{ steps.set-repo-determine-image-tag.outputs.image-tag }}
build-gadgets-examples:
name: Gadgets examples
# level: 0
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Build builtin gadgets example binaries
run: |
for dir in $(dirname $(find examples/builtin-gadgets -name README.md)); do
go build ./$dir;
done
test-unit:
name: Unit tests
# level: 0
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
id: go
- name: Basic unit tests
run: |
make test
- name: Gadgets unit tests
run: |
make gadgets-unit-tests
- name: Controller unit tests
run: |
make controller-tests
benchmarks:
name: Benchmarks
# level: 0