From 12a19dcd84a2935b075524b29773aca412935de9 Mon Sep 17 00:00:00 2001 From: Bjorn Neergaard Date: Mon, 17 Jul 2023 09:50:27 -0600 Subject: [PATCH] Dockerfile: improve CLI/rootlesskit caching Use bind-mounts instead of a `COPY` for cli.sh, and use `COPY --link` for rootlesskit's build stage. Signed-off-by: Bjorn Neergaard --- Dockerfile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 07208a5f9f..32cdcac433 100644 --- a/Dockerfile +++ b/Dockerfile @@ -251,11 +251,11 @@ RUN --mount=type=cache,target=/root/.cache/go-build \ FROM base AS dockercli WORKDIR /go/src/github.com/docker/cli -COPY hack/dockerfile/cli.sh /download-or-build-cli.sh ARG DOCKERCLI_REPOSITORY ARG DOCKERCLI_VERSION ARG TARGETPLATFORM -RUN --mount=type=cache,id=dockercli-git-$TARGETPLATFORM,sharing=locked,target=./.git \ +RUN --mount=source=hack/dockerfile/cli.sh,target=/download-or-build-cli.sh \ + --mount=type=cache,id=dockercli-git-$TARGETPLATFORM,sharing=locked,target=./.git \ --mount=type=cache,target=/root/.cache/go-build,id=dockercli-build-$TARGETPLATFORM \ rm -f ./.git/*.lock \ && /download-or-build-cli.sh ${DOCKERCLI_VERSION} ${DOCKERCLI_REPOSITORY} /build \ @@ -263,12 +263,12 @@ RUN --mount=type=cache,id=dockercli-git-$TARGETPLATFORM,sharing=locked,target=./ FROM base AS dockercli-integration WORKDIR /go/src/github.com/docker/cli -COPY hack/dockerfile/cli.sh /download-or-build-cli.sh ARG DOCKERCLI_INTEGRATION_REPOSITORY ARG DOCKERCLI_INTEGRATION_VERSION ARG TARGETPLATFORM -RUN --mount=type=cache,id=dockercli-integration-git-$TARGETPLATFORM,sharing=locked,target=./.git \ - --mount=type=cache,target=/root/.cache/go-build,id=dockercli-integration-build-$TARGETPLATFORM \ +RUN --mount=source=hack/dockerfile/cli.sh,target=/download-or-build-cli.sh \ + --mount=type=cache,id=dockercli-git-$TARGETPLATFORM,sharing=locked,target=./.git \ + --mount=type=cache,target=/root/.cache/go-build,id=dockercli-build-$TARGETPLATFORM \ rm -f ./.git/*.lock \ && /download-or-build-cli.sh ${DOCKERCLI_INTEGRATION_VERSION} ${DOCKERCLI_INTEGRATION_REPOSITORY} /build \ && /build/docker --version @@ -369,8 +369,8 @@ RUN --mount=from=rootlesskit-src,src=/usr/src/rootlesskit,rw \ xx-go build -o /build/rootlesskit-docker-proxy -ldflags="$([ "$DOCKER_STATIC" != "1" ] && echo "-linkmode=external")" ./cmd/rootlesskit-docker-proxy xx-verify $([ "$DOCKER_STATIC" = "1" ] && echo "--static") /build/rootlesskit-docker-proxy EOT -COPY ./contrib/dockerd-rootless.sh /build/ -COPY ./contrib/dockerd-rootless-setuptool.sh /build/ +COPY --link ./contrib/dockerd-rootless.sh /build/ +COPY --link ./contrib/dockerd-rootless-setuptool.sh /build/ FROM rootlesskit-build AS rootlesskit-linux FROM binary-dummy AS rootlesskit-windows