Files
esp32-web/Makefile
user c1f580ba16 feat: pagination totals, request logging, data retention
Add shared paginate() helper with total count to all list endpoints.
Add request logging middleware (method, path, status, duration, IP).
Add data retention service with configurable thresholds and CLI command.
2026-02-06 09:58:20 +01:00

122 lines
3.1 KiB
Makefile

.PHONY: help build run dev stop logs test migrate clean install start restart status oui cleanup
APP_NAME := esp32-web
PORT := 5500
HOST := 0.0.0.0
PIDFILE := /tmp/esp32-web.pid
LOGFILE := /tmp/esp32-web.log
help:
@echo "ESP32-Web Server"
@echo ""
@echo "Server:"
@echo " make start Start server ($(HOST):$(PORT))"
@echo " make stop Stop server"
@echo " make restart Restart server"
@echo " make status Show PID + uptime"
@echo " make logs Tail log file"
@echo " make dev Run with debug mode"
@echo ""
@echo "Database:"
@echo " make migrate Apply migrations"
@echo " make migrate-init Initialize migrations"
@echo " make migrate-create msg=x Create migration"
@echo ""
@echo "Development:"
@echo " make install Install with dev dependencies"
@echo " make test Run tests"
@echo " make oui Download OUI database"
@echo " make cleanup Delete expired data"
@echo " make clean Remove cache files"
@echo ""
@echo "Container:"
@echo " make build Build image"
@echo " make container-run Run container"
@echo " make container-stop Stop container"
install:
pip install -e ".[dev]"
# Server management
start:
@if [ -f $(PIDFILE) ] && kill -0 $$(cat $(PIDFILE)) 2>/dev/null; then \
echo "Server already running (PID $$(cat $(PIDFILE)))"; \
else \
echo "Starting server on $(HOST):$(PORT)..."; \
nohup flask --app src/esp32_web run --host $(HOST) --port $(PORT) > $(LOGFILE) 2>&1 & \
echo $$! > $(PIDFILE); \
sleep 1; \
echo "Server started (PID $$(cat $(PIDFILE)))"; \
fi
stop:
@if [ -f $(PIDFILE) ]; then \
echo "Stopping server (PID $$(cat $(PIDFILE)))..."; \
kill $$(cat $(PIDFILE)) 2>/dev/null || true; \
rm -f $(PIDFILE); \
echo "Server stopped"; \
else \
echo "Server not running"; \
fi
restart: stop
@sleep 1
@$(MAKE) start
status:
@if [ -f $(PIDFILE) ] && kill -0 $$(cat $(PIDFILE)) 2>/dev/null; then \
echo "Server running (PID $$(cat $(PIDFILE)))"; \
curl -s http://localhost:$(PORT)/health 2>/dev/null | \
python3 -c "import sys,json; d=json.load(sys.stdin); print(f\"Status: {d['status']}\nUptime: {d['uptime']}\")" 2>/dev/null \
|| echo "Health: unreachable"; \
else \
echo "Server not running"; \
rm -f $(PIDFILE) 2>/dev/null; \
fi
logs:
@tail -f $(LOGFILE)
dev:
flask --app src/esp32_web run --host $(HOST) --port $(PORT) --debug
test:
pytest -v
oui:
flask --app src/esp32_web download-oui
cleanup:
flask --app src/esp32_web cleanup-data
migrate:
flask --app src/esp32_web db upgrade
migrate-init:
flask --app src/esp32_web db init
migrate-create:
flask --app src/esp32_web db migrate -m "$(msg)"
# Container targets
build:
podman build -t $(APP_NAME) .
container-run:
podman run -d --name $(APP_NAME) \
-p $(PORT):$(PORT) \
-p $(PORT):$(PORT)/udp \
-v ./instance:/app/instance:Z \
$(APP_NAME)
container-stop:
podman stop $(APP_NAME) && podman rm $(APP_NAME)
container-logs:
podman logs -f $(APP_NAME)
clean:
rm -rf __pycache__ .pytest_cache .ruff_cache
find . -type d -name __pycache__ -exec rm -rf {} +
find . -type f -name "*.pyc" -delete