1
- FROM razonyang/hugo:exts as builder
1
+ ARG GO_VERSION=1.21
2
+ ARG HTMLTEST_VERSION=0.17.0
2
3
3
- ARG HUGO_BASEURL=
4
- ENV HUGO_BASEURL=${HUGO_BASEURL}
4
+ FROM golang:${GO_VERSION}-alpine as base
5
+ WORKDIR /src
6
+ RUN apk --update add nodejs npm git gcompat
5
7
6
- COPY . /src
7
- RUN hugo --minify --gc --enableGitInfo
8
+ FROM base as node
9
+ COPY package*.json .
10
+ ENV NODE_ENV=production
11
+ RUN npm install
8
12
9
- FROM razonyang/hugo:nginx
10
- COPY --from=builder /src/public /site
13
+ FROM base as hugo
14
+ ARG HUGO_VERSION=0.122.0
15
+ ARG TARGETARCH
16
+ WORKDIR /tmp/hugo
17
+ RUN wget -O "hugo.tar.gz" "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-${TARGETARCH}.tar.gz"
18
+ RUN tar -xf "hugo.tar.gz" hugo
19
+
20
+ FROM base as build-base
21
+ COPY --from=hugo /tmp/hugo/hugo /bin/hugo
22
+ COPY --from=node /src/node_modules /src/node_modules
23
+ COPY . .
24
+
25
+ FROM build-base as dev
26
+
27
+ FROM build-base as build
28
+ ARG HUGO_ENV
29
+ ARG DOCS_URL
30
+ RUN hugo --gc --minify -d /out -e $HUGO_ENV -b $DOCS_URL
31
+
32
+ FROM scratch as release
33
+ COPY --from=build /out /
34
+
35
+ FROM scratch as update-stats
36
+ COPY --from=build /src/hugo_stats.json /hugo_stats.json
37
+
38
+ FROM build as validate-stats
39
+ RUN <<EOF
40
+ if [ -n "$(git status --porcelain -- hugo_stats.json)" ]; then
41
+ echo >&2 'ERROR: hugo_stats.json differs. Update with `docker buildx bake update-stats`'
42
+ exit 1
43
+ fi
44
+ EOF
45
+
46
+ FROM davidanson/markdownlint-cli2:v0.12.1 as lint
47
+ USER root
48
+ RUN --mount=type=bind,target=. \
49
+ /usr/local/bin/markdownlint-cli2 \
50
+ "content/**/*.md" \
51
+ "#content/engine/release-notes/*.md" \
52
+ "#content/desktop/previous-versions/*.md"
53
+
54
+ FROM wjdp/htmltest:v${HTMLTEST_VERSION} as test
55
+ WORKDIR /test
56
+ COPY --from=build /out ./public
57
+ ADD .htmltest.yml .htmltest.yml
58
+ RUN htmltest
59
+
60
+ FROM build-base as update-modules
61
+ ARG MODULE
62
+ RUN <<"EOT"
63
+ set -ex
64
+ if [ -n "$MODULE" ]; then
65
+ hugo mod get ${MODULE}
66
+ RESOLVED=$(cat go.mod | grep -m 1 "${MODULE/@*/}" | awk '{print $1 "@" $2}' )
67
+ go mod edit -replace "${MODULE/@*/}=${RESOLVED}" ;
68
+ else
69
+ echo "no module set" ;
70
+ fi
71
+ EOT
72
+ RUN hugo mod vendor
73
+
74
+ FROM scratch as vendor
75
+ COPY --from=update-modules /src/_vendor /_vendor
76
+ COPY --from=update-modules /src/go.* /
77
+
78
+ FROM build-base as build-upstream
79
+ ARG UPSTREAM_MODULE_NAME
80
+ ARG UPSTREAM_REPO
81
+ ARG UPSTREAM_COMMIT
82
+ ENV HUGO_MODULE_REPLACEMENTS="github.com/${UPSTREAM_MODULE_NAME} -> github.com/${UPSTREAM_REPO} ${UPSTREAM_COMMIT}"
83
+ RUN hugo --ignoreVendorPaths "github.com/${UPSTREAM_MODULE_NAME}" -d /out
84
+
85
+ FROM wjdp/htmltest:v${HTMLTEST_VERSION} as validate-upstream
86
+ WORKDIR /test
87
+ COPY --from=build-upstream /out ./public
88
+ ADD .htmltest.yml .htmltest.yml
89
+ RUN htmltest
90
+
91
+ FROM dev
0 commit comments