Skip to content

Commit 6931f0d

Browse files
committed
Docker updates
Signed-off-by: Archit Sharma <[email protected]>
1 parent aac18ab commit 6931f0d

File tree

4 files changed

+117
-9
lines changed

4 files changed

+117
-9
lines changed

.dockerignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.DS_Store
2+
.github
3+
.gitignore
4+
.idea
5+
_releaser
6+
CONTRIBUTING.md
7+
Dockerfile
8+
compose.yml
9+
docker-bake.hcl
10+
public
11+
node_modules
12+
resources
13+
tmp

Dockerfile

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,91 @@
1-
FROM razonyang/hugo:exts as builder
1+
ARG GO_VERSION=1.21
2+
ARG HTMLTEST_VERSION=0.17.0
23

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
57

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
812

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

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,4 @@ check-go:
4444
@echo "Go is installed."
4545

4646
docker:
47-
docker build -t layer5/docs .
48-
docker run -p 8080:80 layer5/docs
47+
docker compose watch

compose.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
server:
3+
build:
4+
context: .
5+
target: dev
6+
ports:
7+
- "1313:1313"
8+
entrypoint: ["hugo", "server", "--bind", "0.0.0.0"]
9+
develop:
10+
watch:
11+
- action: sync
12+
path: .
13+
target: /src
14+
ignore:
15+
- node_modules/

0 commit comments

Comments
 (0)