From ddfcf46dee52a38b8d5ee78c26e50fd13c77d520 Mon Sep 17 00:00:00 2001 From: Ariel Otilibili Date: Sat, 10 Aug 2024 09:14:19 +0200 Subject: [PATCH 1/2] Renamed variables in `Makefile`; introduced the variable `DISTROS` * needed for subsequent changes in `Makefile` * `s/ALPINE_IMAGES/alpine_images/; s/UBUNTU_IMAGES/ubuntu_images/` Signed-off-by: Ariel Otilibili --- Makefile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 594d3edc..fd116826 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,10 @@ PYTHON := $(VENV)/python LASTTAG = $(shell git describe --tags --abbrev=0) IMAGES_TYPES := full minimal dev -ALPINE_IMAGES := $(IMAGES_TYPES:%=docker-alpine-%) -UBUNTU_IMAGES := $(IMAGES_TYPES:%=docker-ubuntu-%) -DOCKER_IMAGES := $(ALPINE_IMAGES) $(UBUNTU_IMAGES) +DISTROS := alpine ubuntu +alpine_images := $(IMAGES_TYPES:%=docker-alpine-%) +ubuntu_images := $(IMAGES_TYPES:%=docker-ubuntu-%) +DOCKER_IMAGES := $(alpine_images) $(ubuntu_images) DOCKER_RUNTIMES := $(DOCKER_IMAGES:%=run-%) UNIT_TESTS := test-core test-restful test-xmlrpc DOCKER_BUILD := docker buildx build @@ -236,8 +237,8 @@ $(DOCKER_IMAGES): docker-%: docker: docker-alpine docker-ubuntu ## Generate local docker images -docker-alpine: $(ALPINE_IMAGES) ## Generate local docker images (Alpine) -docker-ubuntu: $(UBUNTU_IMAGES) ## Generate local docker images (Ubuntu) +docker-alpine: $(alpine_images) ## Generate local docker images (Alpine) +docker-ubuntu: $(ubuntu_images) ## Generate local docker images (Ubuntu) docker-alpine-full: ## Generate local docker image (Alpine full) docker-alpine-minimal: ## Generate local docker image (Alpine minimal) From a37010929d76fef816cf0801caa1bcc7eef2aec4 Mon Sep 17 00:00:00 2001 From: Ariel Otilibili Date: Sat, 10 Aug 2024 09:23:37 +0200 Subject: [PATCH 2/2] Rules targetting `docker-*` are now built at runtime * removed the macros `DOCKERFILE`, `TARGET`, & `DOCKER_TAG` * introduced the macro `MAKE_DOCKER_BUILD_RULES` * at runtime, `docker-*` are built from the `DISTROS` list: done using `eval` [1] * `make help` is unchanged: ``` $ make | grep '\sdocker-' make docker-alpine Generate local docker images (Alpine) make docker-alpine-dev Generate local docker image (Alpine dev) make docker-alpine-full Generate local docker image (Alpine full) make docker-alpine-minimal Generate local docker image (Alpine minimal) make docker-ubuntu Generate local docker images (Ubuntu) make docker-ubuntu-dev Generate local docker image (Ubuntu dev) make docker-ubuntu-full Generate local docker image (Ubuntu full) make docker-ubuntu-minimal Generate local docker image (Ubuntu minimal) $ make docker -n docker buildx build --target full -f docker-files/alpine.Dockerfile -t glances:local-alpine-full . docker buildx build --target minimal -f docker-files/alpine.Dockerfile -t glances:local-alpine-minimal . docker buildx build --target dev -f docker-files/alpine.Dockerfile -t glances:local-alpine-dev . docker buildx build --target full -f docker-files/ubuntu.Dockerfile -t glances:local-ubuntu-full . docker buildx build --target minimal -f docker-files/ubuntu.Dockerfile -t glances:local-ubuntu-minimal . docker buildx build --target dev -f docker-files/ubuntu.Dockerfile -t glances:local-ubuntu-dev . ``` [1] https://www.gnu.org/software/make/manual/html_node/Eval-Function.html Signed-off-by: Ariel Otilibili --- Makefile | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index fd116826..ff8f7daa 100644 --- a/Makefile +++ b/Makefile @@ -21,10 +21,6 @@ DOCKER_SOCK ?= /var/run/docker.sock DOCKER_SOCKS := -v $(PODMAN_SOCK):$(PODMAN_SOCK):ro -v $(DOCKER_SOCK):$(DOCKER_SOCK):ro DOCKER_OPTS := --rm -e TZ="${TZ}" -e GLANCES_OPT="" --pid host --network host -define DOCKER_TAG -glances:local-$* -endef - # if the command is only `make`, the default tasks will be the printing of the help. .DEFAULT_GOAL := help @@ -224,16 +220,12 @@ snapcraft: # Need Docker Buildx package (apt install docker-buildx on Ubuntu) # =================================================================== -define DOCKERFILE -docker-files/$(word 1,$(subst -, ,$*)).Dockerfile +define MAKE_DOCKER_BUILD_RULES +$($(DISTRO)_images): docker-$(DISTRO)-%: docker-files/$(DISTRO).Dockerfile + $(DOCKER_BUILD) --target $$* -f $$< -t glances:local-$(DISTRO)-$$* . endef -define TARGET -$(word 2,$(subst -, ,$*)) -endef - -$(DOCKER_IMAGES): docker-%: - $(DOCKER_BUILD) --target $(TARGET) -f $(DOCKERFILE) -t $(DOCKER_TAG) . +$(foreach DISTRO,$(DISTROS),$(eval $(MAKE_DOCKER_BUILD_RULES))) docker: docker-alpine docker-ubuntu ## Generate local docker images @@ -273,7 +265,7 @@ run-min-local-conf: ## Start minimal Glances in console mode with the system con $(VENV_MIN)/python -m glances $(DOCKER_RUNTIMES): run-docker-%: - $(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it $(DOCKER_TAG) + $(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it glances:local-$* run-docker-alpine-minimal: ## Start Glances Alpine Docker minimal in console mode run-docker-alpine-full: ## Start Glances Alpine Docker full in console mode