ci: use official Hugo image

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
This commit is contained in:
David Karlsson 2024-10-16 17:26:07 +02:00
parent 970eb6607f
commit 5b8ceb6a8f
4 changed files with 19 additions and 36 deletions

View File

@ -7,42 +7,27 @@ ARG ALPINE_VERSION=3.20
ARG GO_VERSION=1.23 ARG GO_VERSION=1.23
# HTMLTEST_VERSION sets the wjdp/htmltest version for HTML testing # HTMLTEST_VERSION sets the wjdp/htmltest version for HTML testing
ARG HTMLTEST_VERSION=0.17.0 ARG HTMLTEST_VERSION=0.17.0
# HUGO_VERSION sets the version of Hugo to build the site with
ARG HUGO_VERSION=0.136.0
# base is the base stage with build dependencies # build-base is the base stage used for building the site
FROM golang:${GO_VERSION}-alpine AS base FROM ghcr.io/gohugoio/hugo:v${HUGO_VERSION} AS build-base
WORKDIR /src USER root
RUN apk --update add nodejs npm git gcompat ENV NODE_ENV="production"
RUN --mount=source=package.json,target=package.json \
# node installs Node.js dependencies --mount=source=package-lock.json,target=package-lock.json \
FROM base AS node --mount=type=cache,target=/root/.npm \
COPY package*.json . npm ci
ENV NODE_ENV=production
RUN npm install
# hugo downloads and extracts the Hugo binary
FROM base AS hugo
ARG HUGO_VERSION=0.134.3
ARG TARGETARCH
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
# 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 . .
# dev is for local development with Docker Compose
FROM build-base AS dev
# build creates production builds with Hugo # build creates production builds with Hugo
FROM build-base AS build FROM build-base AS build
# HUGO_ENV sets the hugo.Environment (production, development, preview) # HUGO_ENV sets the hugo.Environment (production, development, preview)
ARG HUGO_ENV ARG HUGO_ENV="development"
# DOCS_URL sets the base URL for the site # DOCS_URL sets the base URL for the site
ARG DOCS_URL ARG DOCS_URL="https://docs.docker.com"
RUN hugo --gc --minify -d /out -e $HUGO_ENV -b $DOCS_URL RUN --mount=type=cache,target=/cache \
hugo --gc --minify -d /out -e $HUGO_ENV -b $DOCS_URL
# lint lints markdown files # lint lints markdown files
FROM davidanson/markdownlint-cli2:v0.14.0 AS lint FROM davidanson/markdownlint-cli2:v0.14.0 AS lint
@ -122,7 +107,7 @@ fi
EOT EOT
# pagefind installs the Pagefind runtime # pagefind installs the Pagefind runtime
FROM base AS pagefind FROM node:alpine${ALPINE_VERSION} AS pagefind
ARG PAGEFIND_VERSION=1.1.1 ARG PAGEFIND_VERSION=1.1.1
COPY --from=build /out ./public COPY --from=build /out ./public
RUN --mount=type=bind,src=pagefind.yml,target=pagefind.yml \ RUN --mount=type=bind,src=pagefind.yml,target=pagefind.yml \

View File

@ -2,7 +2,7 @@ services:
server: server:
build: build:
context: . context: .
target: dev target: build-base
ports: ports:
- "1313:1313" - "1313:1313"
entrypoint: ["hugo", "server", "--bind", "0.0.0.0"] entrypoint: ["hugo", "server", "--bind", "0.0.0.0"]
@ -11,5 +11,3 @@ services:
- action: sync - action: sync
path: . path: .
target: /src target: /src
ignore:
- node_modules/

View File

@ -1,9 +1,9 @@
variable "HUGO_ENV" { variable "HUGO_ENV" {
default = "development" default = null
} }
variable "DOCS_URL" { variable "DOCS_URL" {
default = "https://docs.docker.com" default = null
} }
variable "DOCS_SITE_DIR" { variable "DOCS_SITE_DIR" {

View File

@ -4,7 +4,7 @@ publish = "public"
[context.deploy-preview.environment] [context.deploy-preview.environment]
NODE_VERSION = "20" NODE_VERSION = "20"
NODE_ENV = "production" NODE_ENV = "production"
HUGO_VERSION = "0.134.3" HUGO_VERSION = "0.136.0"
HUGO_ENABLEGITINFO = "true" HUGO_ENABLEGITINFO = "true"
HUGO_ENVIRONMENT = "preview" HUGO_ENVIRONMENT = "preview"