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