33# Licensed under the GNU Affero General Public License (AGPL).
44# See License.AGPL.txt in the project root for license information.
55
6- set -uo pipefail
6+ set -euo pipefail
77
88# Check if VERSION and FAIL_ON are provided
99if [[ $# -lt 2 ]]; then
@@ -40,8 +40,7 @@ echo "Working directory: $SCAN_DIR"
4040
4141# Directory where this script is located
4242SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
43- CONFIG_DIR=" $SCRIPT_DIR "
44- INSTALLER_CONFIG_FILE=" scan-installer-config.yaml"
43+ INSTALLER_CONFIG_PATH=" $SCRIPT_DIR /scan-installer-config.yaml"
4544TRIVYIGNORE_PATH=" $SCRIPT_DIR /trivyignore.yaml"
4645
4746# Ensure Trivy is installed
@@ -53,11 +52,25 @@ if ! command -v "$TRIVY_CMD" &> /dev/null; then
5352 curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b " $SCAN_DIR /bin"
5453fi
5554
55+ OCI_TOOL_CMD=" oci-tool"
56+ OCI_TOOL_VERSION=" 0.2.0"
57+ if ! command -v " $OCI_TOOL_CMD " & > /dev/null; then
58+ mkdir -p " $SCAN_DIR /bin"
59+ OCI_TOOL_CMD=" $SCAN_DIR /bin/oci-tool"
60+ curl -fsSL https://github.com/csweichel/oci-tool/releases/download/v${OCI_TOOL_VERSION} /oci-tool_${OCI_TOOL_VERSION} _linux_amd64.tar.gz | tar xz -C " $( dirname " $OCI_TOOL_CMD " ) " && chmod +x " $OCI_TOOL_CMD "
61+ fi
62+
5663echo " === Gathering list of all images for $VERSION "
5764
65+ # Extract installer binary from installer image
66+ INSTALLER_IMAGE=" $INSTALLER_IMAGE_BASE_REPO /build/installer:${VERSION} "
67+ INSTALLER=" $SCAN_DIR /installer"
68+ " $OCI_TOOL_CMD " fetch file -o " $INSTALLER " --platform=linux-amd64 " ${INSTALLER_IMAGE} " app/installer
69+ echo " "
70+ chmod +x " $INSTALLER "
71+
5872# Run the installer docker image to get the list of images
59- docker run --rm -v " $CONFIG_DIR :/config" " $INSTALLER_IMAGE_BASE_REPO /build/installer:${VERSION} " mirror list \
60- -c " /config/$INSTALLER_CONFIG_FILE " > " $SCAN_DIR /mirror.json"
73+ " $INSTALLER " mirror list -c " $INSTALLER_CONFIG_PATH " > " $SCAN_DIR /mirror.json"
6174
6275# Extract original image references
6376jq -r ' .[].original' " $SCAN_DIR /mirror.json" > " $SCAN_DIR /images.txt"
@@ -97,6 +110,7 @@ while IFS= read -r IMAGE_REF; do
97110
98111 # Run Trivy on the image
99112 scan_time=$( date -u +" %Y-%m-%dT%H:%M:%SZ" )
113+ set +e
100114 trivy_output=$( " $TRIVY_CMD " image " $IMAGE_REF " --ignorefile " $TRIVYIGNORE_PATH " --scanners vuln --format json " $@ " | jq -c)
101115 scan_status=$?
102116
@@ -127,6 +141,7 @@ while IFS= read -r IMAGE_REF; do
127141 ' {image: $image, scan_time: $scan_time, error: $error, error_details: $details}' >> " $RESULT_FILE "
128142 (( FAILED= FAILED+ 1 ))
129143 fi
144+ set -e
130145
131146 echo " "
132147done < " $SCAN_DIR /images.txt"
0 commit comments