| 1 |
# syntax=docker/dockerfile:1 |
| 2 |
|
| 3 |
ARG GO_VERSION=1.23 |
| 4 |
|
| 5 |
FROM golang:${GO_VERSION}-alpine AS gomod |
| 6 |
RUN apk add --no-cache git |
| 7 |
WORKDIR /src |
| 8 |
RUN --mount=target=/src,rw \ |
| 9 |
--mount=target=/go/pkg/mod,type=cache \ |
| 10 |
go mod tidy && \ |
| 11 |
mkdir /out && cp -r go.mod go.sum /out && \ |
| 12 |
cd bench && go mod tidy && \ |
| 13 |
mkdir /out/bench && cp -r go.mod go.sum /out/bench |
| 14 |
|
| 15 |
FROM scratch AS update |
| 16 |
COPY --from=gomod /out / |
| 17 |
|
| 18 |
FROM gomod AS validate |
| 19 |
RUN --mount=target=.,rw <<EOT |
| 20 |
set -e |
| 21 |
git add -A |
| 22 |
cp -rf /out/* . |
| 23 |
diff=$(git status --porcelain -- go.mod go.sum bench/go.mod bench/go.sum 2>/dev/null) |
| 24 |
if [ -n "$diff" ]; then |
| 25 |
echo >&2 'ERROR: The result of "./hack/validate-gomod" differs. Please update with "./hack/update-gomod".' |
| 26 |
echo "$diff" |
| 27 |
exit 1 |
| 28 |
fi |
| 29 |
EOT |