Skip to content

Commit a88e323

Browse files
committed
limit scanning to 10 images to check CI
1 parent b71b345 commit a88e323

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

actions/docker/scan-repo/action.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ runs:
9393
echo "trivy=${trivy_bin}" >> "${GITHUB_OUTPUT}"
9494
echo "report-file=${_report_file}" >> "${GITHUB_OUTPUT}"
9595
96+
- name: Post save report
97+
uses: milaboratory/github-ci/actions/post/artifact@v4-beta
98+
with:
99+
name: trivy-report
100+
archive: true
101+
path: |
102+
${{ steps.init.outputs.report-file }}
103+
96104
- name: Scan images
97105
id: scan-images
98106
shell: bash
@@ -110,4 +118,4 @@ runs:
110118
REPORT_FORMAT: ${{ inputs.report-format }}
111119
REPORT_FILE: ${{ steps.init.outputs.report-file }}
112120
run: |
113-
"${ACTION_PATH}/scan-images.sh" "${REGISTRY}" "${REPOSITORY}" "${TAG}"
121+
SCAN_IMAGES_LIMIT=10 "${ACTION_PATH}/scan-images.sh" "${REGISTRY}" "${REPOSITORY}" "${TAG}"

actions/docker/scan-repo/scan-images.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ tag="${3:-}"
99

1010
: "${DEBUG:=false}"
1111
: "${TRIVY_BIN:=trivy}"
12+
: "${SCAN_IMAGES_LIMIT:=}" # stop sanning after this amount of images
1213

1314
: "${PKG_TYPES:=os,library}"
1415
: "${SCANNERS:=vuln,secret,misconfig}"
@@ -106,12 +107,20 @@ scan_image() {
106107
}
107108

108109
scan_images() {
110+
local _limit="${1:-}"
109111
local _success=true
110112

113+
local _items_count=0
111114
while read -r tag; do
112115
if ! scan_image "${tag}"; then
113116
_success=false
114117
fi
118+
119+
_items_count=$((_items_count + 1))
120+
if [ -n "${_limit}" ] && [ "${_items_count}" -ge "${_limit}" ]; then
121+
log " reached scan limit of ${_limit} images"
122+
break
123+
fi
115124
done
116125

117126
if [ "${_success}" != "true" ]; then
@@ -137,10 +146,11 @@ if [ -n "${tag}" ]; then
137146
else
138147
log "Scanning images in ${registry}/${repository}..."
139148
list_images "${registry}" "${repository}" |
140-
scan_images || success=false
149+
scan_images "${SCAN_IMAGES_LIMIT}" || success=false
141150
fi
142151

143152
if [ "${success}" == "true" ]; then
153+
log "Scan completed successfully, no CVEs found"
144154
exit 0
145155
fi
146156

0 commit comments

Comments
 (0)