-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile
More file actions
677 lines (596 loc) · 30.2 KB
/
Copy pathMakefile
File metadata and controls
677 lines (596 loc) · 30.2 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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
# Makefile for SchemaBot - Declarative Schema GitOps
# Build metadata injected via -ldflags
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)
# Test runner: use gotestsum if available for nicer output, otherwise fall back to go test
# Check PATH first, then GOBIN, then default ~/go/bin
GOBIN := $(shell go env GOBIN 2>/dev/null)
ifeq ($(GOBIN),)
GOBIN := $(HOME)/go/bin
endif
GOTESTSUM := $(shell command -v gotestsum 2>/dev/null || (test -x $(GOBIN)/gotestsum && echo $(GOBIN)/gotestsum))
ifdef GOTESTSUM
GOTEST := $(GOTESTSUM) --format pkgname-and-test-fails --
else
GOTEST := go test
endif
E2E_TEST_TIMEOUT ?= 10m
E2E_TEST_FLAGS ?=
E2E_GRPC_MD_RUN ?= TestGRPCMultiDeploy
.PHONY: help lint lint-fix setup test test-unit test-consumer-module test-e2e test-e2e-grpc test-e2e-grpc-multideploy test-e2e-k8s test-e2e-local-down test-e2e-mysql test-e2e-vitess test-integration test-localscale build-localscale-image test-coverage build install clean proto up up-telemetry up-grpc down down-grpc status mysql logs logs-grpc test-endpoints plan-testapp apply-testapp seed-testapp seed-testapp-large seed-vitess demo demo-vitess demo-grpc demo-grpc-logs wait-healthy wait-healthy-grpc wait-localscale cli
# Multi-line message definitions
define HELP_HEADER
SchemaBot - Declarative Schema GitOps
Available targets:
endef
export HELP_HEADER
define DEMO_COMMANDS
MySQL (Spirit) commands:
schemabot plan -s examples/mysql/schema/testapp Preview DDL
schemabot apply -s examples/mysql/schema/testapp -e staging Execute schema change
schemabot progress --database testapp Poll progress and ETA
Vitess (PlanetScale) commands:
schemabot plan -s examples/vitess/schema Preview DDL + VSchema
schemabot apply -s examples/vitess/schema -e staging Execute schema change
schemabot progress --database testapp-vitess Poll progress and ETA
General:
schemabot status Show active schema changes
schemabot help See all commands
Tail server logs:
make logs
============================================
endef
export DEMO_COMMANDS
define DEMO_READY_MSG
============================================
SCHEMABOT DEMO READY
SchemaBot API: http://localhost:13370
LocalScale API: http://localhost:13374
MySQL (Spirit):
Staging: localhost:13372 (testapp)
Production: localhost:13373 (testapp)
Data: 50 MB per table
Vitess (PlanetScale via LocalScale):
Database: testapp-vitess
Orgs: localscale-staging, localscale-production
Keyspaces: testapp (unsharded), testapp_sharded (sharded)
Data: 200 MB per table (sharded across keyspace shards)
$(DEMO_COMMANDS)
endef
export DEMO_READY_MSG
define DEMO_SKIP_APPLY_MSG
============================================
SCHEMABOT SERVER READY (SKIP_APPLY mode)
SchemaBot API: http://localhost:13370
Staging MySQL: localhost:13372 (testapp)
Production MySQL: localhost:13373 (testapp)
Schema applies skipped. To apply manually:
make apply-testapp ENV=staging
make apply-testapp ENV=production
$(DEMO_COMMANDS)
endef
export DEMO_SKIP_APPLY_MSG
define DEMO_GRPC_READY_MSG
============================================
SCHEMABOT gRPC DEMO READY
SchemaBot API: http://localhost:13380
Tern Staging (HTTP): http://localhost:13384
Tern Staging (gRPC): localhost:13385
Tern Prod (HTTP): http://localhost:13386
Tern Prod (gRPC): localhost:13387
Staging MySQL: localhost:13382 (testapp)
Production MySQL: localhost:13383 (testapp)
Data: 50 MB per table in each environment
============================================
endef
export DEMO_GRPC_READY_MSG
define DEMO_GRPC_SKIP_APPLY_MSG
============================================
SCHEMABOT gRPC SERVER READY (SKIP_APPLY mode)
SchemaBot API: http://localhost:13380
Tern Staging (HTTP): http://localhost:13384
Tern Staging (gRPC): localhost:13385
Tern Prod (HTTP): http://localhost:13386
Tern Prod (gRPC): localhost:13387
Staging MySQL: localhost:13382 (testapp)
Production MySQL: localhost:13383 (testapp)
============================================
endef
export DEMO_GRPC_SKIP_APPLY_MSG
help: ## Show this help message
@echo "$$HELP_HEADER"
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
lint: check-closeandlog check-webhookheaders ## Run all linters (golangci-lint + custom analyzers)
@echo "Running golangci-lint..."
@docker run --rm -v $$(pwd):/app -w /app golangci/golangci-lint:latest golangci-lint run --timeout=5m
@echo "Running golangci-lint (consumer module)..."
@docker run --rm -v $$(pwd):/app -w /app/e2e/consumermodule golangci/golangci-lint:latest golangci-lint run --timeout=5m
check-closeandlog: ## Run closeandlog analyzer (flags _ = x.Close() patterns)
@echo "Running closeandlog analyzer..."
@go run ./cmd/closeandlog-check ./...
@go run -tags=integration ./cmd/closeandlog-check ./...
check-webhookheaders: ## Run webhookheaders analyzer (flags inline `## ...` markdown headers in pkg/webhook handlers)
@echo "Running webhookheaders analyzer..."
@go run ./cmd/webhookheaders-check $$(go list ./pkg/webhook/... | grep -v '/templates$$')
lint-fix: ## Run golangci-lint with auto-fix enabled
@echo "Running golangci-lint with auto-fix..."
@docker run --rm -v $$(pwd):/app -w /app golangci/golangci-lint:latest golangci-lint run --fix --timeout=5m
setup: ## Set up git hooks for development
git config core.hooksPath .githooks
@echo "Setup complete. Git hooks enabled (.githooks/pre-commit, .githooks/pre-push)."
clean: ## Clean build artifacts
@echo "Cleaning..."
@rm -rf bin/
@rm -f coverage.out
docs-toc: ## Regenerate the Table of Contents in docs/*.md
@python3 scripts/gen-doc-toc.py
# Generate protobuf code (only if .proto is newer than generated .pb.go)
proto: ## Generate protobuf code
@if [ pkg/proto/tern.proto -nt pkg/proto/ternv1/tern.pb.go ]; then \
echo "Proto file changed, regenerating..."; \
buf generate; \
fi
# =============================================================================
# Local Development (not for production)
# =============================================================================
# These commands start a local dev environment with:
# - SchemaBot MySQL (port 13371, schemabot database)
# - Staging MySQL (port 13372, testapp database)
# - Production MySQL (port 13373, testapp database)
# - SchemaBot service (port 13370)
# For production deployment, see docs/guides/deployment.md
# Start local dev environment (embedded Tern, no gRPC required)
# make up # Start services (ports: 13370, 13371, 13372)
# make up FRESH=1 # Reinitialize databases (removes volumes first)
up:
ifeq ($(FRESH),1)
docker compose -f deploy/local/docker-compose.yml down -v 2>/dev/null || true
endif
docker compose -f deploy/local/docker-compose.yml up --build
# Start local dev with observability (Grafana + Prometheus + Loki + Tempo)
# make up-telemetry # Start with Grafana at http://localhost:3000
# make up-telemetry FRESH=1 # Reinitialize databases
up-telemetry:
ifeq ($(FRESH),1)
docker compose -f deploy/local/docker-compose.yml -f deploy/local/docker-compose.telemetry.yml down -v 2>/dev/null || true
endif
docker compose -f deploy/local/docker-compose.yml -f deploy/local/docker-compose.telemetry.yml up --build
# Start services, apply testapp schema, then show logs (full demo workflow)
# make demo # Start and apply MySQL + Vitess schema (wipes data)
# make demo KEEP_DATA=1 # Restart without wiping data (preserves seeded rows)
# make demo SKIP_APPLY=1 # Start server only, skip schema applies (for debugging)
demo:
@# Reset schema files to baseline so the demo starts clean.
@./scripts/generate-schema-change.sh reset 2>/dev/null || true
@./scripts/generate-schema-change.sh reset --vitess 2>/dev/null || true
ifeq ($(KEEP_DATA),1)
docker compose -f deploy/local/docker-compose.yml down --remove-orphans -t 10 2>/dev/null || true
else
docker compose -f deploy/local/docker-compose.yml down --remove-orphans -v -t 10 2>/dev/null || true
endif
@# Build everything in parallel: LocalScale image + Go binaries + start MySQL containers
@echo "Building binaries and starting containers in parallel..."
@docker compose -f deploy/local/docker-compose.yml up -d mysql-schemabot mysql-staging mysql-production & \
$(MAKE) build-localscale-image & \
CGO_ENABLED=0 GOOS=linux go build -ldflags "$(LDFLAGS)" -o bin/schemabot-linux ./pkg/cmd & \
go build -ldflags "$(LDFLAGS)" -o bin/schemabot ./pkg/cmd & \
wait
@$(MAKE) cli
cp bin/schemabot-linux deploy/local/schemabot-dev
docker compose -f deploy/local/docker-compose.yml up --build -d localscale schemabot
@rm -f deploy/local/schemabot-dev
@$(MAKE) wait-healthy
@$(MAKE) wait-localscale
ifneq ($(SKIP_APPLY),1)
@trap 'kill 0' INT TERM; \
echo "Applying MySQL schemas (staging → production)..."; \
./bin/schemabot apply -s examples/mysql/schema/testapp -e staging --endpoint http://localhost:13370 -y --allow-unsafe -o log && \
./bin/schemabot apply -s examples/mysql/schema/testapp -e production --endpoint http://localhost:13370 -y --allow-unsafe -o log && \
echo "MySQL schemas applied." && \
echo "" && \
echo "Applying Vitess schemas (staging → production)..." && \
./bin/schemabot apply -s examples/vitess/schema -e staging --endpoint http://localhost:13370 -y -o log --allow-unsafe --skip-revert && \
./bin/schemabot apply -s examples/vitess/schema -e production --endpoint http://localhost:13370 -y -o log --allow-unsafe --skip-revert && \
echo "Vitess schemas applied." && \
echo "Waiting for VSchema propagation..." && \
sleep 5 && \
echo "" && \
echo "Seeding data..." && \
./scripts/seed-large.sh 50 both && \
STAGING_VTGATE_PORT=19101 ./scripts/seed-vitess.sh 100 && \
echo "Seeding complete."
@echo "$$DEMO_READY_MSG"
else
@echo "$$DEMO_SKIP_APPLY_MSG"
endif
# Wait for SchemaBot to be healthy
wait-healthy:
@echo "Waiting for SchemaBot to be healthy..."
@for i in $$(seq 1 30); do \
if curl -sf http://localhost:13370/health > /dev/null 2>&1; then \
echo "SchemaBot is healthy"; \
exit 0; \
fi; \
sleep 1; \
done; \
echo "Timeout waiting for SchemaBot"; exit 1
# Plan example MySQL schema changes (dry-run)
# make plan-testapp # Plan for staging (default)
# make plan-testapp ENV=production
plan-testapp: build
./bin/schemabot plan -s examples/mysql/schema/testapp -e $(or $(ENV),staging) --endpoint http://localhost:13370
# Apply example MySQL schema
# make apply-testapp # Apply to staging (default)
# make apply-testapp ENV=production
apply-testapp: build
./bin/schemabot apply -s examples/mysql/schema/testapp -e $(or $(ENV),staging) --endpoint http://localhost:13370 -y --allow-unsafe -o log
# Seed testapp with large dataset for testing progress rendering
# make seed-testapp-large # 100 MB per table, staging only
# make seed-testapp-large TARGET_MB=500 # 500 MB per table
# make seed-testapp-large ENV=both # Both environments
seed-testapp-large:
@./scripts/seed-large.sh $(or $(TARGET_MB),100) $(or $(ENV),staging)
# Seed Vitess testapp_sharded with data for per-shard progress
# make seed-vitess # 200 MB per table, staging (default)
# make seed-vitess TARGET_MB=500 # 500 MB per table
# make seed-vitess ENV=production # Seed production
seed-vitess:
@./scripts/seed-vitess.sh $(or $(TARGET_MB),200) $(or $(ENV),staging)
# Seed testapp with sample data (10k rows each for users and orders)
# make seed-testapp # Seed both staging and production
# make seed-testapp ENV=staging # Seed staging only
seed-testapp:
@./scripts/seed.sh $(or $(ENV),both)
# Run all e2e tests (MySQL + Vitess + gRPC) in isolated docker-compose environments.
test-e2e: test-e2e-local test-e2e-grpc ## Run all e2e tests
# E2E local environment shorthand
E2E_DC = docker compose -f deploy/e2e/docker-compose.yml
# Run local e2e tests in an isolated environment (no conflicts with make demo)
# Keeps containers alive between runs for fast iteration. Use FRESH=1 to rebuild from scratch.
# Use `make test-e2e-local-down` to tear down manually.
# Ports: SchemaBot=14370, MySQL-SchemaBot=14371, MySQL-Staging=14372, MySQL-Production=14373, LocalScale=14374
test-e2e-local: build ## Run local e2e tests in isolated environment
ifeq ($(FRESH),1)
@$(E2E_DC) down -v 2>/dev/null || true
endif
@echo "Building binaries..."
@(CGO_ENABLED=0 GOOS=linux go build -ldflags "$(LDFLAGS)" -o bin/schemabot-linux ./pkg/cmd) & \
(CGO_ENABLED=0 GOOS=linux go build -ldflags "$(LDFLAGS)" -o bin/localscale-linux ./cmd/localscale) & \
wait
@cp bin/schemabot-linux deploy/local/schemabot-dev
@docker build -f deploy/local/Dockerfile.localscale -t localscale:latest . -q
@$(E2E_DC) up --build -d mysql-schemabot mysql-staging mysql-production localscale
@$(E2E_DC) up --build --force-recreate -d schemabot
@rm -f deploy/local/schemabot-dev
@echo "Waiting for e2e environment to be healthy..."
@for i in $$(seq 1 60); do \
if curl -sf http://localhost:14370/health > /dev/null 2>&1; then \
echo "SchemaBot e2e environment is healthy"; \
break; \
fi; \
if [ $$i -eq 60 ]; then \
echo "Timeout waiting for SchemaBot e2e environment"; \
$(E2E_DC) logs; \
exit 1; \
fi; \
sleep 1; \
done
@echo "Applying schemas (MySQL + Vitess in parallel)..."
@( ./bin/schemabot apply -s examples/mysql/schema/testapp -e staging --endpoint http://localhost:14370 -y --allow-unsafe -o log && \
./bin/schemabot apply -s examples/mysql/schema/testapp -e production --endpoint http://localhost:14370 -y --allow-unsafe -o log ) & \
MYSQL_PID=$$!; \
for ks in testapp testapp_sharded; do \
if [ -f examples/vitess/schema/$$ks/vschema.json ]; then \
curl -sf -X POST "http://localhost:14374/admin/seed-vschema" \
-H "Content-Type: application/json" \
-d "{\"org\":\"localscale-staging\",\"database\":\"testapp-vitess\",\"keyspace\":\"$$ks\",\"vschema\":$$(cat examples/vitess/schema/$$ks/vschema.json)}"; \
curl -sf -X POST "http://localhost:14374/admin/seed-vschema" \
-H "Content-Type: application/json" \
-d "{\"org\":\"localscale-production\",\"database\":\"testapp-vitess\",\"keyspace\":\"$$ks\",\"vschema\":$$(cat examples/vitess/schema/$$ks/vschema.json)}"; \
fi; \
done; \
./bin/schemabot apply -s examples/vitess/schema -e staging --endpoint http://localhost:14370 -y --allow-unsafe -o log || \
(echo "=== LocalScale logs ===" && $(E2E_DC) logs localscale --tail=200 && false); \
./bin/schemabot apply -s examples/vitess/schema -e production --endpoint http://localhost:14370 -y --allow-unsafe -o log || \
(echo "=== LocalScale logs ===" && $(E2E_DC) logs localscale --tail=200 && false); \
wait $$MYSQL_PID
@echo "Running e2e tests..."
@E2E_SCHEMABOT_URL=http://localhost:14370 \
LOCALSCALE_URL=http://localhost:14374 \
E2E_MYSQL_DSN="root:testpassword@tcp(localhost:14371)/schemabot" \
E2E_TESTAPP_STAGING_DSN="root:testpassword@tcp(localhost:14372)/testapp" \
E2E_TESTAPP_PRODUCTION_DSN="root:testpassword@tcp(localhost:14373)/testapp" \
$(GOTEST) -count=1 -timeout=$(E2E_TEST_TIMEOUT) -tags=e2e $(E2E_TEST_FLAGS) $(if $(RUN),-run '$(RUN)') ./e2e/local/...
# Run only MySQL e2e tests (Spirit engine, no LocalScale/vtcombo needed)
test-e2e-mysql: ## Run MySQL-only e2e tests
$(MAKE) test-e2e-local RUN=TestLocal
# Run only Vitess e2e tests (PlanetScale engine, requires LocalScale/vtcombo)
test-e2e-vitess: ## Run Vitess-only e2e tests
$(MAKE) test-e2e-local RUN=TestVitess
# Tear down e2e local environment
test-e2e-local-down: ## Tear down e2e local environment
@$(E2E_DC) down -v
# Run gRPC e2e tests in an isolated environment
# This spins up SchemaBot + separate Tern services (gRPC mode), runs tests, then tears down.
# Ports: SchemaBot=15370, SchemaBot-MySQL=15371, Tern-Staging-MySQL=15372, Tern-Production-MySQL=15373
# Tern-Staging-HTTP=15380, Tern-Staging-gRPC=15390, Tern-Production-HTTP=15382, Tern-Production-gRPC=15392
E2E_GRPC_ENV := SCHEMABOT_PORT=15370 \
SCHEMABOT_MYSQL_PORT=15371 \
SCHEMABOT_METRICS_PORT=15376 \
TERN_STAGING_MYSQL_PORT=15372 \
TERN_PRODUCTION_MYSQL_PORT=15373 \
TERN_STAGING_PORT=15380 \
TERN_STAGING_GRPC_PORT=15390 \
TERN_PRODUCTION_PORT=15382 \
TERN_PRODUCTION_GRPC_PORT=15392
test-e2e-grpc: build ## Run gRPC e2e tests in isolated environment
@echo "Starting isolated gRPC e2e environment..."
CGO_ENABLED=0 GOOS=linux go build -ldflags "$(LDFLAGS)" -o bin/schemabot-linux ./pkg/cmd
cp bin/schemabot-linux deploy/local/schemabot-dev
@$(E2E_GRPC_ENV) docker compose -p schemabot-e2e-grpc -f deploy/local/docker-compose.grpc.yml down -v 2>/dev/null || true
@$(E2E_GRPC_ENV) docker compose -p schemabot-e2e-grpc -f deploy/local/docker-compose.grpc.yml up --build -d
@rm -f deploy/local/schemabot-dev
@echo "Waiting for SchemaBot gRPC e2e environment to be healthy..."
@for i in $$(seq 1 90); do \
if curl -sf http://localhost:15370/health > /dev/null 2>&1; then \
echo "SchemaBot gRPC e2e environment is healthy"; \
break; \
fi; \
if [ $$i -eq 90 ]; then \
echo "Timeout waiting for SchemaBot gRPC e2e environment"; \
mkdir -p e2e-logs; \
$(E2E_GRPC_ENV) docker compose -p schemabot-e2e-grpc -f deploy/local/docker-compose.grpc.yml logs --no-color --timestamps 2>&1 | tee e2e-logs/grpc-containers.log; \
$(E2E_GRPC_ENV) docker compose -p schemabot-e2e-grpc -f deploy/local/docker-compose.grpc.yml down -v; \
exit 1; \
fi; \
sleep 1; \
done
@echo "Running gRPC e2e tests..."
@E2E_SCHEMABOT_URL=http://localhost:15370 \
E2E_SCHEMABOT_METRICS_URL=http://localhost:15376 \
E2E_SCHEMABOT_MYSQL_DSN="root:testpassword@tcp(localhost:15371)/schemabot" \
E2E_TERN_STAGING_MYSQL_DSN="root:testpassword@tcp(localhost:15372)/testapp" \
E2E_TERN_PRODUCTION_MYSQL_DSN="root:testpassword@tcp(localhost:15373)/testapp" \
$(GOTEST) -count=1 -v -tags=e2e -timeout=10m ./e2e/grpc/... ; \
TEST_EXIT_CODE=$$?; \
if [ $$TEST_EXIT_CODE -ne 0 ]; then \
echo "Capturing gRPC e2e container logs before teardown..."; \
mkdir -p e2e-logs; \
$(E2E_GRPC_ENV) docker compose -p schemabot-e2e-grpc -f deploy/local/docker-compose.grpc.yml logs --no-color --timestamps > e2e-logs/grpc-containers.log 2>&1 || true; \
fi; \
echo "Tearing down gRPC e2e environment..."; \
$(E2E_GRPC_ENV) docker compose -p schemabot-e2e-grpc -f deploy/local/docker-compose.grpc.yml down -v; \
exit $$TEST_EXIT_CODE
# Run the multi-deployment fan-out gRPC e2e fixture.
# One environment (testapp/production) fans out to two deployments (eu, us),
# each backed by its own remote Tern + MySQL.
# NOT part of `make test-e2e`: the stack cannot boot until the server supports
# deployments maps with more than one entry. Run manually once that lands.
# Ports: SchemaBot=15370, SchemaBot-MySQL=15371, EU-MySQL=15372, US-MySQL=15373
# EU-HTTP=15380, EU-gRPC=15390, US-HTTP=15382, US-gRPC=15392
E2E_GRPC_MD_ENV := SCHEMABOT_PORT=15370 \
SCHEMABOT_MYSQL_PORT=15371 \
SCHEMABOT_METRICS_PORT=15376 \
TERN_EU_MYSQL_PORT=15372 \
TERN_US_MYSQL_PORT=15373 \
TERN_EU_PORT=15380 \
TERN_EU_GRPC_PORT=15390 \
TERN_US_PORT=15382 \
TERN_US_GRPC_PORT=15392
test-e2e-grpc-multideploy: build ## Run multi-deployment fan-out gRPC e2e fixture (needs server support for >1-entry deployments maps)
@echo "Starting isolated multi-deployment gRPC e2e environment..."
CGO_ENABLED=0 GOOS=linux go build -ldflags "$(LDFLAGS)" -o bin/schemabot-linux ./pkg/cmd
cp bin/schemabot-linux deploy/local/schemabot-dev
@$(E2E_GRPC_MD_ENV) docker compose -p schemabot-e2e-grpc-md -f deploy/local/docker-compose.grpc-multideploy.yml down -v 2>/dev/null || true
@$(E2E_GRPC_MD_ENV) docker compose -p schemabot-e2e-grpc-md -f deploy/local/docker-compose.grpc-multideploy.yml up --build -d
@rm -f deploy/local/schemabot-dev
@echo "Waiting for multi-deployment SchemaBot gRPC e2e environment to be healthy..."
@for i in $$(seq 1 90); do \
if curl -sf http://localhost:15370/health > /dev/null 2>&1; then \
echo "Multi-deployment SchemaBot gRPC e2e environment is healthy"; \
break; \
fi; \
if [ $$i -eq 90 ]; then \
echo "Timeout waiting for multi-deployment SchemaBot gRPC e2e environment"; \
echo "(expected until the server supports deployments maps with more than one entry)"; \
mkdir -p e2e-logs; \
$(E2E_GRPC_MD_ENV) docker compose -p schemabot-e2e-grpc-md -f deploy/local/docker-compose.grpc-multideploy.yml logs --no-color --timestamps 2>&1 | tee e2e-logs/grpc-multideploy-containers.log; \
$(E2E_GRPC_MD_ENV) docker compose -p schemabot-e2e-grpc-md -f deploy/local/docker-compose.grpc-multideploy.yml down -v; \
exit 1; \
fi; \
sleep 1; \
done
@echo "Running multi-deployment gRPC e2e tests..."
@E2E_MULTIDEPLOY=1 \
E2E_SCHEMABOT_URL=http://localhost:15370 \
E2E_SCHEMABOT_METRICS_URL=http://localhost:15376 \
E2E_SCHEMABOT_MYSQL_DSN="root:testpassword@tcp(localhost:15371)/schemabot" \
E2E_TERN_EU_MYSQL_DSN="root:testpassword@tcp(localhost:15372)/testapp" \
E2E_TERN_US_MYSQL_DSN="root:testpassword@tcp(localhost:15373)/testapp" \
$(GOTEST) -count=1 -v -tags=e2e -timeout=10m -run '$(E2E_GRPC_MD_RUN)' ./e2e/grpc/... ; \
TEST_EXIT_CODE=$$?; \
if [ $$TEST_EXIT_CODE -ne 0 ]; then \
echo "Capturing multi-deployment gRPC e2e container logs before teardown..."; \
mkdir -p e2e-logs; \
$(E2E_GRPC_MD_ENV) docker compose -p schemabot-e2e-grpc-md -f deploy/local/docker-compose.grpc-multideploy.yml logs --no-color --timestamps > e2e-logs/grpc-multideploy-containers.log 2>&1 || true; \
fi; \
echo "Tearing down multi-deployment gRPC e2e environment..."; \
$(E2E_GRPC_MD_ENV) docker compose -p schemabot-e2e-grpc-md -f deploy/local/docker-compose.grpc-multideploy.yml down -v; \
exit $$TEST_EXIT_CODE
# Run k8s e2e tests on minikube. Starts minikube if needed.
# Tests the two-tier gRPC architecture (control plane → data plane) deployed via Helm chart.
test-e2e-k8s: ## Run k8s e2e tests on minikube
@e2e/k8s/e2e-test.sh
# Run the etre-resolver k8s e2e on minikube: the data plane resolves a target
# (DSID) through Etre and assembles credentials via assume-role + Secrets
# Manager, both emulated by ministack in-cluster.
test-e2e-k8s-etre: ## Run the etre-resolver k8s e2e on minikube
@e2e/k8s/e2e-etre-test.sh
test-e2e-k8s-vitess: ## Run the vitess-resolver k8s e2e on minikube
@e2e/k8s/e2e-vitess-test.sh
# Start local dev environment with gRPC backend (separate Tern server)
up-grpc:
docker compose -f deploy/local/docker-compose.grpc.yml up --build
# Full gRPC demo: start services, apply schema, seed data
# make demo-grpc # Start and apply testapp schema (wipes data)
# make demo-grpc KEEP_DATA=1 # Restart without wiping data
# make demo-grpc SKIP_APPLY=1 # Start server only, skip schema applies
# make demo-grpc-logs # Same as demo-grpc, then tail logs
demo-grpc:
ifeq ($(KEEP_DATA),1)
docker compose -f deploy/local/docker-compose.grpc.yml down -t 10 2>/dev/null || true
else
docker compose -f deploy/local/docker-compose.grpc.yml down -v -t 10 2>/dev/null || true
endif
@# Start MySQL containers first, then build Go in parallel
docker compose -f deploy/local/docker-compose.grpc.yml up -d tern-staging-mysql tern-production-mysql schemabot-mysql
CGO_ENABLED=0 GOOS=linux go build -ldflags "$(LDFLAGS)" -o bin/schemabot-linux ./pkg/cmd & \
go build -ldflags "$(LDFLAGS)" -o bin/schemabot ./pkg/cmd & \
wait
@$(MAKE) cli
cp bin/schemabot-linux deploy/local/schemabot-dev
docker compose -f deploy/local/docker-compose.grpc.yml up --build -d
@rm -f deploy/local/schemabot-dev
@$(MAKE) wait-healthy-grpc
ifneq ($(SKIP_APPLY),1)
@./bin/schemabot apply -s examples/mysql/schema/testapp -e staging --endpoint http://localhost:13380 -y --allow-unsafe -o log
@./bin/schemabot apply -s examples/mysql/schema/testapp -e production --endpoint http://localhost:13380 -y --allow-unsafe -o log
@./scripts/seed-grpc.sh 50 both
@echo "$$DEMO_GRPC_READY_MSG"
else
@echo "$$DEMO_GRPC_SKIP_APPLY_MSG"
endif
# Full gRPC demo + tail logs
demo-grpc-logs: demo-grpc
-docker compose -f deploy/local/docker-compose.grpc.yml logs -f
# Wait for gRPC SchemaBot to be healthy
wait-healthy-grpc:
@echo "Waiting for gRPC SchemaBot to be healthy..."
@for i in $$(seq 1 60); do \
if curl -sf http://localhost:13380/health > /dev/null 2>&1; then \
echo "gRPC SchemaBot is healthy"; \
exit 0; \
fi; \
sleep 1; \
done; \
echo "Timeout waiting for gRPC SchemaBot"; exit 1
# Show endpoint URLs (useful with PORTS=dynamic)
status:
@echo "SchemaBot: http://localhost:$$(docker compose -f deploy/local/docker-compose.yml port schemabot 8080 2>/dev/null | cut -d: -f2)"
@echo "MySQL: localhost:$$(docker compose -f deploy/local/docker-compose.yml port mysql 3306 2>/dev/null | cut -d: -f2)"
# Connect to MySQL
# make mysql # Connect to schemabot storage (port 13371)
# make mysql DB=staging # Connect to staging testapp (port 13372)
# make mysql DB=production # Connect to production testapp (port 13373)
DB ?= schemabot
PORT ?= $(if $(filter staging,$(DB)),13372,$(if $(filter production,$(DB)),13373,13371))
DBNAME ?= $(if $(filter staging production,$(DB)),testapp,$(DB))
mysql:
mysql -h 127.0.0.1 -P $(PORT) -u root -ptestpassword $(DBNAME)
# Stop local services
down:
docker compose -f deploy/local/docker-compose.yml down
# Stop gRPC services
down-grpc:
docker compose -f deploy/local/docker-compose.grpc.yml down
# View local logs (prettified with colors)
logs:
./scripts/dev-logs.sh
# View local logs (raw)
logs-raw:
docker compose -f deploy/local/docker-compose.yml logs -f
# View gRPC logs (prettified with colors)
logs-grpc:
./scripts/dev-logs.sh --grpc
# Build binaries
build: ## Build the schemabot binary
go build -ldflags "$(LDFLAGS)" -o bin/schemabot ./pkg/cmd
# Install CLI to GOBIN
install: ## Install schemabot CLI to GOBIN
go build -ldflags "$(LDFLAGS)" -o $(GOBIN)/schemabot ./pkg/cmd
# Install CLI to /usr/local/bin (available on PATH)
cli: build ## Install schemabot CLI to /usr/local/bin
cp bin/schemabot /usr/local/bin/schemabot
# Run all tests (unit with race detection + integration + e2e)
test: proto test-unit test-consumer-module test-integration test-e2e ## Run all tests
# Run unit tests only (with race detection, no testcontainers)
test-unit: ## Run unit tests with race detection
$(GOTEST) -race ./...
# Verify schemabot's startup surface from a consumer module that pins a newer
# OpenTelemetry SDK than this repo. Host binaries embedding schemabot resolve
# their own dependency versions, so this catches conflicts (such as semconv
# schema URL mismatches) that cannot reproduce inside this module.
test-consumer-module: ## Run consumer-module startup tests
cd e2e/consumermodule && $(GOTEST) -race ./...
# Run integration tests (uses testcontainers for MySQL)
# Note: -race is omitted because Spirit (upstream) has known data races in
# Runner.initChunkers/Progress. Our unit tests cover race detection for our code.
test-integration: ## Run integration tests
# -p=2 caps package-level parallelism: the integration suite runs many heavy
# MySQL/Spirit package binaries that otherwise thrash CPU and the shared
# MySQL, starving operator claim loops and causing spurious pending-apply
# timeouts.
$(GOTEST) -tags=integration -timeout=10m -p=2 ./...
# Run tests with coverage (unit + integration, merged per-package breakdown)
# make test-coverage # Unit + integration (requires Docker for testcontainers)
# make test-coverage MODE=unit # Unit tests only (no Docker needed)
# make test-coverage MODE=all # Unit + integration + e2e local (requires Docker Compose)
test-coverage: ## Run tests with coverage report
ifeq ($(MODE),unit)
@./scripts/coverage.sh --unit-only
else ifeq ($(MODE),all)
@./scripts/coverage.sh --all
else
@./scripts/coverage.sh
endif
fmt-schema: ## Format embedded schema files via spirit fmt (auto-detects or starts MySQL)
@scripts/run-spirit-fmt.sh
fmt-schema-check: ## Check if embedded schema files are canonically formatted (for CI)
@scripts/run-spirit-fmt.sh --check
.DEFAULT_GOAL := help
# Test API endpoints
test-endpoints:
@./scripts/test-endpoints.sh
# Build LocalScale Docker image (required for demo-vitess and LocalScale tests)
# Uses pre-built vttestserver image from GHCR (vtcombo + mysqlctl + MySQL 8.4),
# only needs to build the localscale binary and layer it on top.
build-localscale-image: ## Build LocalScale Docker image
CGO_ENABLED=0 GOOS=linux go build -ldflags "$(LDFLAGS)" -o bin/localscale-linux ./cmd/localscale
docker build -f deploy/local/Dockerfile.localscale -t localscale:latest .
# Run LocalScale integration tests
test-localscale: build-localscale-image ## Run LocalScale integration tests
$(GOTEST) -tags=integration -timeout=10m ./pkg/localscale/...
# Start LocalScale for testing the PlanetScale engine via CLI
# make demo-vitess # Start LocalScale + SchemaBot
# make demo-vitess KEEP_DATA=1 # Restart without wiping data
demo-vitess: build build-localscale-image ## Start LocalScale demo environment
ifeq ($(KEEP_DATA),1)
docker compose -f deploy/local/docker-compose.yml down -t 10 2>/dev/null || true
else
docker compose -f deploy/local/docker-compose.yml down -v -t 10 2>/dev/null || true
endif
docker compose -f deploy/local/docker-compose.yml up --build -d localscale
@$(MAKE) wait-localscale
@echo ""
@echo "============================================"
@echo " VITESS DEMO READY"
@echo " LocalScale API: http://localhost:13374"
@echo " Branch proxy ports: 19100-19199"
@echo ""
@echo " Test with CLI:"
@echo " bin/schemabot plan -s examples/vitess/schema -e staging --endpoint http://localhost:13370"
@echo " bin/schemabot apply -s examples/vitess/schema -e staging --endpoint http://localhost:13370 -y"
@echo "============================================"
# Wait for LocalScale to be healthy (vtcombo startup takes ~30-60s)
wait-localscale:
@echo "Waiting for LocalScale to be healthy..."
@for i in $$(seq 1 90); do \
if curl -sf http://localhost:13374/health > /dev/null 2>&1; then \
echo "LocalScale is healthy"; \
exit 0; \
fi; \
sleep 1; \
done; \
echo "Timeout waiting for LocalScale"; exit 1