From 6018f8551d20608314eb0ccb0fc59af8261865aa Mon Sep 17 00:00:00 2001 From: David Karlsson <35727626+dvdksn@users.noreply.github.com> Date: Thu, 4 Jul 2024 16:07:13 +0200 Subject: [PATCH] build: deduplicate context transfers with bake Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com> --- Dockerfile | 13 ++++++++----- docker-bake.hcl | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index ff300d946e..55f83ba780 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,11 +26,14 @@ WORKDIR /tmp/hugo RUN wget -O "hugo.tar.gz" "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-${TARGETARCH}.tar.gz" RUN tar -xf "hugo.tar.gz" hugo +FROM scratch AS ctx +COPY --link . . + # build-base is the base stage for building the site FROM base AS build-base COPY --from=hugo /tmp/hugo/hugo /bin/hugo COPY --from=node /src/node_modules /src/node_modules -COPY . . +COPY --from=ctx . . # dev is for local development with Docker Compose FROM build-base AS dev @@ -46,7 +49,7 @@ RUN hugo --gc --minify -d /out -e $HUGO_ENV -b $DOCS_URL # lint lints markdown files FROM davidanson/markdownlint-cli2:v0.12.1 AS lint USER root -RUN --mount=type=bind,target=. \ +RUN --mount=type=bind,from=ctx,target=. \ /usr/local/bin/markdownlint-cli2 \ "content/**/*.md" \ "#content/engine/release-notes/*.md" \ @@ -103,7 +106,7 @@ RUN htmltest FROM alpine:${ALPINE_VERSION} AS unused-media RUN apk add --no-cache fd ripgrep WORKDIR /test -RUN --mount=type=bind,target=. <<"EOT" +RUN --mount=type=bind,from=ctx,target=. <<"EOT" set -ex ./scripts/test_unused_media.sh EOT @@ -112,7 +115,7 @@ EOT FROM base AS pagefind ARG PAGEFIND_VERSION=1.1.0 COPY --from=build /out ./public -RUN --mount=type=bind,src=pagefind.yml,target=pagefind.yml \ +RUN --mount=type=bind,from=ctx,src=pagefind.yml,target=pagefind.yml \ npx pagefind@v${PAGEFIND_VERSION} --output-path "/pagefind" # index generates a Pagefind index @@ -124,7 +127,7 @@ FROM alpine:${ALPINE_VERSION} AS test-go-redirects WORKDIR /work RUN apk add yq COPY --from=build /out ./public -RUN --mount=type=bind,target=. <<"EOT" +RUN --mount=type=bind,from=ctx,target=. <<"EOT" set -ex ./scripts/test_go_redirects.sh EOT diff --git a/docker-bake.hcl b/docker-bake.hcl index 18e64f5a83..ccc90979af 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -17,13 +17,29 @@ group "default" { targets = ["release"] } +target "ctx" { + target = "ctx" + context = "." + output = ["type=cacheonly"] + provenance = false +} + +target "_common" { + contexts = { + ctx = "target:ctx" + } +} + target "index" { + inherits = ["_common"] # generate a new local search index target = "index" output = ["type=local,dest=static/pagefind"] + provenance = false } target "release" { + inherits = ["_common"] args = { HUGO_ENV = HUGO_ENV DOCS_URL = DOCS_URL @@ -38,22 +54,30 @@ group "validate" { target "test" { target = "test" + inherits = ["_common"] output = ["type=cacheonly"] + provenance = false } target "lint" { target = "lint" + inherits = ["_common"] output = ["type=cacheonly"] + provenance = false } target "unused-media" { target = "unused-media" + inherits = ["_common"] output = ["type=cacheonly"] + provenance = false } target "test-go-redirects" { target = "test-go-redirects" + inherits = ["_common"] output = ["type=cacheonly"] + provenance = false } #