@@ -17,30 +17,33 @@ STAGING_IMAGE_REGISTRY := us-central1-docker.pkg.dev/k8s-staging-images
1717IMAGE_REGISTRY ?= ${STAGING_IMAGE_REGISTRY}/contributor-site
1818IMAGE_NAME := k8s-contrib-site-hugo
1919IMAGE_REPO := $(IMAGE_REGISTRY ) /$(IMAGE_NAME )
20- IMAGE_VERSION := $(shell scripts/hash-files.sh Dockerfile Makefile netlify.toml .dockerignore cloudbuild.yaml package.json package-lock.json | cut -c 1-12)
20+ IMAGE_VERSION := $(shell scripts/hash-files.sh Dockerfile Makefile netlify.toml .dockerignore cloudbuild.yaml package.json package-lock.json go.mod go.sum | cut -c 1-12)
2121COMMIT := $(shell git rev-parse --short HEAD)
22- CONTAINER_RUN := $(CONTAINER_ENGINE ) run --rm -it - v "$(CURDIR ) :/src"
23- CONTAINER_RUN_TTY := $(CONTAINER_ENGINE ) run --rm -it
22+ CONTAINER_RUN := $(CONTAINER_ENGINE ) run --rm -v "$(CURDIR ) :/src"
23+ CONTAINER_RUN_TTY := $(CONTAINER_ENGINE ) run --rm
2424HUGO_VERSION := $(shell grep ^HUGO_VERSION netlify.toml | tail -n 1 | cut -d '=' -f 2 | tr -d " \"\n")
25+ GO_VERSION := $(shell grep ^GO_VERSION netlify.toml | tail -n 1 | cut -d '=' -f 2 | tr -d " \"\n")
2526GIT_TAG ?= v$(HUGO_VERSION ) -$(IMAGE_VERSION )
2627CONTAINER_IMAGE := $(IMAGE_REPO ) :$(GIT_TAG )
28+ GOMODCACHE ?= $(shell go env GOMODCACHE)
2729
2830# Docker buildx related settings for multi-arch images
2931DOCKER_BUILDX ?= docker buildx
3032
3133CONTAINER_HUGO_MOUNTS = \
3234 --read-only \
3335 --mount type=bind,source=$(CURDIR ) /.git,target=/src/.git,readonly \
36+ --mount type=bind,source=$(CURDIR ) /go.mod,target=/src/go.mod \
37+ --mount type=bind,source=$(CURDIR ) /go.sum,target=/src/go.sum \
38+ --mount type=bind,source=$(GOMODCACHE ) ,target=/tmp/gomod \
3439 --mount type=bind,source=$(CURDIR ) /assets,target=/src/assets,readonly \
3540 --mount type=bind,source=$(CURDIR ) /content,target=/src/content,readonly \
36- --mount type=bind,source=$(CURDIR ) /external-sources,target=/src/external-sources,readonly \
37- --mount type=bind,source=$(CURDIR ) /hack,target=/src/hack,readonly \
3841 --mount type=bind,source=$(CURDIR ) /layouts,target=/src/layouts,readonly \
3942 --mount type=bind,source=$(CURDIR ) /static,target=/src/static,readonly \
4043 --mount type=tmpfs,destination=/tmp,tmpfs-mode=01777 \
4144 --mount type=bind,source=$(CURDIR ) /hugo.yaml,target=/src/hugo.yaml,readonly
4245
43- # Fast NONBLOCKING IO to stdout caused by the hack/gen-content.sh script can
46+ # Fast NONBLOCKING IO to stdout caused by Hugo module operations can
4447# cause Netlify builds to terminate unexpectedly. This forces stdout to block.
4548BLOCK_STDOUT_CMD := python -c "import os,sys,fcntl; \
4649 flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL); \
@@ -49,21 +52,38 @@ BLOCK_STDOUT_CMD := python -c "import os,sys,fcntl; \
4952.DEFAULT_GOAL := help
5053
5154.PHONY : targets container-targets
52- targets : help gen-content render server clean clean-all production-build preview-build
53- container-targets : container-image container-push container-gen-content container-render container-server
55+ targets : help modules-get render server test clean clean-all production-build preview-build
56+ container-targets : container-image container-push container-modules-get container-render container-server container-test
5457
5558help : # # Show this help text.
5659 @grep -E ' ^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST ) | awk ' BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
5760
5861dependencies :
5962 npm ci
63+ pip3 install pyyaml || echo " Warning: pip3 install failed, verify-mounts.py may fail."
6064
61- gen-content : # # Generates content from external sources.
62- hack/gen-content.sh
65+ modules-get : # # Pulls latest Hugo module content.
66+ hugo mod get -u
67+ hugo mod tidy
68+
69+ modules-tidy : # # Clean and tidy Hugo modules.
70+ hugo mod tidy
6371
6472render : dependencies # # Build the site using Hugo on the host.
6573 hugo --logLevel info --ignoreCache --minify
6674
75+ test : render # # Run content verification and link/image checks.
76+ python3 scripts/verify-mounts.py --config hugo.yaml --public public
77+ curl -sL https://htmltest.wjdp.uk | bash
78+ ./bin/htmltest
79+
80+ container-test : container-image # # Run tests within a container.
81+ $(CONTAINER_RUN_TTY ) $(CONTAINER_HUGO_MOUNTS ) -e GOMODCACHE=/tmp/gomod $(CONTAINER_IMAGE ) \
82+ bash -c " hugo --ignoreCache --minify --destination /tmp/public && \
83+ python3 scripts/verify-mounts.py --config hugo.yaml --public /tmp/public && \
84+ curl -sL https://htmltest.wjdp.uk | bash && \
85+ ./bin/htmltest --conf .htmltest.yml /tmp/public"
86+
6787server : dependencies # # Run Hugo locally (if Hugo "extended" is installed locally)
6888 hugo server \
6989 --logLevel info \
@@ -77,7 +97,7 @@ docker-image:
7797 $(MAKE ) container-image
7898
7999container-image : # # Build container image for use with container-* targets.
80- $(CONTAINER_ENGINE ) build . -t $(CONTAINER_IMAGE ) --label git_commit=$(COMMIT ) --build-arg HUGO_VERSION=$(HUGO_VERSION )
100+ $(CONTAINER_ENGINE ) build . -t $(CONTAINER_IMAGE ) --label git_commit=$(COMMIT ) --build-arg HUGO_VERSION=$(HUGO_VERSION ) --build-arg GO_VERSION= $( GO_VERSION )
81101
82102container-push : container-image # # Push container image for the preview of the website
83103 $(CONTAINER_ENGINE ) push $(CONTAINER_IMAGE )
@@ -94,24 +114,25 @@ docker-push: ## Build a multi-architecture image and push that into the registry
94114 --push \
95115 --platform=$(PLATFORMS ) \
96116 --build-arg HUGO_VERSION=$(HUGO_VERSION ) \
117+ --build-arg GO_VERSION=$(GO_VERSION ) \
97118 --tag $(CONTAINER_IMAGE ) \
98119 -f Dockerfile.cross .
99120 $(DOCKER_BUILDX ) stop image-builder
100121 rm Dockerfile.cross
101122
102123docker-gen-content :
103124 @echo -e " **** The use of docker-gen-content is deprecated. Use container-gen-content instead. ****" 1>&2
104- $(MAKE ) container-gen-content
125+ $(MAKE ) container-modules-get
105126
106- container-gen-content : # # Generates content from external sources within a container (equiv to gen-content) .
107- $(CONTAINER_RUN ) $(CONTAINER_IMAGE ) hack/gen-content.sh
127+ container-modules-get : # # Pulls latest Hugo module content within a container.
128+ $(CONTAINER_RUN ) -e GOMODCACHE=/tmp/gomod $(CONTAINER_IMAGE ) hugo mod get -u
108129
109130docker-render :
110131 @echo -e " **** The use of docker-render is deprecated. Use container-render instead. ****" 1>&2
111132 $(MAKE ) container-render
112133
113134container-render : # # Build the site using Hugo within a container (equiv to render).
114- $(CONTAINER_RUN_TTY ) $(CONTAINER_HUGO_MOUNTS ) $(CONTAINER_IMAGE ) hugo --logLevel info --ignoreCache --minify
135+ $(CONTAINER_RUN_TTY ) $(CONTAINER_HUGO_MOUNTS ) -e GOMODCACHE=/tmp/gomod $(CONTAINER_IMAGE ) hugo --logLevel info --ignoreCache --minify
115136
116137docker-server :
117138 @echo -e " **** The use of docker-server is deprecated. Use container-server instead. ****" 1>&2
@@ -123,9 +144,9 @@ container-server: ## Run Hugo locally within a container, available at http://lo
123144 $(CONTAINER_HUGO_MOUNTS ) \
124145 --cap-drop=ALL \
125146 --cap-drop=AUDIT_WRITE \
147+ -e GOMODCACHE=/tmp/gomod \
126148 $(CONTAINER_IMAGE ) \
127- bash -c ' cd /src && hack/gen-content.sh --in-container && \
128- cd /tmp/src && \
149+ bash -c ' cd /src && hugo mod get -u && \
129150 hugo server \
130151 --environment preview \
131152 --logLevel info \
@@ -141,40 +162,12 @@ container-server: ## Run Hugo locally within a container, available at http://lo
141162clean : # # Cleans build artifacts.
142163 rm -rf public/ resources/ _tmp/
143164
144- clean-all : # # Cleans both build artifacts and files synced to content directory
165+ clean-all : # # Cleans both build artifacts and Hugo cache.
145166 rm -rf public/ resources/ _tmp/
146- rm -f content/en/events/community-meeting.md
147- rm -f content/en/events/meet-our-contributors.md
148- rm -f content/en/events/office-hours.md
149- rm -f content/en/docs/cheatsheet.md
150- rm -f content/en/resources/rename.md
151- find content/en/docs/guide -maxdepth 1 \
152- -not -path content/en/docs/guide \
153- -not -name " .gitignore" \
154- -exec rm -rf {} \;
155- find content/en/docs/comms -maxdepth 1 \
156- -not -path content/en/docs/comms \
157- -not -name " .gitignore" \
158- -not -name " _index.md" \
159- -exec rm -rf {} \;
160- find content/en/resources/release -maxdepth 1 \
161- -not -path content/en/resources/release \
162- -not -name " .gitignore" \
163- -exec rm -rf {} \;
164- find content/en/docs/orientation -maxdepth 1 \
165- -not -path content/en/docs/orientation \
166- -not -name " .gitignore" \
167- -exec rm -rf {} \;
168- find content/en/community -maxdepth 1 \
169- -not -path content/en/community \
170- -not -name " .gitignore" \
171- -not -name " _index.md" \
172- -not -name " code-of-conduct.md" \
173- -exec rm -rf {} \;
167+ hugo mod clean
174168
175169production-build : # # Builds the production site (this command used only by Netlify).
176170 $(BLOCK_STDOUT_CMD )
177- hack/gen-content.sh
178171 hugo \
179172 --environment production \
180173 --logLevel info \
@@ -183,7 +176,6 @@ production-build: ## Builds the production site (this command used only by Netli
183176
184177preview-build : # # Builds a deploy preview of the site (this command used only by Netlify).
185178 $(BLOCK_STDOUT_CMD )
186- hack/gen-content.sh
187179 hugo \
188180 --environment preview \
189181 --logLevel info \
0 commit comments