fix: Trivy download into dapper container is skipped (#12219)

* only run trivy if executable is available

Signed-off-by: holysoles <holysoles97@gmail.com>
Signed-off-by: Derek Nola <derek.nola@suse.com>
Co-authored-by: Derek Nola <derek.nola@suse.com>
This commit is contained in:
Patrick Evans
2025-06-02 21:23:18 +00:00
committed by GitHub
parent 07171fd7e8
commit 412a21e5a0
3 changed files with 8 additions and 9 deletions

View File

@@ -20,8 +20,8 @@ RUN case "$(go env GOARCH)" in \
amd64) TRIVY_ARCH="64bit" ;; \
s390x) TRIVY_ARCH="s390x" ;; \
*) TRIVY_ARCH="" ;; \
esac
RUN if [ -n "${TRIVY_ARCH}" ]; then \
esac && \
if [ -n "${TRIVY_ARCH}" ]; then \
wget --no-verbose "https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-${TRIVY_ARCH}.tar.gz" \
&& tar -zxvf "trivy_${TRIVY_VERSION}_Linux-${TRIVY_ARCH}.tar.gz" \
&& mv trivy /usr/local/bin; \

View File

@@ -2,15 +2,14 @@
set -e
if [ -z $1 ] && [ -z $2 ]; then
echo "error: image name and arch name are required as arguments. exiting..."
if [ -z $1 ]; then
echo "error: image name is required as argument. exiting..."
exit 1
fi
ARCH=$2
# skipping image scan for 32 bits image since trivy dropped support for those https://github.com/aquasecurity/trivy/discussions/4789
if [[ "${ARCH}" = "arm" ]] || [ "${ARCH}" != "386" ]; then
# we wont have trivy installed if its an unsupported arch
if [ -z "$(which trivy)" ]; then
echo "warning: trivy scan being skipped since 'trivy' executable not found in path"
exit 0
fi

View File

@@ -15,5 +15,5 @@ IMAGE_NAME=${IMAGE_NAME:-k3s}
IMAGE=${REPO}/${IMAGE_NAME}:${TAG}
docker build --build-arg DRONE_TAG=${VERSION_TAG} -t ${IMAGE} -f package/Dockerfile .
./scripts/image_scan.sh ${IMAGE} ${ARCH}
./scripts/image_scan.sh ${IMAGE}
echo Built ${IMAGE}