Skip to content

Commit 0f287db

Browse files
calinmarinasimar7
andauthored
feat(image): add --docker-host option for GH Action users (#267)
* add option to update docker-host via cli parameter * chore: update test results --------- Co-authored-by: simar7 <[email protected]>
1 parent f72b7e8 commit 0f287db

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

action.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ inputs:
9494
limit-severities-for-sarif:
9595
description: 'limit severities for SARIF format'
9696
required: false
97+
docker-host:
98+
description: 'unix domain socket path to use for docker scanning'
99+
required: false
97100

98101
runs:
99102
using: 'docker'
@@ -123,3 +126,4 @@ runs:
123126
- '-v ${{ inputs.trivy-config }}'
124127
- '-x ${{ inputs.tf-vars }}'
125128
- '-z ${{ inputs.limit-severities-for-sarif }}'
129+
- '-y ${{ inputs.docker-host }}'

entrypoint.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
set -e
3-
while getopts "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:x:z:" o; do
3+
while getopts "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:x:y:z:" o; do
44
case "${o}" in
55
a)
66
export scanType=${OPTARG}
@@ -71,6 +71,9 @@ while getopts "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:x:z:" o; do
7171
x)
7272
export tfVars=${OPTARG}
7373
;;
74+
y)
75+
export dockerHost=${OPTARG}
76+
;;
7477
z)
7578
export limitSeveritiesForSARIF=${OPTARG}
7679
;;
@@ -165,6 +168,9 @@ if [ "$hideProgress" == "true" ];then
165168
ARGS="$ARGS --quiet"
166169
SARIF_ARGS="$SARIF_ARGS --quiet"
167170
fi
171+
if [ "$dockerHost" == "true" ];then
172+
ARGS="$ARGS --docker-host $dockerHost"
173+
fi
168174

169175
listAllPkgs=$(echo $listAllPkgs | tr -d '\r')
170176
if [ "$listAllPkgs" == "true" ];then

test/test.bats

+8
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ bats_load_library bats-file
8282
assert_files_equal yamlconfig.test ./test/data/yamlconfig.test
8383
}
8484

85+
@test "trivy image with custom docker-host" {
86+
# trivy image --docker-host unix:///var/run/docker.sock --severity CRITICAL --output image.test knqyf263/vuln-image:1.2.3
87+
run ./entrypoint.sh '-y unix:///var/run/docker.sock' '-a image' '-i knqyf263/vuln-image:1.2.3' '-h image.test' '-g CRITICAL'
88+
run diff image.test ./test/data/image.test
89+
echo "$output"
90+
assert_files_equal image.test ./test/data/image.test
91+
}
92+
8593
@test "trivy config with terraform variables" {
8694
# trivy config --format json --severity MEDIUM --output tfvars.test --tf-vars ./test/data/dev.tfvars ./test/data
8795
run ./entrypoint.sh "-a config" "-j ./test/data" "-h tfvars.test" "-g MEDIUM" "-x dev.tfvars" "-b json"

0 commit comments

Comments
 (0)