| 1 |
# syntax=docker/dockerfile:1 |
| 2 |
|
| 3 |
ARG GO_VERSION=1.25 |
| 4 |
ARG ALPINE_VERSION=3.22 |
| 5 |
|
| 6 |
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS golatest |
| 7 |
|
| 8 |
FROM golatest AS docsgen |
| 9 |
WORKDIR /src |
| 10 |
ENV CGO_ENABLED=0 |
| 11 |
RUN --mount=target=. \ |
| 12 |
--mount=target=/root/.cache,type=cache \ |
| 13 |
--mount=target=/go/pkg/mod,type=cache \ |
| 14 |
go build -mod=vendor -o /out/docsgen ./frontend/dockerfile/linter/generate.go |
| 15 |
|
| 16 |
FROM alpine AS gen |
| 17 |
RUN apk add --no-cache rsync git |
| 18 |
WORKDIR /src |
| 19 |
COPY --from=docsgen /out/docsgen /usr/bin |
| 20 |
RUN --mount=target=/context \ |
| 21 |
--mount=target=.,type=tmpfs <<EOT |
| 22 |
set -ex |
| 23 |
rsync -a /context/. . |
| 24 |
cd frontend/dockerfile/linter |
| 25 |
docsgen ./dist |
| 26 |
mkdir /out |
| 27 |
cp -r dist/* /out |
| 28 |
EOT |
| 29 |
|
| 30 |
FROM scratch AS update |
| 31 |
COPY --from=gen /out / |
| 32 |
|
| 33 |
FROM gen AS validate |
| 34 |
RUN --mount=target=/context \ |
| 35 |
--mount=target=.,type=tmpfs <<EOT |
| 36 |
set -e |
| 37 |
rsync -a /context/. . |
| 38 |
git add -A |
| 39 |
rm -rf frontend/dockerfile/docs/rules/* |
| 40 |
cp -rf /out/* ./frontend/dockerfile/docs/rules/ |
| 41 |
if [ -n "$(git status --porcelain -- frontend/dockerfile/docs/rules/)" ]; then |
| 42 |
echo >&2 'ERROR: Dockerfile docs result differs. Please update with "make docs-dockerfile"' |
| 43 |
git status --porcelain -- frontend/dockerfile/docs/rules/ |
| 44 |
exit 1 |
| 45 |
fi |
| 46 |
EOT |