Skip to content

Commit 7f04966

Browse files
authored
Merge pull request nicolargo#2913 from ariel-anieli/makefile
Renamed variables in `Makefile`; rules targetting `docker-*` are now built at runtime
2 parents 0003768 + a370109 commit 7f04966

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

Makefile

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ PYTHON := $(VENV)/python
88
LASTTAG = $(shell git describe --tags --abbrev=0)
99

1010
IMAGES_TYPES := full minimal dev
11-
ALPINE_IMAGES := $(IMAGES_TYPES:%=docker-alpine-%)
12-
UBUNTU_IMAGES := $(IMAGES_TYPES:%=docker-ubuntu-%)
13-
DOCKER_IMAGES := $(ALPINE_IMAGES) $(UBUNTU_IMAGES)
11+
DISTROS := alpine ubuntu
12+
alpine_images := $(IMAGES_TYPES:%=docker-alpine-%)
13+
ubuntu_images := $(IMAGES_TYPES:%=docker-ubuntu-%)
14+
DOCKER_IMAGES := $(alpine_images) $(ubuntu_images)
1415
DOCKER_RUNTIMES := $(DOCKER_IMAGES:%=run-%)
1516
UNIT_TESTS := test-core test-restful test-xmlrpc
1617
DOCKER_BUILD := docker buildx build
@@ -20,10 +21,6 @@ DOCKER_SOCK ?= /var/run/docker.sock
2021
DOCKER_SOCKS := -v $(PODMAN_SOCK):$(PODMAN_SOCK):ro -v $(DOCKER_SOCK):$(DOCKER_SOCK):ro
2122
DOCKER_OPTS := --rm -e TZ="${TZ}" -e GLANCES_OPT="" --pid host --network host
2223

23-
define DOCKER_TAG
24-
glances:local-$*
25-
endef
26-
2724
# if the command is only `make`, the default tasks will be the printing of the help.
2825
.DEFAULT_GOAL := help
2926

@@ -223,21 +220,17 @@ snapcraft:
223220
# Need Docker Buildx package (apt install docker-buildx on Ubuntu)
224221
# ===================================================================
225222

226-
define DOCKERFILE
227-
docker-files/$(word 1,$(subst -, ,$*)).Dockerfile
228-
endef
229-
230-
define TARGET
231-
$(word 2,$(subst -, ,$*))
223+
define MAKE_DOCKER_BUILD_RULES
224+
$($(DISTRO)_images): docker-$(DISTRO)-%: docker-files/$(DISTRO).Dockerfile
225+
$(DOCKER_BUILD) --target $$* -f $$< -t glances:local-$(DISTRO)-$$* .
232226
endef
233227

234-
$(DOCKER_IMAGES): docker-%:
235-
$(DOCKER_BUILD) --target $(TARGET) -f $(DOCKERFILE) -t $(DOCKER_TAG) .
228+
$(foreach DISTRO,$(DISTROS),$(eval $(MAKE_DOCKER_BUILD_RULES)))
236229

237230
docker: docker-alpine docker-ubuntu ## Generate local docker images
238231

239-
docker-alpine: $(ALPINE_IMAGES) ## Generate local docker images (Alpine)
240-
docker-ubuntu: $(UBUNTU_IMAGES) ## Generate local docker images (Ubuntu)
232+
docker-alpine: $(alpine_images) ## Generate local docker images (Alpine)
233+
docker-ubuntu: $(ubuntu_images) ## Generate local docker images (Ubuntu)
241234

242235
docker-alpine-full: ## Generate local docker image (Alpine full)
243236
docker-alpine-minimal: ## Generate local docker image (Alpine minimal)
@@ -272,7 +265,7 @@ run-min-local-conf: ## Start minimal Glances in console mode with the system con
272265
$(VENV_MIN)/python -m glances
273266

274267
$(DOCKER_RUNTIMES): run-docker-%:
275-
$(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it $(DOCKER_TAG)
268+
$(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it glances:local-$*
276269

277270
run-docker-alpine-minimal: ## Start Glances Alpine Docker minimal in console mode
278271
run-docker-alpine-full: ## Start Glances Alpine Docker full in console mode

0 commit comments

Comments
 (0)