|
| 1 | +#syntax=docker/dockerfile:1.2 |
| 2 | + |
| 3 | +ARG BASE_VARIANT=alpine |
| 4 | +ARG GO_VERSION=1.13.15 |
| 5 | + |
| 6 | +FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-${BASE_VARIANT} AS gostable |
| 7 | +FROM --platform=$BUILDPLATFORM golang:1.16-${BASE_VARIANT} AS golatest |
| 8 | + |
| 9 | +FROM gostable AS go-linux |
| 10 | +FROM golatest AS go-darwin |
| 11 | +FROM golatest AS go-windows-amd64 |
| 12 | +FROM golatest AS go-windows-386 |
| 13 | +FROM golatest AS go-windows-arm |
| 14 | +FROM --platform=$BUILDPLATFORM tonistiigi/golang:497feff1-${BASE_VARIANT} AS go-windows-arm64 |
| 15 | +FROM go-windows-${TARGETARCH} AS go-windows |
| 16 | + |
| 17 | +FROM --platform=$BUILDPLATFORM tonistiigi/xx@sha256:620d36a9d7f1e3b102a5c7e8eff12081ac363828b3a44390f24fa8da2d49383d AS xx |
| 18 | + |
| 19 | +FROM go-${TARGETOS} AS build-base-alpine |
| 20 | +COPY --from=xx / / |
| 21 | +RUN apk add --no-cache clang lld llvm file git |
| 22 | +WORKDIR /go/src/github.com/docker/cli |
| 23 | + |
| 24 | +FROM build-base-alpine AS build-alpine |
| 25 | +ARG TARGETPLATFORM |
| 26 | +# gcc is installed for libgcc only |
| 27 | +RUN xx-apk add --no-cache musl-dev gcc |
| 28 | + |
| 29 | +FROM go-${TARGETOS} AS build-base-buster |
| 30 | +COPY --from=xx / / |
| 31 | +RUN apt-get update && apt-get install --no-install-recommends -y clang lld file |
| 32 | +WORKDIR /go/src/github.com/docker/cli |
| 33 | + |
| 34 | +FROM build-base-buster AS build-buster |
| 35 | +ARG TARGETPLATFORM |
| 36 | +RUN xx-apt install --no-install-recommends -y libc6-dev libgcc-8-dev |
| 37 | + |
| 38 | +FROM build-${BASE_VARIANT} AS build |
| 39 | +# GO_LINKMODE defines if static or dynamic binary should be produced |
| 40 | +ARG GO_LINKMODE=static |
| 41 | +# GO_BUILDTAGS defines additional build tags |
| 42 | +ARG GO_BUILDTAGS |
| 43 | +# GO_STRIP strips debugging symbols if set |
| 44 | +ARG GO_STRIP |
| 45 | +# CGO_ENABLED manually sets if cgo is used |
| 46 | +ARG CGO_ENABLED |
| 47 | +# VERSION sets the version for the produced binary |
| 48 | +ARG VERSION |
| 49 | +RUN --mount=ro --mount=type=cache,target=/root/.cache \ |
| 50 | + --mount=from=dockercore/golang-cross:xx-sdk-extras,target=/xx-sdk,src=/xx-sdk \ |
| 51 | + --mount=type=tmpfs,target=cli/winresources \ |
| 52 | + xx-go --wrap && \ |
| 53 | + # export GOCACHE=$(go env GOCACHE)/$(xx-info)$([ -f /etc/alpine-release ] && echo "alpine") && \ |
| 54 | + TARGET=/out ./scripts/build/binary && \ |
| 55 | + xx-verify $([ "$GO_LINKMODE" = "static" ] && echo "--static") /out/docker |
| 56 | + |
| 57 | +FROM build-base-${BASE_VARIANT} AS dev |
| 58 | +COPY . . |
| 59 | + |
| 60 | +FROM scratch AS binary |
| 61 | +COPY --from=build /out . |
0 commit comments