-
Notifications
You must be signed in to change notification settings - Fork 508
Expand file tree
/
Copy pathMakefile
More file actions
186 lines (156 loc) · 6.06 KB
/
Makefile
File metadata and controls
186 lines (156 loc) · 6.06 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
.DEFAULT_GOAL := help
DOCKER_COMPOSE ?= docker-compose
ENV ?= development
VALID_ENVS := development staging production test
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
define check_env
@if ! echo "$(VALID_ENVS)" | grep -qw "$(ENV)"; then \
echo "Invalid ENV=$(ENV). Must be one of: $(VALID_ENVS)"; exit 1; \
fi
endef
define load_env_file
$(call check_env)
@ENV_FILE=.env.$(ENV); \
if [ ! -f $$ENV_FILE ]; then \
echo "Environment file $$ENV_FILE not found. Please create it."; exit 1; \
fi
endef
# Shorthand: source env vars then run a command
run_with_env = bash -c "source scripts/set_env.sh $(ENV) && $(1)"
# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
install:
pip install uv
uv sync
uv run pre-commit install
# ---------------------------------------------------------------------------
# Server
# ---------------------------------------------------------------------------
dev:
@$(call run_with_env,uv run uvicorn app.main:app --reload --port 8000)
staging:
@$(call run_with_env,$(MAKE) _serve ENV=staging)
prod:
@$(call run_with_env,$(MAKE) _serve ENV=production)
_serve:
@$(call run_with_env,./.venv/bin/python -m uvicorn app.main:app --host 0.0.0.0 --port 8000 --loop uvloop)
# ---------------------------------------------------------------------------
# Database migrations
# ---------------------------------------------------------------------------
migrate:
@$(call run_with_env,uv run alembic upgrade head)
migration:
@if [ -z "$(MSG)" ]; then \
echo "Usage: make migration MSG=\"describe your change\""; exit 1; \
fi
@$(call run_with_env,uv run alembic revision --autogenerate -m '$(MSG)')
migrate-downgrade:
@$(call run_with_env,uv run alembic downgrade -1)
migrate-history:
@$(call run_with_env,uv run alembic history --verbose)
# ---------------------------------------------------------------------------
# Evaluation
# ---------------------------------------------------------------------------
eval:
@$(call run_with_env,python -m evals.main --interactive)
eval-quick:
@$(call run_with_env,python -m evals.main --quick)
eval-no-report:
@$(call run_with_env,python -m evals.main --no-report)
# ---------------------------------------------------------------------------
# Code quality
# ---------------------------------------------------------------------------
lint:
ruff check .
format:
ruff format .
pre-commit:
uv run pre-commit run --all-files
pre-commit-update:
uv run pre-commit autoupdate
# ---------------------------------------------------------------------------
# Docker — single service (API + DB)
# ---------------------------------------------------------------------------
docker-build:
$(call check_env)
@./scripts/build-docker.sh $(ENV)
docker-up:
$(call load_env_file)
@APP_ENV=$(ENV) $(DOCKER_COMPOSE) --env-file .env.$(ENV) up -d --build db app
docker-down:
$(call load_env_file)
@APP_ENV=$(ENV) $(DOCKER_COMPOSE) --env-file .env.$(ENV) down
docker-logs:
$(call load_env_file)
@APP_ENV=$(ENV) $(DOCKER_COMPOSE) --env-file .env.$(ENV) logs -f app db
# ---------------------------------------------------------------------------
# Docker — full stack (API + DB + Prometheus + Grafana)
# ---------------------------------------------------------------------------
stack-up:
$(call load_env_file)
@APP_ENV=$(ENV) $(DOCKER_COMPOSE) --env-file .env.$(ENV) up -d
stack-down:
$(call load_env_file)
@APP_ENV=$(ENV) $(DOCKER_COMPOSE) --env-file .env.$(ENV) down
stack-logs:
$(call load_env_file)
@APP_ENV=$(ENV) $(DOCKER_COMPOSE) --env-file .env.$(ENV) logs -f
# ---------------------------------------------------------------------------
# Misc
# ---------------------------------------------------------------------------
clean:
rm -rf .venv __pycache__ .pytest_cache
# ---------------------------------------------------------------------------
# Help
# ---------------------------------------------------------------------------
help:
@echo "Usage: make <target> [ENV=development|staging|production|test]"
@echo ""
@echo "Setup:"
@echo " install Install deps, set up pre-commit hooks"
@echo ""
@echo "Server:"
@echo " dev Dev server with hot reload (port 8000)"
@echo " staging Staging server"
@echo " prod Production server"
@echo ""
@echo "Database:"
@echo " migrate Run migrations to latest (default ENV=development)"
@echo " migration MSG=... Generate migration from model changes"
@echo " migrate-downgrade Rollback last migration"
@echo " migrate-history Show migration history"
@echo ""
@echo "Evaluation:"
@echo " eval Run evals (interactive)"
@echo " eval-quick Run evals (default settings)"
@echo " eval-no-report Run evals without report"
@echo ""
@echo "Code quality:"
@echo " lint Ruff lint check"
@echo " format Ruff format"
@echo " pre-commit Run all pre-commit hooks"
@echo " pre-commit-update Update pre-commit hook versions"
@echo ""
@echo "Docker (API + DB):"
@echo " docker-build Build Docker image"
@echo " docker-up Start API + DB containers"
@echo " docker-down Stop containers"
@echo " docker-logs Tail container logs"
@echo ""
@echo "Docker (full stack — includes Prometheus + Grafana):"
@echo " stack-up Start entire stack"
@echo " stack-down Stop entire stack"
@echo " stack-logs Tail all service logs"
@echo ""
@echo "Misc:"
@echo " clean Remove .venv, __pycache__, .pytest_cache"
.PHONY: install dev staging prod _serve \
migrate migration migrate-downgrade migrate-history \
eval eval-quick eval-no-report \
lint format pre-commit pre-commit-update \
docker-build docker-up docker-down docker-logs \
stack-up stack-down stack-logs \
clean help