19
19
runs-on : ${{ inputs.runsOn }}
20
20
strategy :
21
21
matrix :
22
- workingdir : [telemetry-aware-scheduling, gpu-aware-scheduling ]
22
+ workingdir : [ telemetry-aware-scheduling ]
23
23
name : image-vulnerability-scanners
24
24
steps :
25
25
- name : Checkout project
@@ -29,18 +29,20 @@ jobs:
29
29
- name : install Trivy
30
30
run : curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin ${{ inputs.trivyVersion }}
31
31
- name : trivy base image scan $DIR
32
+ id : base_image_scan
32
33
run : |
33
34
cd ./${{ matrix.workingdir }}
34
35
base_image_suffix=$(grep "GO_VERSION = " Makefile | cut -d " " -f 3)
35
36
base_image="golang:${base_image_suffix}"
36
37
echo "[INFO] base image name is: ${base_image}"
37
38
output=$(trivy image --severity HIGH,CRITICAL ${base_image} --exit-code=2)
38
- if [ "${output}" -eq 2 ]; then
39
+ if [ "$?" == "2" ]; then
39
40
echo "::warning::severities CRITICAL, HIGH issues spotted by Trivy in ${{ matrix.workingdir }} for base image: ${base_image}"
40
41
exit 1
41
42
else
42
43
echo "trivy image ./ --severity=CRITICAL, HIGH for base image: ${base_image} ran successfully"
43
44
fi
45
+
44
46
cd ..
45
47
shell : bash
46
48
- name : make image
@@ -49,21 +51,40 @@ jobs:
49
51
make image
50
52
cd ..
51
53
- name : trivy image scan $DIR
54
+ id : main_image_scan
52
55
run : |
53
56
cd ./${{ matrix.workingdir }}
54
57
image_name="tasextender"
55
- if [ ${{ matrix.workingdir}} -eq "gpu-aware-scheduling" ]; then
58
+ if [ " ${{ matrix.workingdir}}" == "gpu-aware-scheduling" ]; then
56
59
image_name="gpu-extender"
57
60
fi
58
61
echo "[INFO]image name is: ${image_name}"
59
62
output=$(trivy image --severity HIGH,CRITICAL ${image_name} --exit-code=2)
60
- if [ -n "${output} " ]; then
63
+ if [ "$?" == "2 " ]; then
61
64
echo "::warning::severities CRITICAL, HIGH issues spotted by Trivy in ${{ matrix.workingdir }} for image: ${image_name}"
62
65
exit 1
63
66
else
64
67
echo "trivy image ./ --severity=CRITICAL, HIGH for image ${image_name} ran successfully"
65
68
fi
66
-
69
+
70
+ # output module image name
71
+ echo "MAIN_IMAGE_NAME=$image_name" >> $GITHUB_OUTPUT
72
+
67
73
cd ..
68
74
shell : bash
75
+ - name : clean-up generated images
76
+ id : clean_up_images
77
+ run : |
78
+ echo "clean-up before finishing..."
79
+ # trivy can run the scan on base images without pulling the images
80
+ # locally in Docker, so no point cleaning the base images
81
+ module_image_name=${{ steps.main_image_scan.outputs.MAIN_IMAGE_NAME }}
82
+ if [ -n "$module_image_name" ]; then
83
+ echo "clean-up module image: $module_image_name"
84
+ docker rmi $(docker image ls --format '{{.Repository}}:{{.Tag}}' | grep "$module_image_name:latest")
85
+ fi
86
+
87
+ echo "clean-up finished."
88
+
89
+ shell : bash
69
90
0 commit comments