| 1 |
# syntax=docker/dockerfile-upstream:master |
| 2 |
|
| 3 |
ARG GO_VERSION=1.25 |
| 4 |
ARG ALPINE_VERSION=3.22 |
| 5 |
ARG XX_VERSION=1.6.1 |
| 6 |
|
| 7 |
# xx is a helper for cross-compilation |
| 8 |
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx |
| 9 |
|
| 10 |
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base |
| 11 |
RUN apk add git bash |
| 12 |
COPY --from=xx / / |
| 13 |
WORKDIR /src |
| 14 |
ENV GOFLAGS=-mod=vendor |
| 15 |
|
| 16 |
FROM base AS version |
| 17 |
ARG CHANNEL |
| 18 |
# TODO: PKG should be inferred from go modules |
| 19 |
RUN --mount=target=. \ |
| 20 |
PKG=github.com/moby/buildkit/frontend/dockerfile/cmd/dockerfile-frontend VERSION=$(./frontend/dockerfile/cmd/dockerfile-frontend/hack/detect "$CHANNEL") REVISION=$(git rev-parse HEAD)$(if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi) \ |
| 21 |
&& echo "-X main.Version=${VERSION} -X main.Revision=${REVISION} -X main.Package=${PKG}" | tee /tmp/.ldflags \ |
| 22 |
&& echo -n "${VERSION}" | tee /tmp/.version |
| 23 |
|
| 24 |
FROM base AS build |
| 25 |
RUN apk add --no-cache file |
| 26 |
ARG BUILDTAGS="" |
| 27 |
ARG TARGETPLATFORM |
| 28 |
RUN --mount=target=. --mount=type=cache,target=/root/.cache \ |
| 29 |
--mount=target=/go/pkg/mod,type=cache \ |
| 30 |
--mount=source=/tmp/.ldflags,target=/tmp/.ldflags,from=version \ |
| 31 |
CGO_ENABLED=0 xx-go build -o /dockerfile-frontend -ldflags "-d $(cat /tmp/.ldflags)" -tags "$BUILDTAGS netgo static_build osusergo" ./frontend/dockerfile/cmd/dockerfile-frontend && \ |
| 32 |
xx-verify --static /dockerfile-frontend |
| 33 |
|
| 34 |
FROM scratch AS release |
| 35 |
LABEL moby.buildkit.frontend.network.none="true" |
| 36 |
LABEL moby.buildkit.frontend.caps="moby.buildkit.frontend.inputs,moby.buildkit.frontend.subrequests,moby.buildkit.frontend.contexts,moby.buildkit.frontend.gitquerystring" |
| 37 |
COPY --from=build /dockerfile-frontend /bin/dockerfile-frontend |
| 38 |
ENTRYPOINT ["/bin/dockerfile-frontend"] |
| 39 |
|
| 40 |
FROM release |