@@ -17,30 +17,34 @@ 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 \
43+ --mount type=bind,source=$(CURDIR ) /scripts,target=/src/scripts,readonly \
4044 --mount type=tmpfs,destination=/tmp,tmpfs-mode=01777 \
4145 --mount type=bind,source=$(CURDIR ) /hugo.yaml,target=/src/hugo.yaml,readonly
4246
43- # Fast NONBLOCKING IO to stdout caused by the hack/gen-content.sh script can
47+ # Fast NONBLOCKING IO to stdout caused by Hugo module operations can
4448# cause Netlify builds to terminate unexpectedly. This forces stdout to block.
4549BLOCK_STDOUT_CMD := python -c "import os,sys,fcntl; \
4650 flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL); \
@@ -49,21 +53,36 @@ BLOCK_STDOUT_CMD := python -c "import os,sys,fcntl; \
4953.DEFAULT_GOAL := help
5054
5155.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
56+ targets : help modules-get render server test clean clean-all production-build preview-build
57+ container-targets : container-image container-push container-modules-get container-render container-server container-test
5458
5559help : # # Show this help text.
5660 @grep -E ' ^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST ) | awk ' BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
5761
5862dependencies :
5963 npm ci
64+ pip3 install pyyaml || echo " Warning: pip3 install failed, verify-mounts.py may fail."
6065
61- gen-content : # # Generates content from external sources.
62- hack/gen-content.sh
66+ modules-get : # # Pulls latest Hugo module content.
67+ hugo mod get -u
68+ hugo mod tidy
69+
70+ modules-tidy : # # Clean and tidy Hugo modules.
71+ hugo mod tidy
6372
6473render : dependencies # # Build the site using Hugo on the host.
6574 hugo --logLevel info --ignoreCache --minify
6675
76+ test : render # # Run content verification and link/image checks.
77+ python3 scripts/verify-mounts.py --config hugo.yaml --public public
78+ if ! command -v htmltest > /dev/null; then curl -sL https://htmltest.wjdp.uk | bash; ./bin/htmltest; else htmltest; fi
79+
80+ container-test : container-image # # Run tests within a container using pre-installed dependencies.
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+ htmltest --conf .htmltest.yml /tmp/public"
85+
6786server : dependencies # # Run Hugo locally (if Hugo "extended" is installed locally)
6887 hugo server \
6988 --logLevel info \
@@ -77,7 +96,7 @@ docker-image:
7796 $(MAKE ) container-image
7897
7998container-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 )
99+ $(CONTAINER_ENGINE ) build . -t $(CONTAINER_IMAGE ) --label git_commit=$(COMMIT ) --build-arg HUGO_VERSION=$(HUGO_VERSION ) --build-arg GO_VERSION= $( GO_VERSION )
81100
82101container-push : container-image # # Push container image for the preview of the website
83102 $(CONTAINER_ENGINE ) push $(CONTAINER_IMAGE )
@@ -94,24 +113,25 @@ docker-push: ## Build a multi-architecture image and push that into the registry
94113 --push \
95114 --platform=$(PLATFORMS ) \
96115 --build-arg HUGO_VERSION=$(HUGO_VERSION ) \
116+ --build-arg GO_VERSION=$(GO_VERSION ) \
97117 --tag $(CONTAINER_IMAGE ) \
98118 -f Dockerfile.cross .
99119 $(DOCKER_BUILDX ) stop image-builder
100120 rm Dockerfile.cross
101121
102122docker-gen-content :
103123 @echo -e " **** The use of docker-gen-content is deprecated. Use container-gen-content instead. ****" 1>&2
104- $(MAKE ) container-gen-content
124+ $(MAKE ) container-modules-get
105125
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
126+ container-modules-get : # # Pulls latest Hugo module content within a container.
127+ $(CONTAINER_RUN ) -e GOMODCACHE=/tmp/gomod $(CONTAINER_IMAGE ) hugo mod get -u
108128
109129docker-render :
110130 @echo -e " **** The use of docker-render is deprecated. Use container-render instead. ****" 1>&2
111131 $(MAKE ) container-render
112132
113133container-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
134+ $(CONTAINER_RUN_TTY ) $(CONTAINER_HUGO_MOUNTS ) -e GOMODCACHE=/tmp/gomod $(CONTAINER_IMAGE ) hugo --logLevel info --ignoreCache --minify
115135
116136docker-server :
117137 @echo -e " **** The use of docker-server is deprecated. Use container-server instead. ****" 1>&2
@@ -123,9 +143,9 @@ container-server: ## Run Hugo locally within a container, available at http://lo
123143 $(CONTAINER_HUGO_MOUNTS ) \
124144 --cap-drop=ALL \
125145 --cap-drop=AUDIT_WRITE \
146+ -e GOMODCACHE=/tmp/gomod \
126147 $(CONTAINER_IMAGE ) \
127- bash -c ' cd /src && hack/gen-content.sh --in-container && \
128- cd /tmp/src && \
148+ bash -c ' cd /src && hugo mod get -u && \
129149 hugo server \
130150 --environment preview \
131151 --logLevel info \
@@ -141,40 +161,12 @@ container-server: ## Run Hugo locally within a container, available at http://lo
141161clean : # # Cleans build artifacts.
142162 rm -rf public/ resources/ _tmp/
143163
144- clean-all : # # Cleans both build artifacts and files synced to content directory
164+ clean-all : # # Cleans both build artifacts and Hugo cache.
145165 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 {} \;
166+ hugo mod clean
174167
175168production-build : # # Builds the production site (this command used only by Netlify).
176169 $(BLOCK_STDOUT_CMD )
177- hack/gen-content.sh
178170 hugo \
179171 --environment production \
180172 --logLevel info \
@@ -183,7 +175,6 @@ production-build: ## Builds the production site (this command used only by Netli
183175
184176preview-build : # # Builds a deploy preview of the site (this command used only by Netlify).
185177 $(BLOCK_STDOUT_CMD )
186- hack/gen-content.sh
187178 hugo \
188179 --environment preview \
189180 --logLevel info \
0 commit comments