11# syntax=docker/dockerfile:1
22# check=skip=InvalidBaseImagePlatform
33
4- # ALPINE_VERSION sets the Alpine Linux version for all Alpine stages
5- ARG ALPINE_VERSION=3.20
6- # GO_VERSION sets the Go version for the base stage
4+ ARG ALPINE_VERSION=3.21
75ARG GO_VERSION=1.23
8- # HTMLTEST_VERSION sets the wjdp/htmltest version for HTML testing
96ARG HTMLTEST_VERSION=0.17.0
10- # HUGO_VERSION sets the version of Hugo to build the site with
11- ARG HUGO_VERSION=0.136.3
7+ ARG HUGO_VERSION=0.139.0
8+ ARG NODE_VERSION=22
9+ ARG PAGEFIND_VERSION=1.1.1
1210
13- # build-base is the base stage used for building the site
14- FROM ghcr.io/gohugoio/hugo:v${HUGO_VERSION} AS build-base
11+ # base defines the generic base stage
12+ FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
13+ RUN apk add --no-cache \
14+ git \
15+ nodejs \
16+ npm \
17+ gcompat
18+
19+ # npm downloads Node.js dependencies
20+ FROM base AS npm
1521ENV NODE_ENV="production"
22+ WORKDIR /out
1623RUN --mount=source=package.json,target=package.json \
1724 --mount=source=package-lock.json,target=package-lock.json \
1825 --mount=type=cache,target=/root/.npm \
1926 npm ci
27+
28+ # hugo downloads the Hugo binary
29+ FROM base AS hugo
30+ ARG TARGETARCH
31+ ARG HUGO_VERSION
32+ WORKDIR /out
33+ ADD https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-${TARGETARCH}.tar.gz .
34+ RUN tar xvf hugo_extended_${HUGO_VERSION}_linux-${TARGETARCH}.tar.gz
35+
36+ # build-base is the base stage used for building the site
37+ FROM base AS build-base
38+ WORKDIR /project
39+ COPY --from=hugo /out/hugo /bin/hugo
40+ COPY --from=npm /out/node_modules node_modules
2041COPY . .
2142
2243# build creates production builds with Hugo
@@ -25,7 +46,9 @@ FROM build-base AS build
2546ARG HUGO_ENV="development"
2647# DOCS_URL sets the base URL for the site
2748ARG DOCS_URL="https://docs.docker.com"
28- RUN hugo --gc --minify -e $HUGO_ENV -b $DOCS_URL
49+ ENV HUGO_CACHEDIR="/tmp/hugo_cache"
50+ RUN --mount=type=cache,target=/tmp/hugo_cache \
51+ hugo --gc --minify -e $HUGO_ENV -b $DOCS_URL
2952
3053# lint lints markdown files
3154FROM davidanson/markdownlint-cli2:v0.14.0 AS lint
@@ -61,8 +84,8 @@ RUN hugo mod vendor
6184
6285# vendor is an empty stage with only vendored Hugo modules
6386FROM scratch AS vendor
64- COPY --from=update-modules /src /_vendor /_vendor
65- COPY --from=update-modules /src /go.* /
87+ COPY --from=update-modules /project /_vendor /_vendor
88+ COPY --from=update-modules /project /go.* /
6689
6790# build-upstream builds an upstream project with a replacement module
6891FROM build-base AS build-upstream
@@ -87,10 +110,7 @@ RUN htmltest
87110FROM alpine:${ALPINE_VERSION} AS unused-media
88111RUN apk add --no-cache fd ripgrep
89112WORKDIR /test
90- RUN --mount=type=bind,target=. <<"EOT"
91- set -ex
92- ./scripts/test_unused_media.sh
93- EOT
113+ RUN --mount=type=bind,target=. ./hack/test/unused_media
94114
95115# path-warnings checks for duplicate target paths
96116FROM build-base AS path-warnings
105125EOT
106126
107127# pagefind installs the Pagefind runtime
108- FROM node:alpine${ALPINE_VERSION} AS pagefind
109- ARG PAGEFIND_VERSION=1.1.1
128+ FROM base AS pagefind
129+ ARG PAGEFIND_VERSION
110130COPY --from=build /project/public ./public
111131RUN --mount=type=bind,src=pagefind.yml,target=pagefind.yml \
112132 npx pagefind@v${PAGEFIND_VERSION} --output-path "/pagefind"
@@ -122,7 +142,7 @@ RUN apk add yq
122142COPY --from=build /project/public ./public
123143RUN --mount=type=bind,target=. <<"EOT"
124144set -ex
125- ./scripts/test_go_redirects.sh
145+ ./hack/test/go_redirects
126146EOT
127147
128148# release is an empty scratch image with only compiled assets
0 commit comments