@@ -2,10 +2,18 @@ name: Container vulnerability scan
2
2
on :
3
3
workflow_call :
4
4
inputs :
5
- image :
5
+ image_name :
6
6
type : string
7
7
description : Container image name and tag to scan
8
8
required : true
9
+ image_artifact_name :
10
+ type : string
11
+ description : Container image artifact name to identify the container image file from artifacts
12
+ required : false
13
+ image_artifact_filename :
14
+ type : string
15
+ description : Container image file that needs to be downloaded from artifacts
16
+ required : false
9
17
login_dockerhub :
10
18
type : boolean
11
19
description : " Login to DockerHub, requires the secrets DOCKERHUB_USERNAME and DOCKERHUB_PASSWORD (default: false)"
41
49
- name : Pull aquasec/trivy
42
50
run : |
43
51
docker pull aquasec/trivy:${{ inputs.trivy_tag }}
52
+ - name : Download container image from artifacts if uploaded
53
+ if : ${{ inputs.image_artifact_name }} && ${{ inputs.image_artifact_filename }}
54
+ uses : actions/download-artifact@v2
55
+ with :
56
+ name : ${{ inputs.image_artifact_name }}
57
+ path : /tmp
58
+ - name : Load container image file if one is shipped via artifacts
59
+ if : ${{ inputs.image_artifact_name }} && ${{ inputs.image_artifact_filename }}
60
+ run : |
61
+ docker load --input /tmp/${{ inputs.image_artifact_filename }}
62
+ RC=$?
63
+ if [ ${RC} -gt 0 ]; then
64
+ exit ${RC}
65
+ fi
66
+ - name : Pull container image that should be scanned if no container image is shipped via artifacts
67
+ if : ! ${{ inputs.image_artifact_name }} && ! ${{ inputs.image_artifact_filename }}
68
+ run : |
69
+ docker pull ${{ inputs.image_name }}
70
+ RC=$?
71
+ if [ ${RC} -gt 0 ]; then
72
+ exit ${RC}
73
+ fi
74
+ - name : List available container images in local repository
75
+ run : |
76
+ docker image ls -a
44
77
- name : Vulnerability scan
45
78
run : |
46
- docker run -- rm -v /var/run/docker.sock:/var/run/docker.sock aquasec/trivy:${{ inputs.trivy_tag }} -q image ${{ inputs.image }} | tee -a ${GITHUB_STEP_SUMMARY}
79
+ docker run -u 0 -- rm -v /var/run/docker.sock:/var/run/docker.sock aquasec/trivy:${{ inputs.trivy_tag }} -q image ${{ inputs.image_name }} >> ${GITHUB_STEP_SUMMARY} 2>&1
0 commit comments