-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
124 lines (106 loc) · 4.58 KB
/
Makefile
File metadata and controls
124 lines (106 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
PYTHON ?= python3
VENV ?= .venv
BIN := $(VENV)/bin
DATA_DIR ?= $(CURDIR)/flexlog-data
PORT ?= 5050
INSTALL_MARK := $(VENV)/.installed
.PHONY: help install lock audit openapi run test test-cov smoke clean \
self-host-install self-host-uninstall self-host-backup self-host-drill
help:
@echo "flexlog — make targets"
@echo ""
@echo " make install install flexlog from hash-pinned requirements.lock"
@echo " make run run the app at http://127.0.0.1:$(PORT)/"
@echo " (data dir: $(DATA_DIR))"
@echo " make test run the test suite (enforces 85% coverage gate)"
@echo " make test-cov test + term-missing coverage report"
@echo " make smoke end-to-end smoke test against a tmp data dir"
@echo ""
@echo "Maintainer targets (need outbound network):"
@echo " make lock regenerate requirements.lock from pyproject.toml"
@echo " make audit pip-audit --strict against requirements.lock"
@echo " make openapi validate docs/openapi.yaml + run drift tests"
@echo ""
@echo " make clean remove caches, build artifacts, and the venv"
@echo ""
@echo "Self-host targets (macOS launchd, rclone backup):"
@echo " make self-host-install install the three flexlog launchd agents"
@echo " make self-host-uninstall uninstall the three flexlog launchd agents"
@echo " make self-host-backup trigger a manual backup run"
@echo " make self-host-drill run the quarterly recovery drill"
@echo ""
@echo "Override variables on the command line, e.g.:"
@echo " make run DATA_DIR=/abs/path PORT=5151"
@echo " make install PYTHON=python3.11"
$(VENV):
$(PYTHON) -m venv $(VENV)
$(INSTALL_MARK): pyproject.toml requirements.lock | $(VENV)
$(BIN)/pip install --upgrade pip
$(BIN)/pip install --require-hashes -r requirements.lock
$(BIN)/pip install -e . --no-deps
@if command -v sha256sum >/dev/null 2>&1; then \
cd flexlog/static/vendor && sha256sum -c INTEGRITY.txt; \
elif command -v shasum >/dev/null 2>&1; then \
cd flexlog/static/vendor && shasum -a 256 -c INTEGRITY.txt; \
else \
echo "WARNING: neither sha256sum nor shasum found; vendor integrity NOT verified"; \
fi
@touch $@
install: $(INSTALL_MARK)
lock: | $(VENV)
$(BIN)/pip install --upgrade "pip-tools>=7.4,<8"
$(BIN)/pip-compile \
--generate-hashes \
--extra dev \
--output-file requirements.lock \
pyproject.toml
@echo ""
@echo "Lockfile regenerated. Review the diff and commit alongside pyproject.toml."
audit: install
$(BIN)/pip-audit --strict --requirement requirements.lock
openapi: install
$(BIN)/python -m openapi_spec_validator docs/openapi.yaml
$(BIN)/pytest tests/integration/test_openapi.py -v --no-cov
run: install
@mkdir -p $(DATA_DIR)
FLEXLOG_DATA_DIR=$(DATA_DIR) FLEXLOG_PORT=$(PORT) $(BIN)/flexlog
test: install
$(BIN)/pytest
test-cov: install
$(BIN)/pytest --cov-report=term-missing
smoke: install
@set -e ; \
SCRATCH=$$(mktemp -d) ; \
echo "smoke: data dir = $$SCRATCH" ; \
FLEXLOG_DATA_DIR=$$SCRATCH FLEXLOG_PORT=$(PORT) $(BIN)/flexlog & \
APP_PID=$$! ; \
sleep 2 ; \
rc=0 ; \
if curl -fsS http://127.0.0.1:$(PORT)/ > /dev/null ; then \
echo "OK: dashboard returns 200" ; \
else \
echo "FAIL: dashboard did not respond" ; rc=1 ; \
fi ; \
[ -f "$$SCRATCH/.secret_key" ] && echo "OK: .secret_key created" || { echo "FAIL: .secret_key missing" ; rc=1 ; } ; \
[ -f "$$SCRATCH/data/encounters.db" ] && echo "OK: encounters.db created" || { echo "FAIL: encounters.db missing" ; rc=1 ; } ; \
kill $$APP_PID 2>/dev/null || true ; \
wait $$APP_PID 2>/dev/null || true ; \
rm -rf "$$SCRATCH" ; \
exit $$rc
clean:
rm -rf $(VENV) build dist *.egg-info .coverage .coverage.* htmlcov .pytest_cache
find . -type d -name __pycache__ -exec rm -rf {} +
# ---------------------------------------------------------------- self-host
self-host-install: ## Install the three flexlog launchd agents on macOS
$(BIN)/python scripts/install_launch_agents.py
self-host-uninstall: ## Uninstall the three flexlog launchd agents
$(BIN)/python scripts/uninstall_launch_agents.py
self-host-backup: ## Trigger a manual backup run (same as the launchd agent)
@launchctl kickstart -k gui/$$(id -u)/com.flexlog.backup
@echo "backup triggered. Tail ~/Library/Logs/flexlog/backup.stderr.log for progress."
self-host-drill: ## Run the quarterly recovery drill (RCLONE_REMOTE required)
@if [ -z "$$RCLONE_REMOTE" ]; then \
echo "set RCLONE_REMOTE first, e.g. RCLONE_REMOTE=railway-backup:flexlog-home-backup make self-host-drill"; \
exit 1; \
fi
./scripts/recovery-drill.sh