From 1fef2594d21009a064c117ab7e1625c849e92fc1 Mon Sep 17 00:00:00 2001 From: Ariel Otilibili Date: Thu, 8 Aug 2024 01:27:50 +0200 Subject: [PATCH 1/3] Used pattern for rules targetting `test-*` `make help` & `make test-*` are unchanged: ``` $ make | grep test make test Run unit tests make test-core Run core unit tests make test-min Run core unit tests in minimal environment make test-min-with-upgrade Upgrade deps and run unit tests in minimal environment make test-restful Run Restful unit tests make test-with-upgrade Upgrade deps and run unit tests make test-xmlrpc Run XMLRPC unit tests $ make test -n venv/bin/python unittest-core.py venv/bin/python unittest-restful.py venv/bin/python unittest-xmlrpc.py ``` Signed-off-by: Ariel Otilibili --- Makefile | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 8ae31f78..b0baeb90 100644 --- a/Makefile +++ b/Makefile @@ -5,18 +5,24 @@ VENV_MIN := venv-min/bin CONF := conf/glances.conf PIP := $(VENV)/pip PYTHON := $(VENV)/python -UNITTEST := unittest +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) +DOCKER_RUNTIMES := $(DOCKER_IMAGES:%=run-%) +UNIT_TESTS := test-core test-restful test-xmlrpc DOCKER_BUILD := docker buildx build DOCKER_RUN := docker run -DOCKERFILE_UBUNTU := docker-files/ubuntu.Dockerfile -DOCKERFILE_ALPINE := docker-files/alpine.Dockerfile PODMAN_SOCK ?= /run/user/$(shell id -u)/podman/podman.sock 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 -LASTTAG = $(shell git describe --tags --abbrev=0) +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 @@ -86,24 +92,22 @@ venv-dev-upgrade: ## Upgrade Python 3 dev dependencies # Tests # =================================================================== +$(UNIT_TESTS): test-%: unittest-%.py + $(PYTHON) $< + test-core: ## Run core unit tests - $(PYTHON) $(UNITTEST)-core.py - test-restful: ## Run Restful unit tests - $(PYTHON) $(UNITTEST)-restful.py - test-xmlrpc: ## Run XMLRPC unit tests - $(PYTHON) $(UNITTEST)-xmlrpc.py -test: test-core test-restful test-xmlrpc ## Run unit tests +test: $(UNIT_TESTS) ## Run unit tests test-with-upgrade: venv-upgrade venv-dev-upgrade test ## Upgrade deps and run unit tests test-min: ## Run core unit tests in minimal environment - $(VENV_MIN)/python $(UNITTEST)-core.py + $(VENV_MIN)/python unittest-core.py test-min-with-upgrade: venv-min-upgrade ## Upgrade deps and run unit tests in minimal environment - $(VENV_MIN)/python $(UNITTEST)-core.py + $(VENV_MIN)/python unittest-core.py # =================================================================== # Linters, profilers and cyber security From 516c99e4962307477d10ad710dddd0ecc538ea1c Mon Sep 17 00:00:00 2001 From: Ariel Otilibili Date: Thu, 8 Aug 2024 01:37:01 +0200 Subject: [PATCH 2/3] Used pattern for rules targetting `docker-*` `make help` & `make docker-*` are unchanged: ``` $ make | grep -P '\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-alpine -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 . $ make docker-ubuntu -n 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 . ``` Signed-off-by: Ariel Otilibili --- Makefile | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index b0baeb90..2626c6f2 100644 --- a/Makefile +++ b/Makefile @@ -223,29 +223,28 @@ snapcraft: # Need Docker Buildx package (apt install docker-buildx on Ubuntu) # =================================================================== +define DOCKERFILE +docker-files/$(word 1,$(subst -, ,$*)).Dockerfile +endef + +define TARGET +$(word 2,$(subst -, ,$*)) +endef + +$(DOCKER_IMAGES): docker-%: + $(DOCKER_BUILD) --target $(TARGET) -f $(DOCKERFILE) -t $(DOCKER_TAG) . + docker: docker-alpine docker-ubuntu ## Generate local docker images -docker-alpine: docker-alpine-full docker-alpine-minimal docker-alpine-dev ## Generate local docker images (Alpine) +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_BUILD) --target full -f $(DOCKERFILE_ALPINE) -t glances:local-alpine-full . - docker-alpine-minimal: ## Generate local docker image (Alpine minimal) - $(DOCKER_BUILD) --target minimal -f $(DOCKERFILE_ALPINE) -t glances:local-alpine-minimal . - docker-alpine-dev: ## Generate local docker image (Alpine dev) - $(DOCKER_BUILD) --target dev -f $(DOCKERFILE_ALPINE) -t glances:local-alpine-dev . - -docker-ubuntu: docker-ubuntu-full docker-ubuntu-minimal docker-ubuntu-dev ## Generate local docker images (Ubuntu) - docker-ubuntu-full: ## Generate local docker image (Ubuntu full) - $(DOCKER_BUILD) --target full -f $(DOCKERFILE_UBUNTU) -t glances:local-ubuntu-full . - docker-ubuntu-minimal: ## Generate local docker image (Ubuntu minimal) - $(DOCKER_BUILD) --target minimal -f $(DOCKERFILE_UBUNTU) -t glances:local-ubuntu-minimal . - docker-ubuntu-dev: ## Generate local docker image (Ubuntu dev) - $(DOCKER_BUILD) --target dev -f $(DOCKERFILE_UBUNTU) -t glances:local-ubuntu-dev . # =================================================================== # Run From f5c2d8ce36fb3669a8aea137d898ebf4de97dda3 Mon Sep 17 00:00:00 2001 From: Ariel Otilibili Date: Thu, 8 Aug 2024 01:40:06 +0200 Subject: [PATCH 3/3] Used pattern for rules targetting `run-docker-*` `make help` & `make run-docker-*` are unchanged: ``` $ make | grep run-docker make run-docker-alpine-dev Start Glances Alpine Docker dev in console mode make run-docker-alpine-full Start Glances Alpine Docker full in console mode make run-docker-alpine-minimal Start Glances Alpine Docker minimal in console mode make run-docker-ubuntu-dev Start Glances Ubuntu Docker dev in console mode make run-docker-ubuntu-full Start Glances Ubuntu Docker full in console mode make run-docker-ubuntu-minimal Start Glances Ubuntu Docker minimal in console mode $ make run-docker-alpine-minimal -n docker run --rm -e TZ="" -e GLANCES_OPT="" --pid host --network host -v /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock:ro -v /var/run/docker.sock:/var/run/docker.sock:ro -it glances:local-alpine-minimal $ make run-docker-alpine-full -n docker run --rm -e TZ="" -e GLANCES_OPT="" --pid host --network host -v /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock:ro -v /var/run/docker.sock:/var/run/docker.sock:ro -it glances:local-alpine-full $ make run-docker-alpine-dev -n docker run --rm -e TZ="" -e GLANCES_OPT="" --pid host --network host -v /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock:ro -v /var/run/docker.sock:/var/run/docker.sock:ro -it glances:local-alpine-dev $ make run-docker-ubuntu-dev -n docker run --rm -e TZ="" -e GLANCES_OPT="" --pid host --network host -v /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock:ro -v /var/run/docker.sock:/var/run/docker.sock:ro -it glances:local-ubuntu-dev $ make run-docker-ubuntu-full -n docker run --rm -e TZ="" -e GLANCES_OPT="" --pid host --network host -v /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock:ro -v /var/run/docker.sock:/var/run/docker.sock:ro -it glances:local-ubuntu-full $ make run-docker-ubuntu-minimal -n docker run --rm -e TZ="" -e GLANCES_OPT="" --pid host --network host -v /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock:ro -v /var/run/docker.sock:/var/run/docker.sock:ro -it glances:local-ubuntu-minimal ``` Signed-off-by: Ariel Otilibili --- Makefile | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 2626c6f2..594d3edc 100644 --- a/Makefile +++ b/Makefile @@ -271,23 +271,15 @@ run-min-debug: ## Start minimal Glances in debug console mode (also called stand run-min-local-conf: ## Start minimal Glances in console mode with the system conf file $(VENV_MIN)/python -m glances +$(DOCKER_RUNTIMES): run-docker-%: + $(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it $(DOCKER_TAG) + run-docker-alpine-minimal: ## Start Glances Alpine Docker minimal in console mode - $(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it glances:local-alpine-minimal - run-docker-alpine-full: ## Start Glances Alpine Docker full in console mode - $(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it glances:local-alpine-full - run-docker-alpine-dev: ## Start Glances Alpine Docker dev in console mode - $(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it glances:local-alpine-dev - run-docker-ubuntu-minimal: ## Start Glances Ubuntu Docker minimal in console mode - $(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it glances:local-ubuntu-minimal - run-docker-ubuntu-full: ## Start Glances Ubuntu Docker full in console mode - $(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it glances:local-ubuntu-full - run-docker-ubuntu-dev: ## Start Glances Ubuntu Docker dev in console mode - $(DOCKER_RUN) $(DOCKER_OPTS) $(DOCKER_SOCKS) -it glances:local-ubuntu-dev run-webserver: ## Start Glances in Web server mode $(PYTHON) -m glances -C $(CONF) -w