Files
mtusi2026lab7/scripts/scan.sh
T
Khakimov Dmitrij 2a7418fc45
Skeleton contracts / contracts (pull_request) Blocked by required conditions
lab 7 done
2026-11-29 21:59:16 +03:00

24 lines
864 B
Bash
Executable File

#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
work="$PWD/.runtime/scans"
mkdir -p "$work/manifests" "$work/cache"
cp go.mod go.sum "$work/manifests/"
scanner() {
docker run --rm --cpus 0.75 --memory 512m \
-v "$work:/scan" aquasec/trivy:0.67.2 --cache-dir /scan/cache \
"$@"
}
scanner fs --scanners vuln --format json --output /scan/manifests.json /scan/manifests
if [ "$#" -eq 0 ]; then
# Only images in this project. No Docker socket is mounted into Trivy.
set -- $(./scripts/compose.sh --profile operator config --images | sort -u)
fi
for image do
name=$(printf '%s' "$image" | cut -d@ -f1 | tr '/:' '__')
printf 'Scanning %s\n' "$image"
scan_path="$work/image.tar"
docker image save -o "$scan_path" "$image"
scanner image --scanners vuln,secret --format json --output "/scan/$name.json" --input /scan/image.tar
done