@@ -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)
2222CONTAINER_RUN := $(CONTAINER_ENGINE ) run --rm -it -v "$(CURDIR ) :/src"
2323CONTAINER_RUN_TTY := $(CONTAINER_ENGINE ) run --rm -it
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,17 +52,21 @@ 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 clean clean-all production-build preview-build
56+ container-targets : container-image container-push container-modules-get container-render container-server
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
6063
61- gen-content : # # Generates content from external sources.
62- hack/gen-content.sh
64+ modules-get : # # Pulls latest Hugo module content.
65+ hugo mod get -u
66+ hugo mod tidy
67+
68+ modules-tidy : # # Clean and tidy Hugo modules.
69+ hugo mod tidy
6370
6471render : dependencies # # Build the site using Hugo on the host.
6572 hugo --logLevel info --ignoreCache --minify
@@ -77,7 +84,7 @@ docker-image:
7784 $(MAKE ) container-image
7885
7986container-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 )
87+ $(CONTAINER_ENGINE ) build . -t $(CONTAINER_IMAGE ) --label git_commit=$(COMMIT ) --build-arg HUGO_VERSION=$(HUGO_VERSION ) --build-arg GO_VERSION= $( GO_VERSION )
8188
8289container-push : container-image # # Push container image for the preview of the website
8390 $(CONTAINER_ENGINE ) push $(CONTAINER_IMAGE )
@@ -94,24 +101,25 @@ docker-push: ## Build a multi-architecture image and push that into the registry
94101 --push \
95102 --platform=$(PLATFORMS ) \
96103 --build-arg HUGO_VERSION=$(HUGO_VERSION ) \
104+ --build-arg GO_VERSION=$(GO_VERSION ) \
97105 --tag $(CONTAINER_IMAGE ) \
98106 -f Dockerfile.cross .
99107 $(DOCKER_BUILDX ) stop image-builder
100108 rm Dockerfile.cross
101109
102110docker-gen-content :
103111 @echo -e " **** The use of docker-gen-content is deprecated. Use container-gen-content instead. ****" 1>&2
104- $(MAKE ) container-gen-content
112+ $(MAKE ) container-modules-get
105113
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
114+ container-modules-get : # # Pulls latest Hugo module content within a container.
115+ $(CONTAINER_RUN ) -e GOMODCACHE=/tmp/gomod $(CONTAINER_IMAGE ) hugo mod get -u
108116
109117docker-render :
110118 @echo -e " **** The use of docker-render is deprecated. Use container-render instead. ****" 1>&2
111119 $(MAKE ) container-render
112120
113121container-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
122+ $(CONTAINER_RUN_TTY ) $(CONTAINER_HUGO_MOUNTS ) -e GOMODCACHE=/tmp/gomod $(CONTAINER_IMAGE ) hugo --logLevel info --ignoreCache --minify
115123
116124docker-server :
117125 @echo -e " **** The use of docker-server is deprecated. Use container-server instead. ****" 1>&2
@@ -123,9 +131,9 @@ container-server: ## Run Hugo locally within a container, available at http://lo
123131 $(CONTAINER_HUGO_MOUNTS ) \
124132 --cap-drop=ALL \
125133 --cap-drop=AUDIT_WRITE \
134+ -e GOMODCACHE=/tmp/gomod \
126135 $(CONTAINER_IMAGE ) \
127- bash -c ' cd /src && hack/gen-content.sh --in-container && \
128- cd /tmp/src && \
136+ bash -c ' cd /src && hugo mod get -u && \
129137 hugo server \
130138 --environment preview \
131139 --logLevel info \
@@ -141,40 +149,12 @@ container-server: ## Run Hugo locally within a container, available at http://lo
141149clean : # # Cleans build artifacts.
142150 rm -rf public/ resources/ _tmp/
143151
144- clean-all : # # Cleans both build artifacts and files synced to content directory
152+ clean-all : # # Cleans both build artifacts and Hugo cache.
145153 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 {} \;
154+ hugo mod clean
174155
175156production-build : # # Builds the production site (this command used only by Netlify).
176157 $(BLOCK_STDOUT_CMD )
177- hack/gen-content.sh
178158 hugo \
179159 --environment production \
180160 --logLevel info \
@@ -183,7 +163,6 @@ production-build: ## Builds the production site (this command used only by Netli
183163
184164preview-build : # # Builds a deploy preview of the site (this command used only by Netlify).
185165 $(BLOCK_STDOUT_CMD )
186- hack/gen-content.sh
187166 hugo \
188167 --environment preview \
189168 --logLevel info \
0 commit comments