11# syntax=docker/dockerfile:1
22# check=skip=InvalidBaseImagePlatform
33
4- # ALPINE_VERSION sets the Alpine Linux version for all Alpine stages
54ARG ALPINE_VERSION=3.20
6- # GO_VERSION sets the Go version for the base stage
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.136.5
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
105128EOT
106129
107130# pagefind installs the Pagefind runtime
108- FROM node:alpine${ALPINE_VERSION} AS pagefind
109- ARG PAGEFIND_VERSION=1.1.1
131+ FROM base AS pagefind
132+ ARG PAGEFIND_VERSION
110133COPY --from=build /project/public ./public
111134RUN --mount=type=bind,src=pagefind.yml,target=pagefind.yml \
112135 npx pagefind@v${PAGEFIND_VERSION} --output-path "/pagefind"
0 commit comments