trivy-gate: fs scans of lockfiles, checksum-verified binary when no Docker

dtrack-sbom converts with the same runtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-10-25 18:54:03 +01:00
1 parent 86409a2413
commit 7fae1fa2f6
3 files changed
+127 -28

No files matched your search

+14 -4
View File
@@ -54,12 +54,22 @@ runs:
[ -n "$REPORT" ] && [ -f "$REPORT" ] || warn "no report (gate skipped?)"
[ -n "$DT_KEY" ] || warn "no API key"
work="${RUNNER_TEMP:-/tmp}/dtrack-sbom"; mkdir -p "$work"
docker run -i --rm --entrypoint sh "$TRIVY" -c \
'cat >/tmp/r.json && trivy convert --quiet --format cyclonedx /tmp/r.json' \
<"$REPORT" >"$work/bom.json" || warn "trivy convert failed"
# Same runtime as trivy-gate: its container when a Docker daemon is
# reachable, else the checksum-verified binary trivy-gate fetched.
gate_bin="${RUNNER_TEMP:-/tmp}/trivy-gate/bin/trivy"
if command -v docker >/dev/null && docker info >/dev/null 2>&1; then
docker run -i --rm --entrypoint sh "$TRIVY" -c \
'cat >/tmp/r.json && trivy convert --quiet --format cyclonedx /tmp/r.json' \
<"$REPORT" >"$work/bom.json" || warn "trivy convert failed"
elif [ -x "$gate_bin" ]; then
"$gate_bin" convert --quiet --format cyclonedx "$REPORT" >"$work/bom.json" || warn "trivy convert failed"
else
warn "neither Docker nor the trivy-gate binary available"
fi
if [ -n "$EXTRA" ]; then
jq --slurpfile extra "$EXTRA" '.components += $extra[0]' "$work/bom.json" >"$work/bom2.json" \
&& mv "$work/bom2.json" "$work/bom.json" || warn "cannot merge $EXTRA"
|| warn "cannot merge $EXTRA"
mv "$work/bom2.json" "$work/bom.json"
fi
n=$(jq '.components | length' "$work/bom.json") || warn "unreadable SBOM"
[ "$n" -ge "$MIN" ] || warn "only $n components, not uploading"