github.com/panekj/cli@v0.0.0-20230304125325-467dd2f3797e/Dockerfile (about)

     1  # syntax=docker/dockerfile:1
     2  
     3  ARG BASE_VARIANT=alpine
     4  ARG GO_VERSION=1.19.6
     5  ARG ALPINE_VERSION=3.16
     6  ARG XX_VERSION=1.1.1
     7  ARG GOVERSIONINFO_VERSION=v1.3.0
     8  ARG GOTESTSUM_VERSION=v1.8.2
     9  ARG BUILDX_VERSION=0.10.3
    10  
    11  FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
    12  
    13  FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS build-base-alpine
    14  COPY --from=xx / /
    15  RUN apk add --no-cache bash clang lld llvm file git
    16  WORKDIR /go/src/github.com/docker/cli
    17  
    18  FROM build-base-alpine AS build-alpine
    19  ARG TARGETPLATFORM
    20  # gcc is installed for libgcc only
    21  RUN xx-apk add --no-cache musl-dev gcc
    22  
    23  FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-bullseye AS build-base-bullseye
    24  COPY --from=xx / /
    25  RUN apt-get update && apt-get install --no-install-recommends -y bash clang lld llvm file
    26  WORKDIR /go/src/github.com/docker/cli
    27  
    28  FROM build-base-bullseye AS build-bullseye
    29  ARG TARGETPLATFORM
    30  RUN xx-apt-get install --no-install-recommends -y libc6-dev libgcc-10-dev
    31  # workaround for issue with llvm 11 for darwin/amd64 platform:
    32  #  # github.com/docker/cli/cmd/docker
    33  #  /usr/local/go/pkg/tool/linux_amd64/link: /usr/local/go/pkg/tool/linux_amd64/link: running strip failed: exit status 1
    34  #  llvm-strip: error: unsupported load command (cmd=0x5)
    35  # more info: https://github.com/docker/cli/pull/3717
    36  # FIXME: remove once llvm 12 available on debian
    37  RUN [ "$TARGETPLATFORM" != "darwin/amd64" ] || ln -sfnT /bin/true /usr/bin/llvm-strip
    38  
    39  FROM build-base-${BASE_VARIANT} AS goversioninfo
    40  ARG GOVERSIONINFO_VERSION
    41  RUN --mount=type=cache,target=/root/.cache/go-build \
    42      --mount=type=cache,target=/go/pkg/mod \
    43      GOBIN=/out GO111MODULE=on go install "github.com/josephspurrier/goversioninfo/cmd/goversioninfo@${GOVERSIONINFO_VERSION}"
    44  
    45  FROM build-base-${BASE_VARIANT} AS gotestsum
    46  ARG GOTESTSUM_VERSION
    47  RUN --mount=type=cache,target=/root/.cache/go-build \
    48      --mount=type=cache,target=/go/pkg/mod \
    49      GOBIN=/out GO111MODULE=on go install "gotest.tools/gotestsum@${GOTESTSUM_VERSION}" \
    50      && /out/gotestsum --version
    51  
    52  FROM build-${BASE_VARIANT} AS build
    53  # GO_LINKMODE defines if static or dynamic binary should be produced
    54  ARG GO_LINKMODE=static
    55  # GO_BUILDTAGS defines additional build tags
    56  ARG GO_BUILDTAGS
    57  # GO_STRIP strips debugging symbols if set
    58  ARG GO_STRIP
    59  # CGO_ENABLED manually sets if cgo is used
    60  ARG CGO_ENABLED
    61  # VERSION sets the version for the produced binary
    62  ARG VERSION
    63  # PACKAGER_NAME sets the company that produced the windows binary
    64  ARG PACKAGER_NAME
    65  COPY --from=goversioninfo /out/goversioninfo /usr/bin/goversioninfo
    66  # in bullseye arm64 target does not link with lld so configure it to use ld instead
    67  RUN [ ! -f /etc/alpine-release ] && xx-info is-cross && [ "$(xx-info arch)" = "arm64" ] && XX_CC_PREFER_LINKER=ld xx-clang --setup-target-triple || true
    68  RUN --mount=type=bind,target=.,ro \
    69      --mount=type=cache,target=/root/.cache \
    70      --mount=from=dockercore/golang-cross:xx-sdk-extras,target=/xx-sdk,src=/xx-sdk \
    71      --mount=type=tmpfs,target=cli/winresources \
    72      # override the default behavior of go with xx-go
    73      xx-go --wrap && \
    74      # export GOCACHE=$(go env GOCACHE)/$(xx-info)$([ -f /etc/alpine-release ] && echo "alpine") && \
    75      TARGET=/out ./scripts/build/binary && \
    76      xx-verify $([ "$GO_LINKMODE" = "static" ] && echo "--static") /out/docker
    77  
    78  FROM build-${BASE_VARIANT} AS test
    79  COPY --from=gotestsum /out/gotestsum /usr/bin/gotestsum
    80  ENV GO111MODULE=auto
    81  RUN --mount=type=bind,target=.,rw \
    82      --mount=type=cache,target=/root/.cache \
    83      --mount=type=cache,target=/go/pkg/mod \
    84      gotestsum -- -coverprofile=/tmp/coverage.txt $(go list ./... | grep -vE '/vendor/|/e2e/')
    85  
    86  FROM scratch AS test-coverage
    87  COPY --from=test /tmp/coverage.txt /coverage.txt
    88  
    89  FROM build-${BASE_VARIANT} AS build-plugins
    90  ARG GO_LINKMODE=static
    91  ARG GO_BUILDTAGS
    92  ARG GO_STRIP
    93  ARG CGO_ENABLED
    94  ARG VERSION
    95  RUN --mount=ro --mount=type=cache,target=/root/.cache \
    96      --mount=from=dockercore/golang-cross:xx-sdk-extras,target=/xx-sdk,src=/xx-sdk \
    97      xx-go --wrap && \
    98      TARGET=/out ./scripts/build/plugins e2e/cli-plugins/plugins/*
    99  
   100  FROM build-base-alpine AS e2e-base-alpine
   101  RUN apk add --no-cache build-base curl docker-compose openssl openssh-client
   102  
   103  FROM build-base-bullseye AS e2e-base-bullseye
   104  RUN apt-get update && apt-get install -y build-essential curl openssl openssh-client
   105  ARG COMPOSE_VERSION=1.29.2
   106  RUN curl -fsSL https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose && \
   107      chmod +x /usr/local/bin/docker-compose
   108  
   109  FROM docker/buildx-bin:${BUILDX_VERSION} AS buildx
   110  
   111  FROM e2e-base-${BASE_VARIANT} AS e2e
   112  ARG NOTARY_VERSION=v0.6.1
   113  ADD --chmod=0755 https://github.com/theupdateframework/notary/releases/download/${NOTARY_VERSION}/notary-Linux-amd64 /usr/local/bin/notary
   114  COPY e2e/testdata/notary/root-ca.cert /usr/share/ca-certificates/notary.cert
   115  RUN echo 'notary.cert' >> /etc/ca-certificates.conf && update-ca-certificates
   116  COPY --from=gotestsum /out/gotestsum /usr/bin/gotestsum
   117  COPY --from=build /out ./build/
   118  COPY --from=build-plugins /out ./build/
   119  COPY --from=buildx /buildx /usr/libexec/docker/cli-plugins/docker-buildx
   120  COPY . .
   121  ENV DOCKER_BUILDKIT=1
   122  ENV PATH=/go/src/github.com/docker/cli/build:$PATH
   123  CMD ./scripts/test/e2e/entry
   124  
   125  FROM build-base-${BASE_VARIANT} AS dev
   126  COPY . .
   127  
   128  FROM scratch AS binary
   129  COPY --from=build /out .
   130  
   131  FROM scratch AS plugins
   132  COPY --from=build-plugins /out .