Dockerfile: use COPY --link where possible

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit af05a68828)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-08-25 01:56:35 +02:00
parent 1f8118b1cc
commit e7ca37861b
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
3 changed files with 17 additions and 17 deletions

View File

@ -11,7 +11,7 @@ ARG BUILDX_VERSION=0.11.2
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS build-base-alpine FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS build-base-alpine
COPY --from=xx / / COPY --link --from=xx / /
RUN apk add --no-cache bash clang lld llvm file git RUN apk add --no-cache bash clang lld llvm file git
WORKDIR /go/src/github.com/docker/cli WORKDIR /go/src/github.com/docker/cli
@ -21,7 +21,7 @@ ARG TARGETPLATFORM
RUN xx-apk add --no-cache musl-dev gcc RUN xx-apk add --no-cache musl-dev gcc
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-bullseye AS build-base-bullseye FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-bullseye AS build-base-bullseye
COPY --from=xx / / COPY --link --from=xx / /
RUN apt-get update && apt-get install --no-install-recommends -y bash clang lld llvm file RUN apt-get update && apt-get install --no-install-recommends -y bash clang lld llvm file
WORKDIR /go/src/github.com/docker/cli WORKDIR /go/src/github.com/docker/cli
@ -62,7 +62,7 @@ ARG CGO_ENABLED
ARG VERSION ARG VERSION
# PACKAGER_NAME sets the company that produced the windows binary # PACKAGER_NAME sets the company that produced the windows binary
ARG PACKAGER_NAME ARG PACKAGER_NAME
COPY --from=goversioninfo /out/goversioninfo /usr/bin/goversioninfo COPY --link --from=goversioninfo /out/goversioninfo /usr/bin/goversioninfo
# in bullseye arm64 target does not link with lld so configure it to use ld instead # in bullseye arm64 target does not link with lld so configure it to use ld instead
RUN [ ! -f /etc/alpine-release ] && xx-info is-cross && [ "$(xx-info arch)" = "arm64" ] && XX_CC_PREFER_LINKER=ld xx-clang --setup-target-triple || true RUN [ ! -f /etc/alpine-release ] && xx-info is-cross && [ "$(xx-info arch)" = "arm64" ] && XX_CC_PREFER_LINKER=ld xx-clang --setup-target-triple || true
RUN --mount=type=bind,target=.,ro \ RUN --mount=type=bind,target=.,ro \
@ -76,7 +76,7 @@ RUN --mount=type=bind,target=.,ro \
xx-verify $([ "$GO_LINKMODE" = "static" ] && echo "--static") /out/docker xx-verify $([ "$GO_LINKMODE" = "static" ] && echo "--static") /out/docker
FROM build-${BASE_VARIANT} AS test FROM build-${BASE_VARIANT} AS test
COPY --from=gotestsum /out/gotestsum /usr/bin/gotestsum COPY --link --from=gotestsum /out/gotestsum /usr/bin/gotestsum
ENV GO111MODULE=auto ENV GO111MODULE=auto
RUN --mount=type=bind,target=.,rw \ RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/root/.cache \ --mount=type=cache,target=/root/.cache \
@ -111,19 +111,19 @@ FROM docker/buildx-bin:${BUILDX_VERSION} AS buildx
FROM e2e-base-${BASE_VARIANT} AS e2e FROM e2e-base-${BASE_VARIANT} AS e2e
ARG NOTARY_VERSION=v0.6.1 ARG NOTARY_VERSION=v0.6.1
ADD --chmod=0755 https://github.com/theupdateframework/notary/releases/download/${NOTARY_VERSION}/notary-Linux-amd64 /usr/local/bin/notary ADD --chmod=0755 https://github.com/theupdateframework/notary/releases/download/${NOTARY_VERSION}/notary-Linux-amd64 /usr/local/bin/notary
COPY e2e/testdata/notary/root-ca.cert /usr/share/ca-certificates/notary.cert COPY --link e2e/testdata/notary/root-ca.cert /usr/share/ca-certificates/notary.cert
RUN echo 'notary.cert' >> /etc/ca-certificates.conf && update-ca-certificates RUN echo 'notary.cert' >> /etc/ca-certificates.conf && update-ca-certificates
COPY --from=gotestsum /out/gotestsum /usr/bin/gotestsum COPY --link --from=gotestsum /out/gotestsum /usr/bin/gotestsum
COPY --from=build /out ./build/ COPY --link --from=build /out ./build/
COPY --from=build-plugins /out ./build/ COPY --link --from=build-plugins /out ./build/
COPY --from=buildx /buildx /usr/libexec/docker/cli-plugins/docker-buildx COPY --link --from=buildx /buildx /usr/libexec/docker/cli-plugins/docker-buildx
COPY . . COPY --link . .
ENV DOCKER_BUILDKIT=1 ENV DOCKER_BUILDKIT=1
ENV PATH=/go/src/github.com/docker/cli/build:$PATH ENV PATH=/go/src/github.com/docker/cli/build:$PATH
CMD ./scripts/test/e2e/entry CMD ./scripts/test/e2e/entry
FROM build-base-${BASE_VARIANT} AS dev FROM build-base-${BASE_VARIANT} AS dev
COPY . . COPY --link . .
FROM scratch AS plugins FROM scratch AS plugins
COPY --from=build-plugins /out . COPY --from=build-plugins /out .

View File

@ -48,11 +48,11 @@ CMD bash
ENV DISABLE_WARN_OUTSIDE_CONTAINER=1 ENV DISABLE_WARN_OUTSIDE_CONTAINER=1
ENV PATH=$PATH:/go/src/github.com/docker/cli/build ENV PATH=$PATH:/go/src/github.com/docker/cli/build
COPY --from=buildx /buildx /usr/libexec/docker/cli-plugins/docker-buildx COPY --link --from=buildx /buildx /usr/libexec/docker/cli-plugins/docker-buildx
COPY --from=gofumpt /go/bin/* /go/bin/ COPY --link --from=gofumpt /go/bin/* /go/bin/
COPY --from=gotestsum /go/bin/* /go/bin/ COPY --link --from=gotestsum /go/bin/* /go/bin/
COPY --from=goversioninfo /go/bin/* /go/bin/ COPY --link --from=goversioninfo /go/bin/* /go/bin/
WORKDIR /go/src/github.com/docker/cli WORKDIR /go/src/github.com/docker/cli
ENV GO111MODULE=auto ENV GO111MODULE=auto
COPY . . COPY --link . .

View File

@ -11,7 +11,7 @@ ENV GO111MODULE=off
ENV CGO_ENABLED=0 ENV CGO_ENABLED=0
ENV GOGC=75 ENV GOGC=75
WORKDIR /go/src/github.com/docker/cli WORKDIR /go/src/github.com/docker/cli
COPY --from=golangci-lint /usr/bin/golangci-lint /usr/bin/golangci-lint COPY --link --from=golangci-lint /usr/bin/golangci-lint /usr/bin/golangci-lint
RUN --mount=type=bind,target=. \ RUN --mount=type=bind,target=. \
--mount=type=cache,target=/root/.cache \ --mount=type=cache,target=/root/.cache \
golangci-lint run golangci-lint run