Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
123 lines (100 loc) · 4.93 KB
/
Copy pathMakefile
File metadata and controls
123 lines (100 loc) · 4.93 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
# Everything here runs with no infrastructure. Postgres targets are opt-in.
PY := .venv/bin/python
VENV := .venv
LOCAL_DSN := postgresql://toolguard:toolguard@localhost:5433/toolguard
.DEFAULT_GOAL := help
.PHONY: help
help: ## Show this help
@grep -hE '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-16s\033[0m %s\n", $$1, $$2}'
$(VENV):
python3 -m venv $(VENV)
$(PY) -m pip install --quiet --upgrade pip
$(PY) -m pip install --quiet -e ".[dev,otel]"
.PHONY: install
install: $(VENV) ## Create the virtualenv and install the package with dev extras
.PHONY: test
test: install ## Run the full test suite (SQLite only, no infrastructure needed)
$(PY) -m pytest
.PHONY: postgres-up
postgres-up: install ## Start Postgres, create the runtime role, run migrations
docker compose -f deploy/docker-compose.yml up -d postgres
@until docker compose -f deploy/docker-compose.yml exec -T postgres pg_isready -U toolguard -q; do sleep 1; done
@docker compose -f deploy/docker-compose.yml exec -T postgres psql -q -U toolguard -d toolguard \
-c "DO \$$\$$ BEGIN IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname='gateway_app') \
THEN CREATE ROLE gateway_app LOGIN PASSWORD 'local-dev-only'; END IF; END \$$\$$;"
DATABASE_URL=$(LOCAL_DSN) $(PY) -m alembic -x role=gateway_app upgrade head
@docker compose -f deploy/docker-compose.yml exec -T postgres psql -q -U toolguard -d toolguard \
-c "CREATE SCHEMA IF NOT EXISTS partman; CREATE EXTENSION IF NOT EXISTS pg_partman WITH SCHEMA partman;" \
|| echo " (pg_partman unavailable in this image; partition maintenance needs it)"
DATABASE_URL=$(LOCAL_DSN) $(PY) scripts/setup_partman.py || true
@echo "postgres ready on localhost:5433"
@echo " owner: $(LOCAL_DSN)"
@echo " runtime: postgresql://gateway_app:local-dev-only@localhost:5433/toolguard"
.PHONY: postgres-down
postgres-down: ## Stop Postgres and delete its data
docker compose -f deploy/docker-compose.yml down -v
.PHONY: test-postgres
test-postgres: install ## Run the Postgres suites (needs `make postgres-up`)
@test -n "$$TEST_DATABASE_URL" || { echo "set TEST_DATABASE_URL first"; exit 1; }
$(PY) -m pip install --quiet -e ".[postgres,otel]"
$(PY) -m pytest -m postgres
.PHONY: loadtest
loadtest: install ## Load-test the Postgres path (needs `make postgres-up`)
$(PY) -m pip install --quiet -e ".[postgres]"
DATABASE_URL=$${DATABASE_URL:-$(LOCAL_DSN)} \
$(PY) benchmarks/load_test.py --pool 32
.PHONY: docker-build
docker-build: ## Build the gateway image with the guardrail installed
docker build -t toolguard-gateway:local -f deploy/Dockerfile .
.PHONY: chaos
chaos: install ## Kill Postgres under load; assert nothing destructive is allowed
$(PY) -m pip install --quiet -e ".[postgres]"
DATABASE_URL=$${DATABASE_URL:-$(LOCAL_DSN)} $(PY) benchmarks/chaos_test.py
.PHONY: soak
soak: install ## Longer load run, to surface pool and autovacuum behaviour
$(PY) -m pip install --quiet -e ".[postgres]"
DATABASE_URL=$${DATABASE_URL:-$(LOCAL_DSN)} \
$(PY) benchmarks/load_test.py --pool 32 --scale 200
.PHONY: integration
integration: ## Run the LiteLLM integration tests inside the gateway image
docker build -q -t toolguard-gateway:local -f deploy/Dockerfile . >/dev/null
docker run --rm --entrypoint sh -v "$$PWD":/w -w /w toolguard-gateway:local -c \
"pip install --quiet pytest >/dev/null 2>&1 && python -m pytest tests/integration -q"
.PHONY: partitions
partitions: install ## Show partition maintenance (dry run; detaches, never drops)
$(PY) -m pip install --quiet -e ".[postgres]"
DATABASE_URL=$${DATABASE_URL:-$(LOCAL_DSN)} \
$(PY) scripts/maintain_partitions.py
.PHONY: terraform
terraform: ## Validate, format-check and test the deployment module
cd infra/terraform && terraform init -backend=false -input=false >/dev/null
cd infra/terraform && terraform fmt -check -recursive
cd infra/terraform && terraform validate
cd infra/terraform && terraform test
.PHONY: lint
lint: install ## Lint and format-check
$(PY) -m ruff check src tests benchmarks scripts migrations
$(PY) -m ruff format --check src tests benchmarks scripts migrations
.PHONY: format
format: install ## Apply formatting
$(PY) -m ruff format src tests benchmarks scripts migrations
$(PY) -m ruff check --fix src tests benchmarks scripts migrations
.PHONY: typecheck
typecheck: install ## Static type check
$(PY) -m mypy
.PHONY: demo
demo: install ## Run the scenario walkthrough
$(PY) -m toolguard.demo
.PHONY: migrate
migrate: install ## Apply database migrations
DATABASE_URL=$${DATABASE_URL:-$(LOCAL_DSN)} \
$(PY) -m alembic -x role=$${RUNTIME_ROLE:-gateway_app} upgrade head
.PHONY: migration
migration: install ## Create a new migration: make migration m="what it does"
$(PY) -m alembic revision -m "$(m)"
.PHONY: check
check: lint typecheck test ## The checks CI runs without infrastructure
.PHONY: clean
clean: ## Remove caches and the virtualenv
rm -rf $(VENV) .pytest_cache .mypy_cache .ruff_cache **/__pycache__ *.egg-info