mirror of https://github.com/docker/docs.git
bake: shared session for local context
With the latest Buildx, BuildKit, and Dockerfile, bake can detect when multiple targets use the same local context, and deduplicate context transfer. Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
This commit is contained in:
parent
8e1a75c658
commit
dcd1ba4a33
15
Dockerfile
15
Dockerfile
|
|
@ -1,4 +1,4 @@
|
||||||
# syntax=docker/dockerfile:1
|
# syntax=docker/dockerfile-upstream:master
|
||||||
|
|
||||||
# ALPINE_VERSION sets the Alpine Linux version for all Alpine stages
|
# ALPINE_VERSION sets the Alpine Linux version for all Alpine stages
|
||||||
ARG ALPINE_VERSION=3.20
|
ARG ALPINE_VERSION=3.20
|
||||||
|
|
@ -26,14 +26,11 @@ 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 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
|
RUN tar -xf "hugo.tar.gz" hugo
|
||||||
|
|
||||||
FROM scratch AS ctx
|
|
||||||
COPY --link . .
|
|
||||||
|
|
||||||
# build-base is the base stage for building the site
|
# build-base is the base stage for building the site
|
||||||
FROM base AS build-base
|
FROM base AS build-base
|
||||||
COPY --from=hugo /tmp/hugo/hugo /bin/hugo
|
COPY --from=hugo /tmp/hugo/hugo /bin/hugo
|
||||||
COPY --from=node /src/node_modules /src/node_modules
|
COPY --from=node /src/node_modules /src/node_modules
|
||||||
COPY --from=ctx . .
|
COPY . .
|
||||||
|
|
||||||
# dev is for local development with Docker Compose
|
# dev is for local development with Docker Compose
|
||||||
FROM build-base AS dev
|
FROM build-base AS dev
|
||||||
|
|
@ -49,7 +46,7 @@ RUN hugo --gc --minify -d /out -e $HUGO_ENV -b $DOCS_URL
|
||||||
# lint lints markdown files
|
# lint lints markdown files
|
||||||
FROM davidanson/markdownlint-cli2:v0.12.1 AS lint
|
FROM davidanson/markdownlint-cli2:v0.12.1 AS lint
|
||||||
USER root
|
USER root
|
||||||
RUN --mount=type=bind,from=ctx,target=. \
|
RUN --mount=type=bind,target=. \
|
||||||
/usr/local/bin/markdownlint-cli2 \
|
/usr/local/bin/markdownlint-cli2 \
|
||||||
"content/**/*.md" \
|
"content/**/*.md" \
|
||||||
"#content/engine/release-notes/*.md" \
|
"#content/engine/release-notes/*.md" \
|
||||||
|
|
@ -106,7 +103,7 @@ RUN htmltest
|
||||||
FROM alpine:${ALPINE_VERSION} AS unused-media
|
FROM alpine:${ALPINE_VERSION} AS unused-media
|
||||||
RUN apk add --no-cache fd ripgrep
|
RUN apk add --no-cache fd ripgrep
|
||||||
WORKDIR /test
|
WORKDIR /test
|
||||||
RUN --mount=type=bind,from=ctx,target=. <<"EOT"
|
RUN --mount=type=bind,target=. <<"EOT"
|
||||||
set -ex
|
set -ex
|
||||||
./scripts/test_unused_media.sh
|
./scripts/test_unused_media.sh
|
||||||
EOT
|
EOT
|
||||||
|
|
@ -115,7 +112,7 @@ EOT
|
||||||
FROM base AS pagefind
|
FROM base AS pagefind
|
||||||
ARG PAGEFIND_VERSION=1.1.0
|
ARG PAGEFIND_VERSION=1.1.0
|
||||||
COPY --from=build /out ./public
|
COPY --from=build /out ./public
|
||||||
RUN --mount=type=bind,from=ctx,src=pagefind.yml,target=pagefind.yml \
|
RUN --mount=type=bind,src=pagefind.yml,target=pagefind.yml \
|
||||||
npx pagefind@v${PAGEFIND_VERSION} --output-path "/pagefind"
|
npx pagefind@v${PAGEFIND_VERSION} --output-path "/pagefind"
|
||||||
|
|
||||||
# index generates a Pagefind index
|
# index generates a Pagefind index
|
||||||
|
|
@ -127,7 +124,7 @@ FROM alpine:${ALPINE_VERSION} AS test-go-redirects
|
||||||
WORKDIR /work
|
WORKDIR /work
|
||||||
RUN apk add yq
|
RUN apk add yq
|
||||||
COPY --from=build /out ./public
|
COPY --from=build /out ./public
|
||||||
RUN --mount=type=bind,from=ctx,target=. <<"EOT"
|
RUN --mount=type=bind,target=. <<"EOT"
|
||||||
set -ex
|
set -ex
|
||||||
./scripts/test_go_redirects.sh
|
./scripts/test_go_redirects.sh
|
||||||
EOT
|
EOT
|
||||||
|
|
|
||||||
|
|
@ -14,21 +14,7 @@ group "default" {
|
||||||
targets = ["release"]
|
targets = ["release"]
|
||||||
}
|
}
|
||||||
|
|
||||||
target "ctx" {
|
|
||||||
target = "ctx"
|
|
||||||
context = "."
|
|
||||||
output = ["type=cacheonly"]
|
|
||||||
provenance = false
|
|
||||||
}
|
|
||||||
|
|
||||||
target "_common" {
|
|
||||||
contexts = {
|
|
||||||
ctx = "target:ctx"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
target "index" {
|
target "index" {
|
||||||
inherits = ["_common"]
|
|
||||||
# generate a new local search index
|
# generate a new local search index
|
||||||
target = "index"
|
target = "index"
|
||||||
output = ["type=local,dest=static/pagefind"]
|
output = ["type=local,dest=static/pagefind"]
|
||||||
|
|
@ -36,7 +22,6 @@ target "index" {
|
||||||
}
|
}
|
||||||
|
|
||||||
target "release" {
|
target "release" {
|
||||||
inherits = ["_common"]
|
|
||||||
args = {
|
args = {
|
||||||
HUGO_ENV = HUGO_ENV
|
HUGO_ENV = HUGO_ENV
|
||||||
DOCS_URL = DOCS_URL
|
DOCS_URL = DOCS_URL
|
||||||
|
|
@ -52,28 +37,24 @@ group "validate" {
|
||||||
|
|
||||||
target "test" {
|
target "test" {
|
||||||
target = "test"
|
target = "test"
|
||||||
inherits = ["_common"]
|
|
||||||
output = ["type=cacheonly"]
|
output = ["type=cacheonly"]
|
||||||
provenance = false
|
provenance = false
|
||||||
}
|
}
|
||||||
|
|
||||||
target "lint" {
|
target "lint" {
|
||||||
target = "lint"
|
target = "lint"
|
||||||
inherits = ["_common"]
|
|
||||||
output = ["type=cacheonly"]
|
output = ["type=cacheonly"]
|
||||||
provenance = false
|
provenance = false
|
||||||
}
|
}
|
||||||
|
|
||||||
target "unused-media" {
|
target "unused-media" {
|
||||||
target = "unused-media"
|
target = "unused-media"
|
||||||
inherits = ["_common"]
|
|
||||||
output = ["type=cacheonly"]
|
output = ["type=cacheonly"]
|
||||||
provenance = false
|
provenance = false
|
||||||
}
|
}
|
||||||
|
|
||||||
target "test-go-redirects" {
|
target "test-go-redirects" {
|
||||||
target = "test-go-redirects"
|
target = "test-go-redirects"
|
||||||
inherits = ["_common"]
|
|
||||||
output = ["type=cacheonly"]
|
output = ["type=cacheonly"]
|
||||||
provenance = false
|
provenance = false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue