-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmakefile
More file actions
331 lines (282 loc) · 12.4 KB
/
makefile
File metadata and controls
331 lines (282 loc) · 12.4 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
SHELL := /bin/bash
# Container registry configuration
REGISTRY ?= ghcr.io/analytiq-hub
FRONTEND_IMAGE = $(REGISTRY)/doc-router-frontend
BACKEND_IMAGE = $(REGISTRY)/doc-router-backend
IMAGE_TAG ?= latest
export IMAGE_TAG
DOCKERFILE = deploy/shared/docker/Dockerfile
# Build args for frontend (NEXT_PUBLIC_ vars are baked into Next.js build at build time)
NEXT_PUBLIC_FASTAPI_FRONTEND_URL ?= http://localhost:8000
NODE_ENV ?= production
help:
@echo "Available make targets:"
@echo ""
@echo " make help - Show this help message"
@echo ""
@echo "Setup & Installation:"
@echo " make setup - Interactive menu: Python, TypeScript, Dev (both), Kubernetes, or UI setup"
@echo " make setup-dev - Set up both Python and TypeScript (full dev environment)"
@echo " make setup-python - Set up Python virtual environment and dependencies"
@echo " make setup-typescript - Install and build all TypeScript packages"
@echo " make setup-kind - Set up Kubernetes kind cluster"
@echo " make setup-ui - Set up UI test environment"
@echo ""
@echo "Deployment (Interactive):"
@echo " make deploy - Interactive menu: Local, Docker Compose, or Kubernetes"
@echo ""
@echo "Deployment (Direct):"
@echo " make deploy-local-dev - Deploy to local development environment"
@echo " make deploy-compose - Deploy to Docker Compose (builds images)"
@echo " make deploy-compose-embedded - Deploy to Docker Compose with embedded MongoDB (builds images)"
@echo " make deploy-kind - Deploy to Kubernetes kind cluster"
@echo ""
@echo "Shutdown (Interactive):"
@echo " make down - Interactive menu: Stop containers or remove volumes"
@echo ""
@echo "Shutdown (Direct):"
@echo " make logs - Follow Docker Compose logs with timestamps"
@echo " make down-compose - Stop Docker Compose containers"
@echo " make down-compose-clean - Stop Docker Compose and remove volumes"
@echo " make down-kind - Uninstall doc-router from Kind cluster (keeps cluster running)"
@echo " make destroy-kind - Delete the Kind cluster entirely"
@echo ""
@echo "Testing:"
@echo " make tests - Run Python unit tests (fast, excludes kb_slow)"
@echo " make tests-flow - Run flow engine tests only"
@echo " make flow-node-dump - Dump upstream integration nodes to tools/flow_node_dump.jsonl (override UPSTREAM_NODES_ROOT, FLOW_DUMP_SUBDIRS)"
@echo " make flow-node-port - Emit DocRouter packages from tools/flow_node_dump.jsonl"
@echo " make credential-dump - Dump n8n credential classes to tools/credential_dump.jsonl (needs built ../n8n/packages/nodes-base)"
@echo " make credential-port - Generate schemas/credential-kinds/*.json from tools/credential_dump.jsonl (optional CREDENTIAL_PORT_ARGS)"
@echo " make tests-kb - Run slow KB integration tests (real search indexes)"
@echo " make tests-scale - Run Python scale tests"
@echo " make tests-all - Run all Python tests"
@echo " make tests-ui - Run UI tests"
@echo " make tests-ui-debug - Run UI tests in debug mode"
@echo " make tests-ts - Run TypeScript SDK and MCP tests"
@echo " make vitest - Run frontend Vitest unit tests (flows schema helpers, etc.)"
@echo ""
@echo "Cleanup:"
@echo " make clean - Remove Python virtual environment"
setup:
@if ! command -v gum &> /dev/null; then \
echo "Error: gum is not installed. Please install it first:"; \
echo " On macOS: brew install gum"; \
echo " On Linux: See https://github.com/charmbracelet/gum#installation"; \
exit 1; \
fi; \
choice=$$(gum choose --header "Select setup target:" \
"Development Environment (Python + TypeScript)" \
"Python Environment" \
"TypeScript Packages" \
"Kubernetes (kind)" \
"UI Test Environment"); \
case "$$choice" in \
"Development Environment (Python + TypeScript)") \
$(MAKE) setup-dev;; \
"Python Environment") \
$(MAKE) setup-python;; \
"TypeScript Packages") \
$(MAKE) setup-typescript;; \
"Kubernetes (kind)") \
$(MAKE) setup-kind;; \
"UI Test Environment") \
$(MAKE) setup-ui;; \
*) \
echo "No selection made or cancelled."; \
exit 1;; \
esac
setup-python:
# Create and activate virtual environment if it doesn't exist
if [ ! -d ".venv" ]; then \
echo "Creating virtual environment..." ; \
python3 -m venv .venv ; \
fi ; \
source .venv/bin/activate ; \
# Install uv if not already installed
if ! command -v uv &> /dev/null; then \
echo "Installing uv..." ; \
curl -LsSf https://astral.sh/uv/install.sh | sh ; \
fi ; \
# Install build dependencies
uv pip install hatchling ; \
# Install packages in order
uv pip install -r packages/python/requirements.txt ; \
uv pip install -e packages/python/sdk ; \
# Ensure test dependencies are installed
uv pip install pytest-asyncio pytest-cov pytest-xdist
setup-dev: setup-python setup-typescript
deploy-dev: setup-python
cp .env packages/typescript/frontend/.env.local
./start-all.sh
setup-typescript: setup-python
# Install and build all TypeScript packages
cd packages/typescript/sdk && npm install && npm run build
cd packages/typescript/mcp && npm install && npm run build
cd packages/typescript/frontend && npm install
# Legacy deployment
#deploy:
# # Use .env for runtime env vars without baking them into images
# docker compose down ; \
# docker compose --env-file .env up -d --build
deploy:
@if ! command -v gum &> /dev/null; then \
echo "Error: gum is not installed. Please install it first:"; \
echo " On macOS: brew install gum"; \
echo " On Linux: See https://github.com/charmbracelet/gum#installation"; \
exit 1; \
fi; \
choice=$$(gum choose --header "Select deployment target:" \
"Local Development" \
"Docker Compose (build images)" \
"Docker Compose (Embedded MongoDB, build images)" \
"Kubernetes (kind)"); \
case "$$choice" in \
"Local Development") \
$(MAKE) deploy-local-dev;; \
"Docker Compose (build images)") \
$(MAKE) deploy-compose;; \
"Docker Compose (Embedded MongoDB, build images)") \
$(MAKE) deploy-compose-embedded;; \
"Kubernetes (kind)") \
$(MAKE) deploy-kind;; \
*) \
echo "No selection made or cancelled."; \
exit 1;; \
esac
define merge_env
awk -F= '!/^[[:space:]]*#/ && /=/ { vals[$$1] = $$0 } END { for (k in vals) print vals[k] }' $(1) $(2) > deploy/compose/.env
endef
deploy-local-dev:
cp .env packages/typescript/frontend/.env.local
./start-all.sh
deploy-compose:
$(call merge_env,.env,.env.compose)
cd deploy/compose; \
docker compose down; \
docker compose -f docker-compose.yml --env-file .env up -d --build
deploy-compose-embedded:
$(call merge_env,.env,.env.compose.embedded)
cd deploy/compose; \
docker compose down; \
docker compose -f docker-compose.embedded.yml --env-file .env up -d --build
down:
@if ! command -v gum &> /dev/null; then \
echo "Error: gum is not installed. Please install it first:"; \
echo " On macOS: brew install gum"; \
echo " On Linux: See https://github.com/charmbracelet/gum#installation"; \
exit 1; \
fi; \
choice=$$(gum choose --header "Select shutdown target:" \
"Docker Compose (stop containers)" \
"Docker Compose (stop and remove volumes)" \
"Kubernetes (kind) — uninstall app" \
"Kubernetes (kind) — destroy cluster"); \
case "$$choice" in \
"Docker Compose (stop containers)") \
$(MAKE) down-compose;; \
"Docker Compose (stop and remove volumes)") \
$(MAKE) down-compose-clean;; \
"Kubernetes (kind) — uninstall app") \
$(MAKE) down-kind;; \
"Kubernetes (kind) — destroy cluster") \
$(MAKE) destroy-kind;; \
*) \
echo "No selection made or cancelled."; \
exit 1;; \
esac
logs:
cd deploy/compose && docker compose logs -f --timestamps
down-compose:
cd deploy/compose; \
docker compose -f docker-compose.yml down 2>/dev/null || true; \
docker compose -f docker-compose.embedded.yml down 2>/dev/null || true
down-compose-clean:
cd deploy/compose; \
docker compose -f docker-compose.embedded.yml down -v 2>/dev/null || true; \
docker compose -f docker-compose.yml down -v 2>/dev/null || true; \
docker volume rm compose_doc-router-local-mongodb 2>/dev/null || true; \
echo "Removed containers and volumes"
setup-kind:
./deploy/scripts/setup-kind.sh
deploy-kind:
./deploy/scripts/deploy-kind.sh
down-kind:
./deploy/scripts/down-kind.sh
destroy-kind:
./deploy/scripts/destroy-kind.sh
tests: setup-python
. .venv/bin/activate && pytest -n auto -m "not kb_slow" packages/python/tests/
tests-flow: setup-python
. .venv/bin/activate && pytest -q packages/python/tests/flows/
# Repository root (directory containing this makefile). Paths below work with `make -f /abs/path/makefile`.
_DOC_ROUTER_ROOT := $(abspath $(dir $(firstword $(MAKEFILE_LIST))))
# Sibling upstream checkout with a built packages/nodes-base/dist (pnpm install && pnpm build).
UPSTREAM_NODES_ROOT ?= $(abspath $(_DOC_ROUTER_ROOT)/../n8n)
FLOW_DUMP_SUBDIRS ?= packages/nodes-base/dist/nodes
flow-node-dump:
mkdir -p tools
tmp=$$(mktemp); \
trap 'rm -f "$$tmp"' EXIT; \
FLOW_DUMP_SUBDIRS="$(FLOW_DUMP_SUBDIRS)" node --disable-warning=DEP0040 tools/dump_nodes.js --upstream-root "$(UPSTREAM_NODES_ROOT)" > "$$tmp" && \
mv -f "$$tmp" tools/flow_node_dump.jsonl
flow-node-port: setup-python
. .venv/bin/activate && python tools/port_nodes.py tools/flow_node_dump.jsonl --validate
credential-dump:
mkdir -p tools
tmp=$$(mktemp); \
trap 'rm -f "$$tmp"' EXIT; \
node --disable-warning=DEP0040 tools/dump_credentials.js \
--n8n-nodes-base "$(UPSTREAM_NODES_ROOT)/packages/nodes-base" > "$$tmp" && \
mv -f "$$tmp" tools/credential_dump.jsonl
# Extra CLI args for port_credentials.py (e.g. CREDENTIAL_PORT_ARGS=--limit 50 --dry-run).
CREDENTIAL_PORT_ARGS ?=
credential-port: setup-python
. .venv/bin/activate && PYTHONPATH=packages/python python tools/port_credentials.py tools/credential_dump.jsonl \
--out schemas/credential-kinds $(CREDENTIAL_PORT_ARGS)
tests-kb: setup-python
. .venv/bin/activate && pytest -v -m "kb_slow" packages/python/tests/
tests-scale: setup-python
. .venv/bin/activate && pytest packages/python/tests_scale
tests-all: tests tests-kb tests-scale
setup-ui:
cd tests-ui && npm install
tests-ui: setup-ui
cd tests-ui && npm run test:ui
tests-ui-debug: setup-ui
cd tests-ui && npm run test:ui:debug
tests-ts:
cd packages/typescript/sdk && npm install && npm run test:all
cd packages/typescript/mcp && npm install && npm run test
vitest:
cd packages/typescript/frontend && npm install && npm test
clean:
rm -rf .venv
# DockerHub targets
dockerhub-build-frontend:
@echo "Building frontend image: $(FRONTEND_IMAGE):$(IMAGE_TAG)"
@echo "Using NEXT_PUBLIC_FASTAPI_FRONTEND_URL=$(NEXT_PUBLIC_FASTAPI_FRONTEND_URL)"
@echo "Note: This value is baked into the Next.js build. Override with: make dockerhub-build-frontend NEXT_PUBLIC_FASTAPI_FRONTEND_URL=your-url"
docker build -t $(FRONTEND_IMAGE):$(IMAGE_TAG) \
--target frontend \
--build-arg NEXT_PUBLIC_FASTAPI_FRONTEND_URL=$(NEXT_PUBLIC_FASTAPI_FRONTEND_URL) \
--build-arg NODE_ENV=$(NODE_ENV) \
-f $(DOCKERFILE) .
dockerhub-build-backend:
@echo "Building backend image: $(BACKEND_IMAGE):$(IMAGE_TAG)"
docker build -t $(BACKEND_IMAGE):$(IMAGE_TAG) \
--target backend \
-f $(DOCKERFILE) .
dockerhub-build: dockerhub-build-frontend dockerhub-build-backend
@echo "✅ Both images built successfully"
dockerhub-push-frontend: dockerhub-build-frontend
@echo "Pushing frontend image: $(FRONTEND_IMAGE):$(IMAGE_TAG)"
docker push $(FRONTEND_IMAGE):$(IMAGE_TAG)
dockerhub-push-backend: dockerhub-build-backend
@echo "Pushing backend image: $(BACKEND_IMAGE):$(IMAGE_TAG)"
docker push $(BACKEND_IMAGE):$(IMAGE_TAG)
dockerhub-push: dockerhub-push-frontend dockerhub-push-backend
@echo "✅ Both images pushed successfully to DockerHub"
dockerhub-build-push: dockerhub-build dockerhub-push
@echo "✅ Build and push complete!"
.PHONY: help deploy-dev tests tests-kb setup setup-dev setup-python setup-typescript setup-kind setup-ui tests-ts vitest deploy deploy-compose deploy-compose-embedded deploy-kind down logs down-compose down-compose-clean down-kind destroy-kind dockerhub-build dockerhub-build-frontend dockerhub-build-backend dockerhub-push dockerhub-push-frontend dockerhub-push-backend dockerhub-build-push clean flow-node-dump flow-node-port credential-dump credential-port