2024-07-24 20:01:50 +08:00
|
|
|
# syntax=docker/dockerfile:1
|
|
|
|
|
2024-11-07 20:46:47 +08:00
|
|
|
ARG GO_VERSION=1.23
|
|
|
|
ARG GOVULNCHECK_VERSION=v1.1.3
|
2024-07-24 20:01:50 +08:00
|
|
|
ARG FORMAT="text"
|
|
|
|
|
|
|
|
FROM golang:${GO_VERSION}-alpine AS base
|
|
|
|
WORKDIR /go/src/github.com/docker/buildx
|
2024-08-09 16:46:42 +08:00
|
|
|
RUN apk add --no-cache jq moreutils
|
2024-07-24 20:01:50 +08:00
|
|
|
ARG GOVULNCHECK_VERSION
|
|
|
|
RUN --mount=type=cache,target=/root/.cache \
|
|
|
|
--mount=type=cache,target=/go/pkg/mod \
|
|
|
|
go install golang.org/x/vuln/cmd/govulncheck@$GOVULNCHECK_VERSION
|
|
|
|
|
|
|
|
FROM base AS run
|
|
|
|
ARG FORMAT
|
|
|
|
RUN --mount=type=bind,target=. <<EOT
|
|
|
|
set -ex
|
|
|
|
mkdir /out
|
|
|
|
govulncheck -format ${FORMAT} ./... | tee /out/govulncheck.out
|
2024-08-09 16:46:42 +08:00
|
|
|
if [ "${FORMAT}" = "sarif" ]; then
|
|
|
|
# Make sure "results" field is defined in SARIF output otherwise GitHub Code Scanning
|
|
|
|
# will fail when uploading report with "Invalid SARIF. Missing 'results' array in run."
|
|
|
|
# Relates to https://github.com/golang/vuln/blob/ffdef74cc44d7eb71931d8d414c478b966812488/internal/sarif/sarif.go#L69
|
|
|
|
jq '(.runs[] | select(.results == null) | .results) |= []' /out/govulncheck.out | tee >(sponge /out/govulncheck.out)
|
|
|
|
fi
|
2024-07-24 20:01:50 +08:00
|
|
|
EOT
|
|
|
|
|
|
|
|
FROM scratch AS output
|
|
|
|
COPY --from=run /out /
|