103 lines
3.5 KiB
Makefile
103 lines
3.5 KiB
Makefile
.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 <target>\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 <<<y
|
|
@# $(ENGINE) container stop elastic-recheck
|
|
@# bash -c "$(ENGINE) rm elastic-recheck || true"
|
|
@# $(ENGINE) run --env ES_URL --env LS_URL --env DB_URI --env GERRIT_HOST --env GERRIT_USER --env IRC_NICK --env IRC_PASS -it --name elastic-recheck elastic-recheck:latest
|
|
|
|
.PHONY: down
|
|
down: ## Destroy containers
|
|
$(COMPOSE) down --remove-orphans --rmi local
|
|
|
|
.PHONY: into
|
|
into: ## Starts bash inside $(ENGINE) image
|
|
$(ENGINE) run --mount 'type=volume,src=er-volume,dst=/data,volume-driver=local' -it $(IMAGE_TAG) /bin/sh
|
|
# $(ENGINE) exec -it er-cron /bin/sh
|
|
@# $(COMPOSE) run elastic-recheck bash
|
|
|
|
.PHONY: dive
|
|
dive: ## Use `dive` tool to investigate container size
|
|
# https://github.com/wagoodman/dive
|
|
dive $(IMAGE_TAG)
|
|
|
|
data/id_ecdsa:
|
|
# this key must be unencrypted, so create a spare one for testing and
|
|
# add it to your gerrit user configuration
|
|
cp -f ~/.ssh/id_ecdsa_insecure data/id_ecdsa
|
|
|
|
.PHONY: clean
|
|
clean: ## Use clean to remove all temp files, including container and images but **not** data/
|
|
$(ENGINE) image rm --force $(IMAGE_TAG)
|
|
|
|
.PHONY: key
|
|
key: ## Makes a SSH key compatibile with paramiko (overrides existing one)
|
|
@mkdir -p data
|
|
@rm data/id_ecdsa || true
|
|
@ssh-keygen -q -N '' -m PEM -t ecdsa -f data/id_ecdsa
|
|
@echo "WARN: Please assign key below to your gerrit user using the web interface:"
|
|
@ssh-keygen -l -f data/id_ecdsa
|
|
|
|
|
|
.PHONY: wheel
|
|
wheel: ## Use clean to remove all temp files, including container and images but **not** data/
|
|
mkdir -p build
|
|
cd build && pip3 wheel ..
|