diff --git a/Makefile b/Makefile index 8ae31f78..594d3edc 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 @@ -219,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 @@ -268,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