0
0
Fork 0
mirror of https://github.com/crazy-max/diun.git synced 2025-03-16 20:33:30 +00:00
crazy-max_diun/hack/vendor.Dockerfile

48 lines
1.3 KiB
Text
Raw Permalink Normal View History

# syntax=docker/dockerfile:1
2024-12-14 20:07:33 +00:00
ARG GO_VERSION="1.23"
2024-12-14 20:08:36 +00:00
ARG ALPINE_VERSION="3.21"
ARG GOMOD_OUTDATED_VERSION="v0.8.0"
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
2024-12-14 21:23:46 +00:00
ENV GOFLAGS="-mod=vendor"
RUN apk add --no-cache git linux-headers musl-dev rsync
WORKDIR /src
FROM base AS vendored
2024-12-14 21:23:46 +00:00
RUN --mount=target=/context \
--mount=target=.,type=tmpfs \
--mount=target=/go/pkg/mod,type=cache <<EOT
2022-10-22 19:21:06 +00:00
set -e
2024-12-14 21:23:46 +00:00
rsync -a /context/. .
2022-10-22 19:21:06 +00:00
go mod tidy
2024-12-14 21:23:46 +00:00
go mod vendor
2022-10-22 19:21:06 +00:00
mkdir /out
2024-12-14 21:23:46 +00:00
cp -r go.mod go.sum vendor /out
EOT
FROM scratch AS update
COPY --from=vendored /out /
FROM vendored AS validate
2024-12-14 21:23:46 +00:00
RUN --mount=target=/context \
--mount=target=.,type=tmpfs <<EOT
2022-10-22 19:21:06 +00:00
set -e
2024-12-14 21:23:46 +00:00
rsync -a /context/. .
2022-10-22 19:21:06 +00:00
git add -A
2024-12-14 21:23:46 +00:00
rm -rf vendor
2022-10-22 19:21:06 +00:00
cp -rf /out/* .
2024-12-14 21:23:46 +00:00
if [ -n "$(git status --porcelain -- go.mod go.sum vendor)" ]; then
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "make vendor"'
git status --porcelain -- go.mod go.sum vendor
2022-10-22 19:21:06 +00:00
exit 1
fi
EOT
FROM psampaz/go-mod-outdated:${GOMOD_OUTDATED_VERSION} AS go-mod-outdated
FROM base AS outdated
2024-12-14 21:23:46 +00:00
RUN --mount=type=bind,target=.,rw \
2022-10-22 19:21:06 +00:00
--mount=type=cache,target=/go/pkg/mod \
--mount=from=go-mod-outdated,source=/home/go-mod-outdated,target=/usr/bin/go-mod-outdated \
2024-12-14 21:23:46 +00:00
go list -mod=mod -u -m -json all | go-mod-outdated -update -direct