.EXPORT_ALL_VARIABLES: PYTHON ?= $(shell command -v python3 python|head -n1) # Keep docker before podman due to: # https://github.com/containers/podman/issues/7602 ENGINE ?= $(shell command -v docker podman|head -n1) COMPOSE ?= $(shell command -v docker-compose podman-compose|head -n1) # localhost/ prefix must be present in order to assure docker/podman compatibility: # https://github.com/containers/buildah/issues/1034 IMAGE_TAG=localhost/elastic-recheck # Enable newer docker buildkit if available DOCKER_BUILDKIT=1 COMPOSE_DOCKER_CLI_BUILD=1 # ssh opts to add, used only for testing SSH_OPTS=-o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" .PHONY: default default: help define PRINT_HELP_PYSCRIPT import re, sys print("Usage: make \n") cmds = {} for line in sys.stdin: match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) if match: target, help = match.groups() cmds.update({target: help}) for cmd in sorted(cmds): print(f" {cmd:12} {cmds[cmd]}") endef export PRINT_HELP_PYSCRIPT .PHONY: help help: @$(PYTHON) -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) .PHONY: check-env check-env: ifndef GERRIT_USER $(error GERRIT_USER is undefined, you need to define it to run this command) endif .PHONY: build build: data/id_ecdsa check-env ## Build image using $(ENGINE) @echo "Checking that current user can connect to gerit using ssh...""" @python3 ./tools/ssh-check.py $(ENGINE) build -t $(IMAGE_TAG) . @echo "Image size: $$($(ENGINE) image inspect --format='scale=0; {{.Size}}/1024/1024' $(IMAGE_TAG) | bc)MB" @echo "Validate that built container can also connect to gerrit...""" $(ENGINE) run --env GERRIT_USER -it $(IMAGE_TAG) python3 /root/ssh-check.py .PHONY: up up: data/id_ecdsa check-env ## Run containers @# validates that container has credentials and connectivity to talk with gerrit server @# Validate the builder image can connect to server @# $(ENGINE) run --env GERRIT_USER -it $(IMAGE_TAG) python3 /root/ssh-check.py @# --abort-on-container-exit $(COMPOSE) up --force-recreate --remove-orphans --abort-on-container-exit <<