From: Arran Cudbard-Bell Date: Wed, 20 May 2026 19:46:20 +0000 (-0400) Subject: docker: drive per-type wiring from a single TYPES list X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=27baa583f37870a0249508ddd104f13c56b92fbe;p=thirdparty%2Ffreeradius-server.git docker: drive per-type wiring from a single TYPES list docker.mk and dockerfile.mk both had a hand-written stanza per type: four DOCKER_BUILD calls, four DOCKERFILE_RULE calls, four umbrellas. Adding a fifth type meant editing every block. Collapse them into a single DOCKER_TYPES / DOCKERFILE_TYPES list plus a double foreach over images and types. Per-type quirks (profiling's --build-arg=from=crossbuild and crossbuild stamp dependency, the optional CB_FROM_$(IMG) override on crossbuild) move into DOCKER_BUILD_ARGS_ / DOCKER_BUILD_DEPS_ recursive variables, so the $(IMG) inside them resolves at the right point in the foreach. Adding a new type is now: append to the list, drop in the m4 files, optionally set the two lookup vars. --- diff --git a/scripts/docker/docker.mk b/scripts/docker/docker.mk index 20e065d1e11..bdc289a18fc 100644 --- a/scripts/docker/docker.mk +++ b/scripts/docker/docker.mk @@ -189,16 +189,34 @@ $(DOCKER_STATE): @mkdir -p $@ # -# Wire build + phony + clean + lifecycle for every (image, type) -# combo. Profiling FROMs the crossbuild image of the same distro, -# so its build depends on the corresponding crossbuild stamp. -# -$(foreach IMG,$(IMAGES),\ - $(eval $(call DOCKER_BUILD,$(IMG),service,,)) \ - $(eval $(call DOCKER_BUILD,$(IMG),ci,,)) \ - $(eval $(call DOCKER_BUILD,$(IMG),crossbuild,$(if $(CB_FROM_$(IMG)),--build-arg=from=$(CB_FROM_$(IMG))),)) \ - $(eval $(call DOCKER_BUILD,$(IMG),profiling,--build-arg=from=$(DOCKER_IMAGE_PREFIX)-crossbuild/$(IMG):$(GIT_SHA),$(DOCKER_STATE)/stamp-image.$(IMG).crossbuild)) \ - $(foreach T,service ci crossbuild profiling, \ +# Build types, and the per-type knobs DOCKER_BUILD needs. Anything +# type-specific (extra --build-arg, extra stamp deps) lives here so +# the per-(image,type) wiring stays a plain double foreach. +# +# $(IMG) in these values is resolved at $(eval) time inside the +# foreach below, so each image sees its own substituted form. +# +DOCKER_TYPES := ci crossbuild profiling service + +DOCKER_BUILD_ARGS_service := +DOCKER_BUILD_ARGS_ci := +DOCKER_BUILD_ARGS_crossbuild = $(if $(CB_FROM_$(IMG)),--build-arg=from=$(CB_FROM_$(IMG))) +DOCKER_BUILD_ARGS_profiling = --build-arg=from=$(DOCKER_IMAGE_PREFIX)-crossbuild/$(IMG):$(GIT_SHA) + +DOCKER_BUILD_DEPS_service := +DOCKER_BUILD_DEPS_ci := +DOCKER_BUILD_DEPS_crossbuild := +DOCKER_BUILD_DEPS_profiling = $(DOCKER_STATE)/stamp-image.$(IMG).crossbuild + +# +# Wire build + phony + clean + lifecycle + test for every (image, +# type) combo. Profiling FROMs the crossbuild image of the same +# distro, so its build depends on the corresponding crossbuild +# stamp (see DOCKER_BUILD_DEPS_profiling above). +# +$(foreach IMG,$(IMAGES), \ + $(foreach T,$(DOCKER_TYPES), \ + $(eval $(call DOCKER_BUILD,$(IMG),$(T),$(DOCKER_BUILD_ARGS_$(T)),$(DOCKER_BUILD_DEPS_$(T)))) \ $(eval $(call DOCKER_PHONY,$(IMG),$(T))) \ $(eval $(call DOCKER_CLEAN,$(IMG),$(T))) \ $(eval $(call DOCKER_LIFECYCLE,$(IMG),$(T))) \ @@ -217,10 +235,7 @@ docker.${1}.down: $(foreach IMG,${2},docker.${1}.$(IMG).down) docker.${1}.reset: $(foreach IMG,${2},docker.${1}.$(IMG).reset) endef -$(eval $(call DOCKER_TYPE_UMBRELLAS,service,$(IMAGES))) -$(eval $(call DOCKER_TYPE_UMBRELLAS,ci,$(IMAGES))) -$(eval $(call DOCKER_TYPE_UMBRELLAS,crossbuild,$(IMAGES))) -$(eval $(call DOCKER_TYPE_UMBRELLAS,profiling,$(IMAGES))) +$(foreach T,$(DOCKER_TYPES),$(eval $(call DOCKER_TYPE_UMBRELLAS,$(T),$(IMAGES)))) # # Across-type umbrellas. 'docker' stays as a legacy alias for the @@ -229,10 +244,12 @@ $(eval $(call DOCKER_TYPE_UMBRELLAS,profiling,$(IMAGES))) .PHONY: docker docker.common docker.clean docker.up docker.down docker.reset docker.info docker.info_header docker: docker.info docker.service docker.common: docker.info $(foreach IMG,$(DOCKER_COMMON),docker.service.$(IMG)) -docker.clean: docker.ci.clean docker.crossbuild.clean docker.profiling.clean docker.service.clean -docker.up: docker.ci.up docker.crossbuild.up docker.profiling.up docker.service.up -docker.down: docker.ci.down docker.crossbuild.down docker.profiling.down docker.service.down -docker.reset: docker.ci.reset docker.crossbuild.reset docker.profiling.reset docker.service.reset + +define DOCKER_VERB_UMBRELLA +docker.${1}: $(foreach T,$(DOCKER_TYPES),docker.$(T).${1}) +endef + +$(foreach V,clean up down reset,$(eval $(call DOCKER_VERB_UMBRELLA,$(V)))) docker.info: docker.info_header $(foreach IMG,$(IMAGES),docker.service.$(IMG).status) @echo All images: $(IMAGES) diff --git a/scripts/docker/dockerfile.mk b/scripts/docker/dockerfile.mk index acbc46a9b99..9a75658290e 100644 --- a/scripts/docker/dockerfile.mk +++ b/scripts/docker/dockerfile.mk @@ -86,29 +86,27 @@ ${1}: endef # -# Wire each (image, type) Dockerfile rule plus the per-type regen -# and drift-check umbrellas. Profiling is filtered to PROFILING_IMAGES -# because it doesn't have an rpm template. +# Build types. Per-type m4 prereqs follow the .deb.m4 / +# .rpm.m4 naming convention so DOCKERFILE_RULE picks them up +# from $(T) alone. # -$(foreach IMG,$(IMAGES),\ - $(eval $(call DOCKERFILE_RULE,$(IMG),service,$(CB_DIR)/m4/service.deb.m4 $(CB_DIR)/m4/service.rpm.m4)) \ - $(eval $(call DOCKERFILE_RULE,$(IMG),ci,$(CB_DIR)/m4/ci.deb.m4 $(CB_DIR)/m4/ci.rpm.m4)) \ - $(eval $(call DOCKERFILE_RULE,$(IMG),crossbuild,$(CB_DIR)/m4/crossbuild.deb.m4 $(CB_DIR)/m4/crossbuild.rpm.m4)) \ - $(eval $(call DOCKERFILE_RULE,$(IMG),profiling,$(CB_DIR)/m4/profiling.deb.m4 $(CB_DIR)/m4/profiling.rpm.m4))) +DOCKERFILE_TYPES := ci crossbuild profiling service -$(eval $(call DOCKERFILE_ALL,dockerfile.service,service,$(IMAGES))) -$(eval $(call DOCKERFILE_ALL,dockerfile.ci,ci,$(IMAGES))) -$(eval $(call DOCKERFILE_ALL,dockerfile.crossbuild,crossbuild,$(IMAGES))) -$(eval $(call DOCKERFILE_ALL,dockerfile.profiling,profiling,$(IMAGES))) +# +# Wire each (image, type) Dockerfile rule plus the per-type regen +# and drift-check umbrellas. +# +$(foreach IMG,$(IMAGES), \ + $(foreach T,$(DOCKERFILE_TYPES), \ + $(eval $(call DOCKERFILE_RULE,$(IMG),$(T),$(CB_DIR)/m4/$(T).deb.m4 $(CB_DIR)/m4/$(T).rpm.m4)))) -$(eval $(call DOCKERFILE_CHECK,dockerfile.service.check,service,$(IMAGES),dockerfile.service)) -$(eval $(call DOCKERFILE_CHECK,dockerfile.ci.check,ci,$(IMAGES),dockerfile.ci)) -$(eval $(call DOCKERFILE_CHECK,dockerfile.crossbuild.check,crossbuild,$(IMAGES),dockerfile.crossbuild)) -$(eval $(call DOCKERFILE_CHECK,dockerfile.profiling.check,profiling,$(IMAGES),dockerfile.profiling)) +$(foreach T,$(DOCKERFILE_TYPES), \ + $(eval $(call DOCKERFILE_ALL,dockerfile.$(T),$(T),$(IMAGES))) \ + $(eval $(call DOCKERFILE_CHECK,dockerfile.$(T).check,$(T),$(IMAGES),dockerfile.$(T)))) .PHONY: dockerfile dockerfile.check -dockerfile: dockerfile.ci dockerfile.crossbuild dockerfile.profiling dockerfile.service -dockerfile.check: dockerfile.ci.check dockerfile.crossbuild.check dockerfile.profiling.check dockerfile.service.check +dockerfile: $(foreach T,$(DOCKERFILE_TYPES),dockerfile.$(T)) +dockerfile.check: $(foreach T,$(DOCKERFILE_TYPES),dockerfile.$(T).check) # # Glossary of type identifiers, shared by docker.help / dockerfile.help.