-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathMakefile
More file actions
130 lines (111 loc) · 4.56 KB
/
Copy pathMakefile
File metadata and controls
130 lines (111 loc) · 4.56 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
.PHONY: bootstrap install-prod compose-up compose-down compose-logs db-migrate dev build start lint test typecheck \
schemas gen-api web-build docker-up docker-down docker-logs
WEB_PORT ?= 3068
API_PORT ?= 8000
DATA_DIR ?= data
DATABASE_URL ?= sqlite:///$(DATA_DIR)/viskit.db
CONFIG_PATH ?= $(DATA_DIR)/config.yaml
IMAGEGEN_OUTPUT_DIR ?= $(DATA_DIR)/imagegen
## bootstrap: install pnpm + uv deps + pre-commit hooks
bootstrap:
pnpm install
uv sync --extra dev
uv run pre-commit install
## install-prod: install runtime dependencies for source deployment
install-prod:
@if command -v corepack >/dev/null 2>&1; then \
corepack enable; \
corepack prepare pnpm@10.32.1 --activate; \
fi
pnpm install --frozen-lockfile
uv sync --frozen --no-dev
mkdir -p $(DATA_DIR)
test -f .env || cp .env.example .env
test -f $(CONFIG_PATH) || cp config.yaml.example $(CONFIG_PATH)
## compose-up: start optional PostgreSQL in detached mode (waits for healthchecks)
compose-up:
docker compose -f infra/docker-compose.yml up -d --wait
## compose-down: stop and remove optional PostgreSQL containers
compose-down:
docker compose -f infra/docker-compose.yml down
## compose-logs: tail optional PostgreSQL logs
compose-logs:
docker compose -f infra/docker-compose.yml logs -f
## db-migrate: apply SQLite/PostgreSQL schema migrations and seed the local workspace
db-migrate:
uv run python -m apps.api.lib.db
## dev: run Next.js + FastAPI concurrently
dev:
@set -eu; \
kill_tree() { \
for child in $$(pgrep -P "$$1" 2>/dev/null || true); do kill_tree "$$child"; done; \
kill "$$1" >/dev/null 2>&1 || true; \
}; \
( cd apps/web && PORT=$(WEB_PORT) NEXT_PUBLIC_API_BASE_URL=http://localhost:$(API_PORT) pnpm dev ) & \
web_pid=$$!; \
cleanup() { kill_tree "$$web_pid"; wait "$$web_pid" >/dev/null 2>&1 || true; }; \
trap cleanup EXIT INT TERM; \
CORS_ALLOW_ORIGINS=http://localhost:$(WEB_PORT),http://127.0.0.1:$(WEB_PORT) uv run python -m uvicorn apps.api.main:app --reload --port $(API_PORT)
## build: build the production web app for source deployment
build: gen-api
NEXT_PUBLIC_API_BASE_URL=http://localhost:$(API_PORT) pnpm --filter @viskit/web build
rm -rf apps/web/.next/standalone/apps/web/.next/static apps/web/.next/standalone/apps/web/public
mkdir -p apps/web/.next/standalone/apps/web/.next
cp -R apps/web/.next/static apps/web/.next/standalone/apps/web/.next/static
cp -R apps/web/public apps/web/.next/standalone/apps/web/public
## start: run FastAPI + compiled Next.js without dev reloaders
start:
@set -eu; \
mkdir -p $(DATA_DIR) $(IMAGEGEN_OUTPUT_DIR); \
test -f $(CONFIG_PATH) || cp config.yaml.example $(CONFIG_PATH); \
kill_tree() { \
for child in $$(pgrep -P "$$1" 2>/dev/null || true); do kill_tree "$$child"; done; \
kill "$$1" >/dev/null 2>&1 || true; \
}; \
CONFIG_PATH=$(CONFIG_PATH) IMAGEGEN_OUTPUT_DIR=$(IMAGEGEN_OUTPUT_DIR) DATABASE_URL=$(DATABASE_URL) \
CORS_ALLOW_ORIGINS=http://localhost:$(WEB_PORT),http://127.0.0.1:$(WEB_PORT) \
uv run python -m uvicorn apps.api.main:app --host 0.0.0.0 --port $(API_PORT) & \
api_pid=$$!; \
cleanup() { kill_tree "$$api_pid"; wait "$$api_pid" >/dev/null 2>&1 || true; }; \
trap cleanup EXIT INT TERM; \
until (echo > /dev/tcp/127.0.0.1/$(API_PORT)) >/dev/null 2>&1; do \
if ! kill -0 "$$api_pid" 2>/dev/null; then wait "$$api_pid"; exit $$?; fi; \
sleep 0.2; \
done; \
HOSTNAME=0.0.0.0 PORT=$(WEB_PORT) NEXT_SERVER_API_BASE_URL=http://localhost:$(API_PORT) \
node apps/web/.next/standalone/apps/web/server.js & \
web_pid=$$!; \
cleanup() { kill_tree "$$api_pid"; kill_tree "$$web_pid"; wait "$$api_pid" "$$web_pid" >/dev/null 2>&1 || true; }; \
trap cleanup EXIT INT TERM; \
wait -n "$$api_pid" "$$web_pid"; \
status=$$?; \
exit "$$status"
## lint: run Biome (JS/TS) and Ruff (Python)
lint:
pnpm -r lint
uv run ruff check .
## test: run Python unit/regression tests
test:
uv run python -m unittest discover -v
## typecheck: run TypeScript and mypy checks
typecheck:
pnpm -r typecheck
uv run python -m mypy .
## schemas: generate OpenAPI + DB schemas
schemas:
cd packages/schemas && pnpm gen
## gen-api: generate apps/web TanStack-Query typed client from live FastAPI /openapi.json
gen-api:
pnpm --filter @viskit/web gen:api
## web-build: gen-api then Next.js build (paths types stay in sync before compile)
web-build: gen-api
pnpm --filter @viskit/web build
## docker-up: build and run the single-container app (SQLite + local files)
docker-up:
docker compose up -d --build
## docker-down: stop the single-container app
docker-down:
docker compose down
## docker-logs: tail single-container app logs
docker-logs:
docker compose logs -f