Skip to content

Commit 782f34b

Browse files
committed
chore: ensure image is built pull or build
1 parent 728a09e commit 782f34b

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

Makefile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ CONTAINER_HUGO_MOUNTS = \
5959
# Writable mount for container-render output (Hugo writes to /out -> host public/)
6060
CONTAINER_RENDER_MOUNT := --mount type=bind,source=$(CURDIR)/public,target=/out$(MOUNT_OPTS)
6161

62+
# Command to ensure the container image is available locally (pull or build)
63+
IMAGE_ENSURE := $(CONTAINER_ENGINE) pull $(CONTAINER_IMAGE) || $(MAKE) container-image
64+
65+
# Base command for running Hugo in the container with all shared mounts and env vars
66+
CONTAINER_HUGO_RUN := $(CONTAINER_RUN_TTY) $(CONTAINER_HUGO_ENV) $(CONTAINER_HUGO_MOUNTS)
67+
6268
# Fast NONBLOCKING IO to stdout caused by the hack/gen-content.sh script can
6369
# cause Netlify builds to terminate unexpectedly. This forces stdout to block.
6470
BLOCK_STDOUT_CMD := python -c "import os,sys,fcntl; \
@@ -129,19 +135,17 @@ docker-render:
129135
$(MAKE) container-render
130136

131137
container-render: ## Build the site using Hugo within a container (equiv to render).
132-
$(CONTAINER_ENGINE) pull $(CONTAINER_IMAGE) || $(MAKE) container-image
133-
$(CONTAINER_RUN_TTY) $(CONTAINER_HUGO_ENV) $(CONTAINER_HUGO_MOUNTS) $(CONTAINER_RENDER_MOUNT) $(CONTAINER_IMAGE) bash -c 'cd /src && hugo mod get && hugo --noBuildLock --destination /out --logLevel info --ignoreCache --minify'
138+
@$(IMAGE_ENSURE)
139+
$(CONTAINER_HUGO_RUN) $(CONTAINER_RENDER_MOUNT) $(CONTAINER_IMAGE) bash -c 'cd /src && hugo mod get && hugo --noBuildLock --destination /out --logLevel info --ignoreCache --minify'
134140

135141
docker-server:
136142
@echo -e "**** The use of docker-server is deprecated. Use container-server instead. ****" 1>&2
137143
$(MAKE) container-server
138144

139145
container-server: ## Run Hugo locally within a container, available at http://localhost:1313/
140146
# no build lock to allow for read-only mounts
141-
$(CONTAINER_ENGINE) pull $(CONTAINER_IMAGE) || $(MAKE) container-image
142-
$(CONTAINER_RUN_TTY) $(CONTAINER_HUGO_ENV) -p 1313:1313 \
143-
$(CONTAINER_HUGO_MOUNTS) \
144-
$(CONTAINER_IMAGE) \
147+
@$(IMAGE_ENSURE)
148+
$(CONTAINER_HUGO_RUN) -p 1313:1313 $(CONTAINER_IMAGE) \
145149
bash -c 'cd /src && hugo mod get && \
146150
hugo server \
147151
--environment preview \

0 commit comments

Comments
 (0)