2020-12-09 07:44:08 +08:00
|
|
|
# syntax=docker/dockerfile:1.2
|
2019-03-23 07:23:09 +08:00
|
|
|
|
2020-12-09 07:44:08 +08:00
|
|
|
ARG DOCKERD_VERSION=19.03
|
2019-03-23 07:23:09 +08:00
|
|
|
ARG CLI_VERSION=19.03
|
|
|
|
|
|
|
|
FROM docker:$DOCKERD_VERSION AS dockerd-release
|
|
|
|
|
2021-06-29 09:30:27 +08:00
|
|
|
# xx is a helper for cross-compilation
|
|
|
|
FROM --platform=$BUILDPLATFORM tonistiigi/xx@sha256:21a61be4744f6531cb5f33b0e6f40ede41fa3a1b8c82d5946178f80cc84bfc04 AS xx
|
2019-03-23 07:23:09 +08:00
|
|
|
|
2021-02-17 15:03:26 +08:00
|
|
|
FROM --platform=$BUILDPLATFORM golang:1.16-alpine AS gobase
|
2021-06-29 09:30:27 +08:00
|
|
|
COPY --from=xx / /
|
2019-03-23 09:18:07 +08:00
|
|
|
RUN apk add --no-cache file git
|
2019-03-23 07:23:09 +08:00
|
|
|
ENV GOFLAGS=-mod=vendor
|
|
|
|
WORKDIR /src
|
|
|
|
|
|
|
|
FROM gobase AS buildx-version
|
|
|
|
RUN --mount=target=. \
|
2019-04-25 10:29:56 +08:00
|
|
|
PKG=github.com/docker/buildx VERSION=$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags) REVISION=$(git rev-parse HEAD)$(if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi); \
|
2019-03-23 07:23:09 +08:00
|
|
|
echo "-X ${PKG}/version.Version=${VERSION} -X ${PKG}/version.Revision=${REVISION} -X ${PKG}/version.Package=${PKG}" | tee /tmp/.ldflags; \
|
|
|
|
echo -n "${VERSION}" | tee /tmp/.version;
|
|
|
|
|
|
|
|
FROM gobase AS buildx-build
|
|
|
|
ENV CGO_ENABLED=0
|
|
|
|
ARG TARGETPLATFORM
|
|
|
|
RUN --mount=target=. --mount=target=/root/.cache,type=cache \
|
|
|
|
--mount=target=/go/pkg/mod,type=cache \
|
|
|
|
--mount=source=/tmp/.ldflags,target=/tmp/.ldflags,from=buildx-version \
|
2021-06-29 09:30:27 +08:00
|
|
|
set -x; xx-go build -ldflags "$(cat /tmp/.ldflags)" -o /usr/bin/buildx ./cmd/buildx && \
|
|
|
|
xx-verify --static /usr/bin/buildx
|
2019-03-23 07:23:09 +08:00
|
|
|
|
2019-03-23 09:52:36 +08:00
|
|
|
FROM buildx-build AS integration-tests
|
|
|
|
COPY . .
|
|
|
|
|
2019-05-07 07:11:39 +08:00
|
|
|
# FROM golang:1.12-alpine AS docker-cli-build
|
|
|
|
# RUN apk add -U git bash coreutils gcc musl-dev
|
|
|
|
# ENV CGO_ENABLED=0
|
|
|
|
# ARG REPO=github.com/tiborvass/cli
|
|
|
|
# ARG BRANCH=cli-plugin-aliases
|
|
|
|
# ARG CLI_VERSION
|
|
|
|
# WORKDIR /go/src/github.com/docker/cli
|
|
|
|
# RUN git clone git://$REPO . && git checkout $BRANCH
|
|
|
|
# RUN ./scripts/build/binary
|
2019-03-23 07:23:09 +08:00
|
|
|
|
2019-03-23 08:21:05 +08:00
|
|
|
FROM scratch AS binaries-unix
|
|
|
|
COPY --from=buildx-build /usr/bin/buildx /
|
|
|
|
|
|
|
|
FROM binaries-unix AS binaries-darwin
|
|
|
|
FROM binaries-unix AS binaries-linux
|
|
|
|
|
|
|
|
FROM scratch AS binaries-windows
|
|
|
|
COPY --from=buildx-build /usr/bin/buildx /buildx.exe
|
|
|
|
|
|
|
|
FROM binaries-$TARGETOS AS binaries
|
|
|
|
|
2019-04-25 08:54:56 +08:00
|
|
|
FROM --platform=$BUILDPLATFORM alpine AS releaser
|
|
|
|
WORKDIR /work
|
|
|
|
ARG TARGETPLATFORM
|
|
|
|
RUN --mount=from=binaries \
|
|
|
|
--mount=source=/tmp/.version,target=/tmp/.version,from=buildx-version \
|
|
|
|
mkdir -p /out && cp buildx* "/out/buildx-$(cat /tmp/.version).$(echo $TARGETPLATFORM | sed 's/\//-/g')$(ls buildx* | sed -e 's/^buildx//')"
|
|
|
|
|
|
|
|
FROM scratch AS release
|
|
|
|
COPY --from=releaser /out/ /
|
|
|
|
|
2019-03-23 07:23:09 +08:00
|
|
|
FROM alpine AS demo-env
|
2019-04-25 01:49:34 +08:00
|
|
|
RUN apk add --no-cache iptables tmux git vim less openssh
|
2019-03-23 07:23:09 +08:00
|
|
|
RUN mkdir -p /usr/local/lib/docker/cli-plugins && ln -s /usr/local/bin/buildx /usr/local/lib/docker/cli-plugins/docker-buildx
|
|
|
|
COPY ./hack/demo-env/entrypoint.sh /usr/local/bin
|
|
|
|
COPY ./hack/demo-env/tmux.conf /root/.tmux.conf
|
|
|
|
COPY --from=dockerd-release /usr/local/bin /usr/local/bin
|
2019-05-07 07:11:39 +08:00
|
|
|
#COPY --from=docker-cli-build /go/src/github.com/docker/cli/build/docker /usr/local/bin
|
2019-03-24 12:30:29 +08:00
|
|
|
|
|
|
|
WORKDIR /work
|
|
|
|
COPY ./hack/demo-env/examples .
|
2019-03-23 08:21:05 +08:00
|
|
|
COPY --from=binaries / /usr/local/bin/
|
2019-03-23 07:23:09 +08:00
|
|
|
VOLUME /var/lib/docker
|
|
|
|
ENTRYPOINT ["entrypoint.sh"]
|
2019-04-25 07:00:59 +08:00
|
|
|
|
|
|
|
FROM binaries
|