2022-08-19 10:50:01 -04:00
|
|
|
# syntax=docker/dockerfile:1
|
2021-03-03 02:03:02 -05:00
|
|
|
|
|
|
|
ARG BASE_VARIANT=alpine
|
2022-11-05 12:48:35 -04:00
|
|
|
ARG GO_VERSION=1.18.8
|
2022-12-04 08:01:30 -05:00
|
|
|
ARG ALPINE_VERSION=3.16
|
2022-03-26 01:57:27 -04:00
|
|
|
ARG XX_VERSION=1.1.0
|
2021-03-03 02:03:02 -05:00
|
|
|
|
2021-09-15 06:47:50 -04:00
|
|
|
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
|
2021-03-03 02:03:02 -05:00
|
|
|
|
2022-12-04 08:01:30 -05:00
|
|
|
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS build-base-alpine
|
2021-03-03 02:03:02 -05:00
|
|
|
COPY --from=xx / /
|
2021-03-05 03:56:55 -05:00
|
|
|
RUN apk add --no-cache clang lld llvm file git
|
2021-03-03 02:03:02 -05:00
|
|
|
WORKDIR /go/src/github.com/docker/cli
|
|
|
|
|
|
|
|
FROM build-base-alpine AS build-alpine
|
|
|
|
ARG TARGETPLATFORM
|
|
|
|
# gcc is installed for libgcc only
|
|
|
|
RUN xx-apk add --no-cache musl-dev gcc
|
|
|
|
|
2021-08-16 23:07:43 -04:00
|
|
|
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-buster AS build-base-buster
|
2021-03-03 02:03:02 -05:00
|
|
|
COPY --from=xx / /
|
|
|
|
RUN apt-get update && apt-get install --no-install-recommends -y clang lld file
|
|
|
|
WORKDIR /go/src/github.com/docker/cli
|
|
|
|
|
|
|
|
FROM build-base-buster AS build-buster
|
|
|
|
ARG TARGETPLATFORM
|
|
|
|
RUN xx-apt install --no-install-recommends -y libc6-dev libgcc-8-dev
|
|
|
|
|
|
|
|
FROM build-${BASE_VARIANT} AS build
|
|
|
|
# GO_LINKMODE defines if static or dynamic binary should be produced
|
|
|
|
ARG GO_LINKMODE=static
|
|
|
|
# GO_BUILDTAGS defines additional build tags
|
|
|
|
ARG GO_BUILDTAGS
|
|
|
|
# GO_STRIP strips debugging symbols if set
|
|
|
|
ARG GO_STRIP
|
|
|
|
# CGO_ENABLED manually sets if cgo is used
|
|
|
|
ARG CGO_ENABLED
|
|
|
|
# VERSION sets the version for the produced binary
|
|
|
|
ARG VERSION
|
|
|
|
RUN --mount=ro --mount=type=cache,target=/root/.cache \
|
|
|
|
--mount=from=dockercore/golang-cross:xx-sdk-extras,target=/xx-sdk,src=/xx-sdk \
|
2021-03-05 03:56:55 -05:00
|
|
|
--mount=type=tmpfs,target=cli/winresources \
|
2021-03-03 02:03:02 -05:00
|
|
|
xx-go --wrap && \
|
|
|
|
# export GOCACHE=$(go env GOCACHE)/$(xx-info)$([ -f /etc/alpine-release ] && echo "alpine") && \
|
|
|
|
TARGET=/out ./scripts/build/binary && \
|
|
|
|
xx-verify $([ "$GO_LINKMODE" = "static" ] && echo "--static") /out/docker
|
|
|
|
|
2022-03-26 01:57:27 -04:00
|
|
|
FROM build-base-${BASE_VARIANT} AS dev
|
2021-03-05 03:56:55 -05:00
|
|
|
COPY . .
|
2021-03-03 02:03:02 -05:00
|
|
|
|
|
|
|
FROM scratch AS binary
|
|
|
|
COPY --from=build /out .
|