Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
274 lines (215 loc) · 12.3 KB
/
Copy pathMakefile
File metadata and controls
274 lines (215 loc) · 12.3 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
.PHONY: help install install-backend install-frontend test test-backend test-frontend test-dataset dev dev-redis dev-backend dev-frontend build-frontend db-generate-init-old db db-prd-local docker-app-up docker-app-down docker-app-logs clean redis keycloak keycloak-down models-doc up-fr down-fr logs-fr display-env-fr up-da down-da logs-da display-env-da dataset-export dataset-export-dry-run helm-lint helm-test
# Variables
PYTHON := python3
UV := uv
NPM := yarn
BACKEND_PORT := 8008
FRONTEND_PORT := 5173
CONTROLLER_PORT := 21001
HELM_CHART := devops/helm/comparia
COMPARIA_REDIS_HOST ?= localhost
export COMPARIA_REDIS_HOST
KEEPASS_DB ?= $(HOME)/comparia_dev.kdbx
KEEPASS_GROUP_FR ?= instances/fr
KEEPASS_GROUP_DA ?= instances/da
help: ## Display this help
@echo "Available commands for compar:IA:"
@echo ""
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-25s\033[0m %s\n", $$1, $$2}'
###################################
# Shared - PostgreSQL and Redis init using docker
###################################
network: ## Create shared Docker network (idempotent)
@docker network create comparia-net 2>/dev/null || true
db-generate-init-old: ## (legacy) Create comparia_da and apply old SQL schema to both databases via docker exec
@bash devops/instances/postgres/generate-init-db.sh
@docker compose -f devops/instances/postgres/postgres-simple.compose.yml exec -T postgres-simple \
psql -U comparia -c "CREATE DATABASE comparia_da OWNER comparia;" 2>/dev/null || true
@sed -e 's/"languia-dev"/"comparia"/g' -e 's/"languia-prd"/"comparia"/g' -e 's/"languia"/"comparia"/g' \
devops/instances/postgres/schema.sql | \
docker compose -f devops/instances/postgres/postgres-simple.compose.yml exec -T postgres-simple \
psql -U comparia -d comparia
@sed -e 's/"languia-dev"/"comparia"/g' -e 's/"languia-prd"/"comparia"/g' -e 's/"languia"/"comparia"/g' \
devops/instances/postgres/schema.sql | \
docker compose -f devops/instances/postgres/postgres-simple.compose.yml exec -T postgres-simple \
psql -U comparia -d comparia_da
db: ## Launch Postgres database using docker compose (empty schema, use db-migrate to apply)
@$(MAKE) network
@echo "Starting PostgreSQL database..."
docker compose -f devops/instances/postgres/postgres-simple.compose.yml up -d
db-reset-data:
@echo "Removing docker dev data (volumes)..."
@docker compose -f devops/instances/postgres/postgres-simple.compose.yml down -v
db-migrate: ## Apply pending Alembic migrations (requires COMPARIA_DB_URI)
@if [ -z "$$COMPARIA_DB_URI" ]; then echo "Error: COMPARIA_DB_URI is not set"; exit 1; fi
$(UV) run alembic upgrade head
db-migrate-generate: ## Generate a new Alembic migration (usage: make db-migrate-generate MSG="description", requires COMPARIA_DB_URI)
@if [ -z "$$COMPARIA_DB_URI" ]; then echo "Error: COMPARIA_DB_URI is not set"; exit 1; fi
$(UV) run alembic revision --autogenerate -m "$(MSG)"
db-migrate-status: ## Show current Alembic migration status (requires COMPARIA_DB_URI)
@if [ -z "$$COMPARIA_DB_URI" ]; then echo "Error: COMPARIA_DB_URI is not set"; exit 1; fi
$(UV) run alembic current
db-schema-dump: ## Dump current database schema (requires COMPARIA_DB_URI)
@if [ -z "$$COMPARIA_DB_URI" ]; then echo "Error: COMPARIA_DB_URI is not set"; exit 1; fi
pg_dump "$$COMPARIA_DB_URI" --schema-only --no-owner --no-privileges
db-seed-admins: ## Promote ADMIN_EMAILS users to admin role (requires COMPARIA_DB_URI)
@if [ -z "$$COMPARIA_DB_URI" ]; then echo "Error: COMPARIA_DB_URI is not set"; exit 1; fi
./comparia-cli db seed-admins
db-seed-activity: ## Fill a debug database with fake conversations (usage: make db-seed-activity COUNT=500000, requires COMPARIA_DB_URI and LANGUIA_DEBUG=true)
@if [ -z "$$COMPARIA_DB_URI" ]; then echo "Error: COMPARIA_DB_URI is not set"; exit 1; fi
./comparia-cli db seed-activity --count $(or $(COUNT),1000)
db-reset-totp: ## Forget an admin's authenticator app and sign them out (usage: make db-reset-totp EMAIL=admin@example.org, requires COMPARIA_DB_URI)
@if [ -z "$$COMPARIA_DB_URI" ]; then echo "Error: COMPARIA_DB_URI is not set"; exit 1; fi
@if [ -z "$(EMAIL)" ]; then echo "Error: EMAIL is not set"; exit 1; fi
./comparia-cli db reset-totp "$(EMAIL)"
db-clear-visitor-ids: ## Count the comparisons still holding a Matomo visitor id, or clear them with COMMIT=1 (requires COMPARIA_DB_URI)
@if [ -z "$$COMPARIA_DB_URI" ]; then echo "Error: COMPARIA_DB_URI is not set"; exit 1; fi
./comparia-cli db clear-visitor-ids $(if $(COMMIT),--commit)
db-analysis-shadow: ## Score SAMPLE (default 500) analysed comparisons with the dataset check's decision model and compare, writing nothing (requires COMPARIA_DB_URI)
@if [ -z "$$COMPARIA_DB_URI" ]; then echo "Error: COMPARIA_DB_URI is not set"; exit 1; fi
./comparia-cli db analysis-shadow --sample $(or $(SAMPLE),500)
db-analysis-reapply: ## Recompute analysis flags and tags from stored scores with the current thresholds; dry run unless COMMIT=1 (requires COMPARIA_DB_URI)
@if [ -z "$$COMPARIA_DB_URI" ]; then echo "Error: COMPARIA_DB_URI is not set"; exit 1; fi
./comparia-cli db analysis-reapply $(if $(COMMIT),--commit)
db-analysis-rescore: ## Score published comparisons again with the dataset check's decision model (all of them with EVERY=1); dry run unless COMMIT=1 (requires COMPARIA_DB_URI)
@if [ -z "$$COMPARIA_DB_URI" ]; then echo "Error: COMPARIA_DB_URI is not set"; exit 1; fi
./comparia-cli db analysis-rescore $(if $(COMMIT),--commit) $(if $(EVERY),--every)
db-purge-inactive: ## Warn then erase accounts unused for MONTHS (default 24); dry run unless APPLY=1 (requires COMPARIA_DB_URI)
@if [ -z "$$COMPARIA_DB_URI" ]; then echo "Error: COMPARIA_DB_URI is not set"; exit 1; fi
./comparia-cli db purge-inactive --months $(or $(MONTHS),24) $(if $(filter 1 true yes,$(APPLY)),--apply)
db-purge-retention: ## Blank or delete data past the privacy policy's retention periods; dry run unless APPLY=1 (requires COMPARIA_DB_URI)
@if [ -z "$$COMPARIA_DB_URI" ]; then echo "Error: COMPARIA_DB_URI is not set"; exit 1; fi
./comparia-cli db purge-retention $(if $(filter 1 true yes,$(APPLY)),--apply)
redis: ## Launch Redis using docker compose
@$(MAKE) network
@echo "Starting Redis..."
docker compose -f devops/instances/redis/redis.compose.yml up -d
redis-down: ## Stop Redis
docker compose -f devops/instances/redis/redis.compose.yml down
keycloak: ## Launch a local Keycloak (OIDC test IdP, local dev only) and configure the comparia client + test user
@$(MAKE) network
@echo "Starting Keycloak..."
docker compose -f devops/instances/keycloak/keycloak.compose.yml up -d
bash devops/instances/keycloak/setup-keycloak.sh
keycloak-down: ## Stop the local Keycloak
docker compose -f devops/instances/keycloak/keycloak.compose.yml down
###################################
# Instance fr docker
###################################
up-fr: ## Launch FR instance (frontend + backend + postgres + redis)
@$(MAKE) redis
@$(MAKE) db
eval $$(uv run --group devops python devops/keepassxc/load_env.py --db $(KEEPASS_DB) --group "$(KEEPASS_GROUP_FR)") && \
docker compose -f devops/instances/fr/app.compose.fr.yml up -d --build
down-fr: ## Stop FR instance
docker compose -f devops/instances/fr/app.compose.fr.yml down
logs-fr: ## Show logs for FR instance
docker compose -f devops/instances/fr/app.compose.fr.yml logs -f
display-env-fr: ## Display env vars loaded from KeePass for FR instance
uv run --group devops python devops/keepassxc/load_env.py --db $(KEEPASS_DB) --group "$(KEEPASS_GROUP_FR)" --mask
###################################
# Instance da docker
###################################
up-da: ## Launch DA instance (frontend + backend + postgres + redis)
eval $$(uv run --group devops python devops/keepassxc/load_env.py --db $(KEEPASS_DB) --group "$(KEEPASS_GROUP_DA)") && \
docker compose -f devops/instances/da/app.compose.da.yml up -d --build
down-da: ## Stop DA instance
docker compose -f devops/instances/da/app.compose.da.yml down
logs-da: ## Show logs for DA instance
docker compose -f devops/instances/da/app.compose.da.yml logs -f
display-env-da: ## Display env vars loaded from KeePass for DA instance
uv run --group devops python devops/keepassxc/load_env.py --db $(KEEPASS_DB) --group "$(KEEPASS_GROUP_DA)" --mask
###################################
# Development with local code
###################################
test: test-backend test-frontend test-dataset ## Run all tests
test-backend: ## Run the python test suite (no DB required)
$(UV) run --group dev --group data pytest tests -q
test-frontend: ## Run the frontend unit tests
cd frontend && yarn vitest run
test-dataset: ## Run dataset export tests (no DB required)
$(UV) run --group data python tests/dataset/test_comparison_to_turns.py
$(UV) run --group data python tests/dataset/test_streaming_export.py
install: install-backend install-frontend ## Install all dependencies (backend + frontend)
install-backend: ## Install Python backend dependencies with uv
@echo "Installing backend dependencies..."
@if ! command -v uv &> /dev/null; then \
echo "uv is not installed. Installing..."; \
curl -LsSf https://astral.sh/uv/install.sh | sh; \
fi
# ^ upstream's own installer, fetched over TLS; verifying its signature or
# using a package manager (brew install uv, pipx install uv) is safer
$(UV) sync
install-frontend: ## Install npm frontend dependencies
@echo "Installing frontend dependencies..."
cd frontend && $(NPM) install || npm install --legacy-peer-deps
dev: ## Launch backend and frontend (env vars must be exported, e.g. source .env)
$(MAKE) -j 2 dev-backend dev-frontend
dev-backend: ## Launch only the backend (FastAPI + Gradio)
@echo "Starting backend on port $(BACKEND_PORT)..."
$(UV) run uvicorn backend.main:app --reload --host 0.0.0.0 --port $(BACKEND_PORT) --timeout-graceful-shutdown 1
dev-frontend: ## Launch only the frontend (Vite + SvelteKit)
@echo "Starting frontend on port $(FRONTEND_PORT)..."
cd frontend && $(NPM) run dev
build-frontend: ## Build the frontend for production
@echo "Building frontend..."
cd frontend && $(NPM) run build
lint-python: ## Check python code
@echo "Checking python code..."
uv run mypy .
lint-frontend: ## Check frontend code
@echo "Checking frontend code..."
cd frontend && $(NPM) run lint
format-python: ## Format python code
@echo "Formatting python code..."
uv run autoflake .
uv run isort .
uv run black .
format-frontend: ## Format frontend code
@echo "Formatting frontend code..."
cd frontend && $(NPM) run format
check-requirements: ## Check that required tools are installed
@echo "Checking prerequisites..."
@command -v $(PYTHON) >/dev/null 2>&1 || { echo "Python 3 is required but not installed."; exit 1; }
@command -v $(NPM) >/dev/null 2>&1 || { echo "npm is required but not installed."; exit 1; }
@command -v $(UV) >/dev/null 2>&1 || { echo "uv is not installed. Run 'make install-backend' to install it."; }
@echo "All prerequisites are installed ✓"
clean: ## Clean generated files
@echo "Cleaning..."
rm -rf frontend/node_modules
rm -rf frontend/.svelte-kit
rm -rf frontend/build
rm -rf .venv
rm -rf __pycache__
find . -type d -name "__pycache__" -exec rm -rf {} +
find . -type f -name "*.pyc" -delete
###################################
# i18n utilities
###################################
i18n-clean-locales: ## Remove locales keys not present in fr
@echo "Cleaning frontend locales keys..."
./comparia-cli internal i18n
###################################
# Dataset utilities
###################################
dataset-export: ## Export the datasets to the destinations set in the admin panel (requires COMPARIA_DB_URI)
@echo "Exporting datasets..."
@if [ -z "$$COMPARIA_DB_URI" ]; then \
echo "Error: COMPARIA_DB_URI is not defined"; \
exit 1; \
fi
$(UV) run python -m utils.dataset.run
dataset-export-dry-run: ## Build the datasets locally and send them nowhere (requires COMPARIA_DB_URI)
@echo "Exporting datasets..."
@if [ -z "$$COMPARIA_DB_URI" ]; then \
echo "Error: COMPARIA_DB_URI is not defined"; \
exit 1; \
fi
$(UV) run python -m utils.dataset.run --dry-run
###################################
# Helm chart (devops/helm/comparia)
###################################
helm-lint: ## Lint the self-hosting Helm chart
helm lint $(HELM_CHART) -f $(HELM_CHART)/ci/values-lint.yaml
helm-test: ## Run the Helm chart's helm-unittest suite
helm unittest $(HELM_CHART)