-
Notifications
You must be signed in to change notification settings - Fork 320
Expand file tree
/
Copy pathMakefile
More file actions
164 lines (138 loc) · 7.94 KB
/
Copy pathMakefile
File metadata and controls
164 lines (138 loc) · 7.94 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
PYTEST_ARGS := -q -ra -o faulthandler_timeout=300 -o faulthandler_exit_on_timeout=true --timeout=180 --timeout-method=thread --durations=20
POSTGRES_TEST_DATABASE_URL ?= postgresql+asyncpg://codex_lb:codex_lb@127.0.0.1:5432/codex_lb
POSTGRES_PYTEST_TARGETS := \
tests/integration/test_migrations.py::test_postgresql_migration_contract_policy_and_drift_match \
tests/integration/test_migrations.py::test_postgresql_upgrade_head_from_empty_database \
tests/integration/test_migrations.py::test_postgresql_startup_migration_auto_remap_legacy_head \
tests/integration/test_usage_repository.py::test_latest_by_account_primary_query_plan_uses_normalized_window_index_postgresql \
tests/integration/test_repositories.py::test_accounts_upsert_with_merge_enabled_serializes_concurrent_same_email \
tests/integration/test_proxy_api_extended.py::test_proxy_stream_usage_limit_returns_http_error \
tests/integration/test_repositories.py::test_accounts_upsert_with_merge_disabled_uses_identity_lock_on_postgresql
SHELL := /bin/bash
.PHONY: help
help:
@printf '%s\n' \
'Common targets:' \
' make lint ruff check + format check + architecture checks' \
' make architecture-check proxy architecture fitness ratchets' \
' make typecheck ty check' \
' make frontend-test vitest coverage, same as CI' \
' make test-unit unit pytest slice, same as CI' \
' make test-integration-core integration-core pytest slice' \
' make package build and verify sdist/wheel' \
' make ci-fast lint/type/frontend/unit/package' \
' make ci full local CI gate'
.PHONY: frontend-install frontend-lint frontend-typecheck frontend-test frontend-build
frontend-install:
cd frontend && bun install --frozen-lockfile
frontend-lint: frontend-install
cd frontend && bun run lint
frontend-typecheck: frontend-install
cd frontend && bun run typecheck
frontend-test: frontend-install
cd frontend && bun run test:coverage
frontend-build: frontend-install
cd frontend && bun run build
.PHONY: lint typecheck architecture-check
lint: architecture-check
uvx ruff check .
uvx ruff format --check .
architecture-check:
python scripts/check_proxy_architecture.py
typecheck:
uv sync --dev --frozen
uv run ty check
.PHONY: test-unit test-integration-core test-integration-bridge test-e2e test-postgres
test-unit: frontend-build
uv sync --dev --frozen
PYTHONFAULTHANDLER=1 uv run pytest $(PYTEST_ARGS) tests/unit tests/test_request_logs_options_api.py
test-integration-core: frontend-build
uv sync --dev --frozen
PYTHONFAULTHANDLER=1 uv run pytest $(PYTEST_ARGS) tests/integration \
--ignore=tests/integration/test_http_responses_bridge.py \
--ignore=tests/integration/test_proxy_websocket_responses.py
test-integration-bridge: frontend-build
uv sync --dev --frozen
PYTHONFAULTHANDLER=1 uv run pytest $(PYTEST_ARGS) -vv \
tests/integration/test_http_responses_bridge.py \
tests/integration/test_proxy_websocket_responses.py
test-e2e: frontend-build
uv sync --dev --frozen
PYTHONFAULTHANDLER=1 uv run pytest $(PYTEST_ARGS) tests/e2e
test-postgres:
uv sync --dev --frozen
CODEX_LB_TEST_DATABASE_URL="$${CODEX_LB_TEST_DATABASE_URL:-$(POSTGRES_TEST_DATABASE_URL)}" \
PYTHONFAULTHANDLER=1 \
uv run pytest $(PYTEST_ARGS) $(POSTGRES_PYTEST_TARGETS)
.PHONY: migration-check migration-check-postgres
migration-check:
uv sync --dev --frozen
TMP_DB="$$(mktemp -u /tmp/codex-lb-ci-migrate-XXXXXX.db)"; \
DB_URL="sqlite+aiosqlite:///$${TMP_DB}"; \
trap 'rm -f "$${TMP_DB}"' EXIT; \
uv run codex-lb-db --db-url "$${DB_URL}" upgrade head; \
uv run codex-lb-db --db-url "$${DB_URL}" check
migration-check-postgres:
uv sync --dev --frozen
uv run codex-lb-db --db-url "$(POSTGRES_TEST_DATABASE_URL)" upgrade head
uv run codex-lb-db --db-url "$(POSTGRES_TEST_DATABASE_URL)" check
.PHONY: package
package: frontend-build
uv sync --frozen --no-dev
uv run python -c "import app; import app.main; print('import ok')"
rm -rf build dist *.egg-info
uvx --from build==1.3.0 python -m build
python scripts/verify-wheel-assets.py
.PHONY: docker
docker:
docker build -t codex-lb:ci .
trivy image --format table --exit-code 1 --severity CRITICAL --ignore-unfixed codex-lb:ci
.PHONY: helm-deps helm-lint helm-template helm-kubeconform
helm-deps:
helm dependency build deploy/helm/codex-lb/
helm-lint: helm-deps
helm lint --strict deploy/helm/codex-lb/ --set postgresql.auth.password=test-password
helm lint --strict deploy/helm/codex-lb/ -f deploy/helm/codex-lb/values-dev.yaml --set postgresql.auth.password=test-password
helm lint --strict deploy/helm/codex-lb/ -f deploy/helm/codex-lb/values-bundled.yaml --set postgresql.auth.password=test-password
helm lint --strict deploy/helm/codex-lb/ -f deploy/helm/codex-lb/values-external-db.yaml --set externalDatabase.url=postgresql+asyncpg://test:test@localhost/test
helm lint --strict deploy/helm/codex-lb/ -f deploy/helm/codex-lb/values-external-secrets.yaml --set externalSecrets.secretStoreRef.name=test-store
helm lint --strict deploy/helm/codex-lb/ -f deploy/helm/codex-lb/values-staging.yaml --set externalDatabase.url=postgresql+asyncpg://test:test@localhost/test
helm lint --strict deploy/helm/codex-lb/ -f deploy/helm/codex-lb/values-prod.yaml --set externalSecrets.secretStoreRef.name=test-store
helm-template:
helm template codex-lb deploy/helm/codex-lb/ --set postgresql.auth.password=test-password > /dev/null
helm template codex-lb deploy/helm/codex-lb/ -f deploy/helm/codex-lb/values-dev.yaml --set postgresql.auth.password=test-password > /dev/null
helm template codex-lb deploy/helm/codex-lb/ -f deploy/helm/codex-lb/values-bundled.yaml --set postgresql.auth.password=test-password > /dev/null
helm template codex-lb deploy/helm/codex-lb/ -f deploy/helm/codex-lb/values-external-db.yaml --set externalDatabase.url=postgresql+asyncpg://test:test@localhost/test > /dev/null
helm template codex-lb deploy/helm/codex-lb/ -f deploy/helm/codex-lb/values-external-secrets.yaml --set externalSecrets.secretStoreRef.name=test-store > /dev/null
helm template codex-lb deploy/helm/codex-lb/ -f deploy/helm/codex-lb/values-staging.yaml --set externalDatabase.url=postgresql+asyncpg://test:test@localhost/test > /dev/null
helm template codex-lb deploy/helm/codex-lb/ -f deploy/helm/codex-lb/values-prod.yaml --set externalSecrets.secretStoreRef.name=test-store > /dev/null
helm-kubeconform:
set -e -o pipefail; \
for version in 1.32.0 1.35.0; do \
helm template codex-lb deploy/helm/codex-lb/ \
-f deploy/helm/codex-lb/values-prod.yaml \
--set externalSecrets.secretStoreRef.name=test \
--set externalSecrets.secretStoreRef.kind=SecretStore \
--set gatewayApi.enabled=true \
--set "gatewayApi.parentRefs[0].name=test-gw" \
--set "gatewayApi.hostnames[0]=test.example.com" \
| kubeconform \
-strict \
-kubernetes-version "$${version}" \
-schema-location default \
-schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json' \
-summary; \
done
.PHONY: helm-check helm-smoke-kind
helm-check: helm-lint helm-template helm-kubeconform
helm-smoke-kind:
kind create cluster --name codex-lb-smoke --image kindest/node:v1.35.0 --wait 120s
docker build -t ghcr.io/soju06/codex-lb:ci .
kind load docker-image ghcr.io/soju06/codex-lb:ci --name codex-lb-smoke
KUBE_CONTEXT=kind-codex-lb-smoke IMAGE_REGISTRY=ghcr.io IMAGE_REPOSITORY=soju06/codex-lb IMAGE_TAG=ci ./scripts/helm-kind-smoke.sh bundled
KUBE_CONTEXT=kind-codex-lb-smoke IMAGE_REGISTRY=ghcr.io IMAGE_REPOSITORY=soju06/codex-lb IMAGE_TAG=ci ./scripts/helm-kind-smoke.sh external-db
.PHONY: ci-fast ci
ci-fast: lint typecheck frontend-test test-unit package
ci: frontend-lint frontend-typecheck frontend-test frontend-build lint typecheck \
test-unit test-integration-core test-integration-bridge test-e2e test-postgres \
migration-check migration-check-postgres package docker helm-check helm-smoke-kind