-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
125 lines (103 loc) · 4.66 KB
/
Copy pathMakefile
File metadata and controls
125 lines (103 loc) · 4.66 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
.PHONY: help install run worker migrate revision seed test lint format up up-infra down build logs psql redis-cli tunnel grafana-dashboards
help:
@echo "Common targets:"
@echo " make install — sync deps via uv"
@echo " make up — start the full stack (postgres, redis, api, worker)"
@echo " make up-infra — start only postgres + redis (use with host-side make run / make worker)"
@echo " make down — stop all containers"
@echo " make build — rebuild the conduct image"
@echo " make migrate — run alembic upgrade head (host-side, against the compose postgres)"
@echo " make revision m=\"message\" — create alembic autogenerate revision"
@echo " make run — run the FastAPI app on :8000 with reload (host-side dev)"
@echo " make worker — run the RQ worker (host-side dev)"
@echo " make seed — bootstrap clients + routing rules (idempotent)"
@echo " make test — run pytest"
@echo " make lint — ruff check"
@echo " make format — ruff format"
@echo " make psql — open psql against the dev database"
@echo " make redis-cli — open redis-cli against the dev redis"
@echo " make tunnel — start the ngrok HTTPS tunnel"
@echo " make reload-pricing — SIGUSR1 the api + worker to reload config/pricing.yaml without restart"
@echo " make download-voice [v=<voice-name>] — download a Piper TTS voice (default en_US-amy-medium)"
@echo " make coverage — run pytest with coverage, write coverage.xml"
@echo " make sonar-scan — run SonarQube static analysis (results at http://localhost:9000/dashboard?id=conduct)"
install:
uv sync
up:
docker compose up -d
@echo "Waiting for postgres..."
@until docker compose exec -T postgres pg_isready -U conduct >/dev/null 2>&1; do sleep 1; done
@echo "Postgres ready."
up-infra:
docker compose up -d postgres redis
@echo "Waiting for postgres..."
@until docker compose exec -T postgres pg_isready -U conduct >/dev/null 2>&1; do sleep 1; done
@echo "Postgres ready."
down:
docker compose down
build:
GIT_SHA=$$(git rev-parse HEAD 2>/dev/null || echo "") docker compose build api worker
migrate:
uv run alembic upgrade head
revision:
@if [ -z "$(m)" ]; then echo "Usage: make revision m=\"message\""; exit 1; fi
uv run alembic revision --autogenerate -m "$(m)"
run:
uv run uvicorn main:app --reload --host 0.0.0.0 --port 8000
worker:
uv run python -m worker.queue
seed:
uv run python -m scripts.seed
test:
uv run pytest
lint:
uv run ruff check .
format:
uv run ruff format .
psql:
docker compose exec postgres psql -U conduct -d conduct
redis-cli:
docker compose exec redis redis-cli
tunnel:
ngrok http 8000
reload-pricing:
@docker kill --signal=USR1 conduct-api conduct-worker
@echo "SIGUSR1 sent — check the api/worker logs for 'pricing reloaded'"
# Run SonarQube static analysis against the local watchtower instance.
# First runs pytest with coverage (writes coverage.xml in Cobertura format,
# which SonarQube ingests), then ships the project + coverage to the local
# SonarQube. Reads SONAR_TOKEN from .env. Results appear at
# http://localhost:9000/dashboard?id=conduct
sonar-scan: coverage
@if [ -z "$$SONAR_TOKEN" ] && ! grep -q '^SONAR_TOKEN=' .env 2>/dev/null; then \
echo "Set SONAR_TOKEN in .env (generate at http://localhost:9000)"; exit 1; \
fi
@set -a; . ./.env; set +a; \
docker run --rm \
-e SONAR_HOST_URL=http://host.docker.internal:9000 \
-e SONAR_TOKEN=$$SONAR_TOKEN \
-v "$$(pwd):/usr/src" \
sonarsource/sonar-scanner-cli:latest
# Run tests under coverage. Writes coverage.xml (Cobertura) for SonarQube
# ingestion plus a terminal summary.
coverage:
uv run pytest --cov --cov-report=xml --cov-report=term -q
# Download a Piper voice into ./voices. Override v=<voice-name> to grab a
# different one. Browse https://huggingface.co/rhasspy/piper-voices for the
# full catalog. The default en_US-amy-medium is ~25MB.
v ?= en_US-amy-medium
download-voice:
@mkdir -p voices
@LANG=$$(echo "$(v)" | cut -d_ -f1); \
REGION=$$(echo "$(v)" | cut -d_ -f2 | cut -d- -f1); \
NAME=$$(echo "$(v)" | cut -d- -f2); \
QUALITY=$$(echo "$(v)" | cut -d- -f3); \
BASE="https://huggingface.co/rhasspy/piper-voices/resolve/main/$$LANG/$${LANG}_$${REGION}/$$NAME/$${QUALITY}/$(v)"; \
echo "Downloading $(v) from $$BASE..."; \
curl -sSL "$$BASE.onnx" -o "voices/$(v).onnx" && \
curl -sSL "$$BASE.onnx.json" -o "voices/$(v).onnx.json" && \
echo "Done. Voice ready at voices/$(v).onnx"
# Push Conduct's Grafana dashboards (grafana/dashboards/*.json) into Grafana.
# Reads GRAFANA_URL + GRAFANA_TOKEN or GRAFANA_USER/GRAFANA_PASSWORD from .env.
grafana-dashboards:
@set -a; [ -f .env ] && . ./.env; set +a; uv run python -m scripts.push_dashboards