From 0c6604d128ecf397ad76c233d9d8bf5ce3d6b477 Mon Sep 17 00:00:00 2001 From: David Karlsson <35727626+dvdksn@users.noreply.github.com> Date: Thu, 31 Oct 2024 09:35:02 +0100 Subject: [PATCH 1/3] hugo: use a custom hugo setup This reverts the use of the official Hugo image since it doesn't run with root privileges, causing a number of unexpected issues. Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com> --- Dockerfile | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0489b3ef64..6b4a5ba261 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,43 @@ # syntax=docker/dockerfile:1 # check=skip=InvalidBaseImagePlatform -# ALPINE_VERSION sets the Alpine Linux version for all Alpine stages ARG ALPINE_VERSION=3.20 -# GO_VERSION sets the Go version for the base stage ARG GO_VERSION=1.23 -# HTMLTEST_VERSION sets the wjdp/htmltest version for HTML testing ARG HTMLTEST_VERSION=0.17.0 -# HUGO_VERSION sets the version of Hugo to build the site with ARG HUGO_VERSION=0.136.3 +ARG NODE_VERSION=22 +ARG PAGEFIND_VERSION=1.1.1 -# build-base is the base stage used for building the site -FROM ghcr.io/gohugoio/hugo:v${HUGO_VERSION} AS build-base +# base defines the generic base stage +FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base +RUN apk add --no-cache \ + git \ + nodejs \ + npm \ + gcompat + +# npm downloads Node.js dependencies +FROM base AS npm ENV NODE_ENV="production" +WORKDIR /out RUN --mount=source=package.json,target=package.json \ --mount=source=package-lock.json,target=package-lock.json \ --mount=type=cache,target=/root/.npm \ npm ci + +# hugo downloads the Hugo binary +FROM base AS hugo +ARG TARGETARCH +ARG HUGO_VERSION +WORKDIR /out +ADD https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-${TARGETARCH}.tar.gz . +RUN tar xvf hugo_extended_${HUGO_VERSION}_linux-${TARGETARCH}.tar.gz + +# build-base is the base stage used for building the site +FROM base AS build-base +WORKDIR /project +COPY --from=hugo /out/hugo /bin/hugo +COPY --from=npm /out/node_modules node_modules COPY . . # build creates production builds with Hugo @@ -25,7 +46,9 @@ FROM build-base AS build ARG HUGO_ENV="development" # DOCS_URL sets the base URL for the site ARG DOCS_URL="https://docs.docker.com" -RUN hugo --gc --minify -e $HUGO_ENV -b $DOCS_URL +ENV HUGO_CACHEDIR="/tmp/hugo_cache" +RUN --mount=type=cache,target=/tmp/hugo_cache \ + hugo --gc --minify -e $HUGO_ENV -b $DOCS_URL # lint lints markdown files FROM davidanson/markdownlint-cli2:v0.14.0 AS lint @@ -105,8 +128,8 @@ fi EOT # pagefind installs the Pagefind runtime -FROM node:alpine${ALPINE_VERSION} AS pagefind -ARG PAGEFIND_VERSION=1.1.1 +FROM base AS pagefind +ARG PAGEFIND_VERSION COPY --from=build /project/public ./public RUN --mount=type=bind,src=pagefind.yml,target=pagefind.yml \ npx pagefind@v${PAGEFIND_VERSION} --output-path "/pagefind" From f909620f8f85a82a55739bcb82334221f9c3bede Mon Sep 17 00:00:00 2001 From: David Karlsson <35727626+dvdksn@users.noreply.github.com> Date: Thu, 31 Oct 2024 09:36:54 +0100 Subject: [PATCH 2/3] hugo: update hugo to v0.136.5 Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com> --- Dockerfile | 2 +- netlify.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6b4a5ba261..bc48dcee3b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ARG ALPINE_VERSION=3.20 ARG GO_VERSION=1.23 ARG HTMLTEST_VERSION=0.17.0 -ARG HUGO_VERSION=0.136.3 +ARG HUGO_VERSION=0.136.5 ARG NODE_VERSION=22 ARG PAGEFIND_VERSION=1.1.1 diff --git a/netlify.toml b/netlify.toml index 9052d54885..27e4eb15eb 100644 --- a/netlify.toml +++ b/netlify.toml @@ -4,7 +4,7 @@ publish = "public" [context.deploy-preview.environment] NODE_VERSION = "20" NODE_ENV = "production" -HUGO_VERSION = "0.136.3" +HUGO_VERSION = "0.136.5" HUGO_ENABLEGITINFO = "true" HUGO_ENVIRONMENT = "preview" From c643508a1f01182e0880d84d23baed5184ae0eab Mon Sep 17 00:00:00 2001 From: David Karlsson <35727626+dvdksn@users.noreply.github.com> Date: Thu, 31 Oct 2024 09:37:20 +0100 Subject: [PATCH 3/3] ci: update node.js version to 22 (active lts) Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com> --- netlify.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netlify.toml b/netlify.toml index 27e4eb15eb..da603d4300 100644 --- a/netlify.toml +++ b/netlify.toml @@ -2,7 +2,7 @@ publish = "public" [context.deploy-preview.environment] -NODE_VERSION = "20" +NODE_VERSION = "22" NODE_ENV = "production" HUGO_VERSION = "0.136.5" HUGO_ENABLEGITINFO = "true"