2018-10-12 20:58:56 +00:00
|
|
|
# syntax = tonistiigi/dockerfile:runmount20181002
|
|
|
|
|
2018-10-16 18:37:41 +00:00
|
|
|
FROM --platform=$BUILDPLATFORM tonistiigi/xx:golang@sha256:6f7d999551dd471b58f70716754290495690efa8421e0a1fcf18eb11d0c0a537 AS xgo
|
|
|
|
|
|
|
|
FROM --platform=$BUILDPLATFORM golang:1.11 AS base
|
|
|
|
COPY --from=xgo / /
|
|
|
|
WORKDIR /go/src/github.com/moby/buildkit
|
|
|
|
|
|
|
|
FROM base AS version
|
|
|
|
ARG CHANNEL
|
|
|
|
RUN --mount=target=. \
|
|
|
|
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); \
|
|
|
|
echo "-X main.Version=${VERSION} -X main.Revision=${REVISION} -X main.Package=${PKG}" | tee /tmp/.ldflags; \
|
|
|
|
echo -n "${VERSION}" | tee /tmp/.version;
|
|
|
|
|
|
|
|
FROM base AS build
|
2018-10-12 20:58:56 +00:00
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends file
|
2018-06-07 20:57:35 +00:00
|
|
|
ARG BUILDTAGS=""
|
2018-10-16 18:37:41 +00:00
|
|
|
ARG TARGETPLATFORM
|
|
|
|
ENV TARGETPLATFORM=$TARGETPLATFORM
|
2018-10-12 20:58:56 +00:00
|
|
|
RUN --mount=target=. --mount=type=cache,target=/root/.cache \
|
2018-10-16 18:37:41 +00:00
|
|
|
--mount=source=/tmp/.ldflags,target=/tmp/.ldflags,from=version \
|
|
|
|
CGO_ENABLED=0 go build -o /dockerfile-frontend -ldflags "-d $(cat /tmp/.ldflags)" -tags "$BUILDTAGS netgo static_build osusergo" ./frontend/dockerfile/cmd/dockerfile-frontend && \
|
2018-10-12 20:58:56 +00:00
|
|
|
file /dockerfile-frontend | grep "statically linked"
|
2017-10-03 21:31:46 +00:00
|
|
|
|
|
|
|
FROM scratch
|
2018-10-16 18:37:41 +00:00
|
|
|
COPY --from=build /dockerfile-frontend /bin/dockerfile-frontend
|
2017-10-03 21:31:46 +00:00
|
|
|
ENTRYPOINT ["/bin/dockerfile-frontend"]
|