| 1 |
# syntax=docker/dockerfile-upstream:master |
| 2 |
|
| 3 |
ARG GO_VERSION=1.25 |
| 4 |
ARG ALPINE_VERSION=3.22 |
| 5 |
ARG MODOUTDATED_VERSION=v0.9.0 |
| 6 |
|
| 7 |
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base |
| 8 |
RUN apk add --no-cache git rsync |
| 9 |
WORKDIR /src |
| 10 |
|
| 11 |
FROM base AS vendored |
| 12 |
RUN --mount=target=/context \ |
| 13 |
--mount=target=.,type=tmpfs \ |
| 14 |
--mount=target=/go/pkg/mod,type=cache <<EOT |
| 15 |
set -e |
| 16 |
rsync -a /context/. . |
| 17 |
go mod tidy |
| 18 |
go mod vendor |
| 19 |
mkdir /out |
| 20 |
cp -r go.mod go.sum vendor /out |
| 21 |
EOT |
| 22 |
|
| 23 |
FROM scratch AS update |
| 24 |
COPY --from=vendored /out /out |
| 25 |
|
| 26 |
FROM vendored AS validate |
| 27 |
RUN --mount=target=/context \ |
| 28 |
--mount=target=.,type=tmpfs <<EOT |
| 29 |
set -e |
| 30 |
rsync -a /context/. . |
| 31 |
git add -A |
| 32 |
rm -rf vendor |
| 33 |
cp -rf /out/* . |
| 34 |
if [ -n "$(git status --porcelain -- go.mod go.sum vendor)" ]; then |
| 35 |
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "make vendor"' |
| 36 |
git status --porcelain -- go.mod go.sum vendor |
| 37 |
exit 1 |
| 38 |
fi |
| 39 |
EOT |
| 40 |
|
| 41 |
FROM --platform=linux/amd64 psampaz/go-mod-outdated:${MODOUTDATED_VERSION} AS go-mod-outdated-amd64 |
| 42 |
|
| 43 |
FROM go-mod-outdated-amd64 AS go-mod-outdated |
| 44 |
FROM base AS outdated |
| 45 |
RUN --mount=target=.,rw \ |
| 46 |
--mount=target=/go/pkg/mod,type=cache \ |
| 47 |
--mount=from=go-mod-outdated,source=/usr/bin/go-mod-outdated,target=/usr/bin/go-mod-outdated \ |
| 48 |
go list -mod=mod -u -m -json all | go-mod-outdated -update -direct |