Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
534 lines (461 loc) · 18.4 KB
/
Copy pathMakefile
File metadata and controls
534 lines (461 loc) · 18.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
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
.PHONY: help init check-env check-versions proto gen-proto gen-proto-go gen-proto-java gen-proto-ts verify-proto \
build test lint lint-fix format docker-build build-image run clean list-apps create \
test-coverage verify-coverage test-services \
dev pre-commit verify-auto-detection \
deps deps-update deps-clean deps-verify deps-audit deps-status \
deps-go deps-java deps-node deps-proto \
deps-update-go deps-update-java deps-update-node \
infra-up infra-down services-up services-down dev-up dev-down dev-restart infra-logs infra-clean infra-status \
im-up im-down \
observability-up observability-down observability-restart observability-logs observability-status observability-clean \
k8s-deploy-dev k8s-deploy-prod k8s-infra-deploy k8s-validate
# Default target
help:
@echo "Monorepo Build System"
@echo ""
@echo "Available targets:"
@echo " init - Initialize development environment and install dependencies"
@echo " check-env - Check if all required tools are installed"
@echo " check-versions - Verify tool versions match requirements"
@echo " verify-auto-detection - Verify app type auto-detection works correctly"
@echo " proto - Generate code from Protobuf definitions (all languages)"
@echo " verify-proto - Verify generated code is up to date (for CI)"
@echo ""
@echo " Unified Dependency Management:"
@echo " deps - Install all dependencies (Go, Java, Node.js)"
@echo " deps-update - Update all dependencies"
@echo " deps-clean - Clean all dependencies"
@echo " deps-verify - Verify dependency integrity"
@echo " deps-audit - Security audit for all dependencies"
@echo " deps-status - Show dependency status"
@echo " deps-go - Install Go dependencies only"
@echo " deps-java - Install Java dependencies only"
@echo " deps-node - Install Node.js dependencies only"
@echo ""
@echo " Quality & Testing:"
@echo " pre-commit - Run all pre-commit quality checks (lint, test, security)"
@echo " test-services [SUITE=name] - Test running services (all, hello-todo, shortener, im, infra)"
@echo " lint [APP=name] - Run linters for app(s)"
@echo " lint-fix [APP=name] - Auto-fix lint errors for app(s)"
@echo " format [APP=name] - Format code for app(s)"
@echo " test [APP=name] - Run tests for app(s)"
@echo " test-coverage [APP=name] - Run tests with coverage for app(s)"
@echo " verify-coverage [APP=name] - Verify coverage thresholds for app(s)"
@echo ""
@echo " Docker Compose Deployment (Local Development):"
@echo " dev-up - Start all services (infrastructure + applications)"
@echo " dev-down - Stop all services"
@echo " im-up - Start IM Chat System (infrastructure + IM services)"
@echo " im-down - Stop IM Chat System"
@echo " infra-up - Start infrastructure only (MySQL, Redis, etcd, Kafka)"
@echo " infra-down - Stop infrastructure"
@echo " services-up - Start application services only"
@echo " services-down - Stop application services"
@echo " dev-restart - Restart application services (keep infrastructure running)"
@echo ""
@echo " Observability Stack:"
@echo " observability-up - Start observability stack (OTel, Jaeger, Prometheus, Grafana, Loki)"
@echo " observability-down - Stop observability stack"
@echo " observability-restart - Restart observability stack"
@echo " observability-logs - View observability logs"
@echo " observability-status - Check observability status"
@echo " observability-clean - Clean observability data (WARNING: Deletes all data!)"
@echo ""
@echo " Kubernetes Deployment (Production):"
@echo " k8s-deploy-dev - Deploy to Kubernetes development environment"
@echo " k8s-deploy-prod - Deploy to Kubernetes production environment"
@echo " k8s-infra-deploy - Deploy infrastructure using Helm charts"
@echo " k8s-validate - Validate Kubernetes manifests"
@echo ""
@echo " Infrastructure Management:"
@echo " infra-logs - View infrastructure logs"
@echo " infra-clean - Clean infrastructure data (WARNING: Deletes all data!)"
@echo " infra-status - Check infrastructure service status"
@echo ""
@echo " App Management (supports APP=<name> or auto-detects changed apps):"
@echo " list-apps - List all available apps"
@echo " create - Create a new app from template"
@echo " build [APP=name] - Build app(s)"
@echo " build-image [APP=name] - Build Docker image(s) with proto validation"
@echo " docker-build [APP=name] - Build Docker image(s) (legacy, use build-image)"
@echo " run [APP=name] - Run app(s) locally"
@echo " clean [APP=name] - Clean build artifacts for app(s)"
@echo ""
@echo " dev - Start all services in development mode (legacy)"
@echo ""
@echo "Examples:"
@echo " make dev-up # Start everything for local development"
@echo " make infra-up # Start only infrastructure"
@echo " make services-up # Start only application services"
@echo " make dev-restart # Restart services without restarting infrastructure"
@echo " make test-services # Test all running services"
@echo " make test-services SUITE=im # Test IM Chat System only"
@echo " make test-services SUITE=infra # Test infrastructure only"
@echo " make k8s-deploy-dev # Deploy to Kubernetes dev environment"
@echo " make k8s-deploy-prod # Deploy to Kubernetes production"
@echo " make k8s-infra-deploy # Deploy infrastructure with Helm"
@echo " make pre-commit # Run all quality checks before commit"
@echo " make proto # Generate code from Protobuf"
@echo " make test APP=hello # Test specific app (short name)"
@echo " make test-coverage APP=shortener # Run coverage for specific app"
@echo " make test-coverage # Run coverage for all apps"
@echo " make lint-fix # Fix linting issues in all changed apps"
@echo " make build APP=todo # Build specific app (short name)"
@echo " make build-image APP=hello # Build Docker image with proto validation"
@echo " make build-image # Build Docker images for all changed apps"
# Initialization
init:
@echo "Initializing development environment..."
@./scripts/init.sh
# ===== Unified Dependency Management =====
# Install all dependencies
deps:
@echo "📦 Installing all dependencies..."
@./scripts/deps-manager.sh install all
# Update all dependencies
deps-update:
@echo "🔄 Updating all dependencies..."
@./scripts/deps-manager.sh update all
# Clean all dependencies
deps-clean:
@echo "🧹 Cleaning all dependencies..."
@./scripts/deps-manager.sh clean all
# Verify dependency integrity
deps-verify:
@echo "✅ Verifying all dependencies..."
@./scripts/deps-manager.sh verify all
# Security audit
deps-audit:
@echo "🔒 Auditing dependencies for security issues..."
@./scripts/deps-manager.sh audit all
# Dependency status
deps-status:
@echo "📊 Dependency status..."
@./scripts/deps-manager.sh status all
# Language-specific dependency management
deps-go:
@./scripts/deps-manager.sh install go
deps-java:
@./scripts/deps-manager.sh install java
deps-node:
@./scripts/deps-manager.sh install node
deps-proto:
@./scripts/deps-manager.sh install proto
deps-update-go:
@./scripts/deps-manager.sh update go
deps-update-java:
@./scripts/deps-manager.sh update java
deps-update-node:
@./scripts/deps-manager.sh update node
# ===== End Unified Dependency Management =====
# Environment check
check-env:
@./scripts/check-env.sh
# Verify auto-detection functionality
verify-auto-detection:
@./scripts/verify-auto-detection.sh
# Version check
check-versions:
@./scripts/check-versions.sh
# Protobuf code generation
proto: gen-proto-go gen-proto-java gen-proto-typescript
@echo "✅ Protobuf code generation completed for all languages"
# Legacy alias for backward compatibility
gen-proto: proto
@echo "Note: 'gen-proto' is deprecated. Use 'make proto' instead."
# Convenience aliases for CI (without gen- prefix)
proto-go: gen-proto-go
proto-java: gen-proto-java
proto-typescript: gen-proto-typescript
proto-ts: gen-proto-typescript
gen-proto-go:
@./scripts/proto-generator-new.sh go
gen-proto-java:
@./scripts/proto-generator-new.sh java
gen-proto-typescript:
@./scripts/proto-generator-new.sh typescript
# Legacy alias
gen-proto-ts: gen-proto-typescript
# CI verification
verify-proto:
@echo "Verifying generated code is up to date..."
@$(MAKE) proto
@git diff --exit-code api/gen || \
(echo "Generated code is out of date. Run 'make proto' and commit changes." && exit 1)
# App management targets (new unified interface)
list-apps:
@./scripts/app-manager.sh list
create:
@echo "Create a new app from template"
@echo ""
@read -p "App type (java/go/node): " app_type; \
read -p "App name (e.g., user-service): " app_name; \
read -p "Port (default: auto-assign): " port; \
read -p "Description: " description; \
if [ "$$app_type" = "java" ]; then \
read -p "Java package (default: com.pingxin403.cuckoo.$$app_name): " package; \
fi; \
if [ "$$app_type" = "go" ]; then \
read -p "Go module (default: github.com/pingxin403/cuckoo/apps/$$app_name): " module; \
fi; \
read -p "Team name (default: platform-team): " team; \
cmd="./scripts/create-app.sh $$app_type $$app_name"; \
[ -n "$$port" ] && cmd="$$cmd --port $$port"; \
[ -n "$$description" ] && cmd="$$cmd --description \"$$description\""; \
[ -n "$$package" ] && cmd="$$cmd --package $$package"; \
[ -n "$$module" ] && cmd="$$cmd --module $$module"; \
[ -n "$$team" ] && cmd="$$cmd --team $$team"; \
eval $$cmd
build:
ifdef APP
@./scripts/app-manager.sh build $(APP)
else
@./scripts/app-manager.sh build
endif
test:
ifdef APP
@./scripts/app-manager.sh test $(APP)
else
@./scripts/app-manager.sh test
endif
lint:
ifdef APP
@./scripts/app-manager.sh lint $(APP)
else
@./scripts/app-manager.sh lint
endif
lint-fix:
ifdef APP
@./scripts/app-manager.sh lint-fix $(APP)
else
@./scripts/app-manager.sh lint-fix
endif
format:
ifdef APP
@./scripts/app-manager.sh format $(APP)
else
@./scripts/app-manager.sh format
endif
docker-build:
ifdef APP
@./scripts/app-manager.sh docker $(APP)
else
@./scripts/app-manager.sh docker
endif
# New unified Docker image builder with proto validation
build-image:
ifdef APP
@./scripts/build-image.sh $(APP) $(if $(TAG),--tag $(TAG)) $(if $(NO_CACHE),--no-cache) $(if $(PUSH),--push)
else
@./scripts/build-image.sh $(if $(TAG),--tag $(TAG)) $(if $(NO_CACHE),--no-cache) $(if $(PUSH),--push)
endif
run:
ifdef APP
@./scripts/app-manager.sh run $(APP)
else
@echo "Error: APP parameter required for run command"
@echo "Usage: make run APP=<app-name>"
@echo "Available apps:"
@./scripts/app-manager.sh list
@exit 1
endif
clean:
ifdef APP
@./scripts/app-manager.sh clean $(APP)
else
@./scripts/app-manager.sh clean
endif
# Test coverage targets (unified interface)
test-coverage:
ifdef APP
@./scripts/coverage-manager.sh $(APP)
else
@./scripts/coverage-manager.sh
endif
# Verify coverage thresholds (for CI)
verify-coverage:
ifdef APP
@./scripts/coverage-manager.sh $(APP) --verify
else
@./scripts/coverage-manager.sh --verify
endif
# Test running services (end-to-end tests)
test-services:
ifdef SUITE
@./scripts/test-services.sh $(SUITE)
else
@./scripts/test-services.sh all
endif
# ===== Docker Compose Deployment =====
.PHONY: infra-up infra-down services-up services-down dev-up dev-down dev-restart infra-logs infra-clean infra-status
# Start infrastructure only
infra-up:
@echo "Starting infrastructure services..."
@docker compose -f deploy/docker/docker-compose.infra.yml up -d
@echo "✅ Infrastructure started"
@echo ""
@echo "Endpoints:"
@echo " - etcd: localhost:2379"
@echo " - MySQL: localhost:3306 (databases: shortener, im_chat)"
@echo " - Redis: localhost:6379"
@echo " - Kafka: localhost:9092, localhost:9093"
@echo ""
@echo "Run 'make infra-status' to check service health"
# Stop infrastructure
infra-down:
@echo "Stopping infrastructure services..."
@docker compose -f deploy/docker/docker-compose.infra.yml down
@echo "✅ Infrastructure stopped"
# Start application services only
services-up:
@echo "Starting application services..."
@docker compose -f deploy/docker/docker-compose.services.yml up -d
@echo "✅ Services started"
# Stop application services
services-down:
@echo "Stopping application services..."
@docker compose -f deploy/docker/docker-compose.services.yml down
@echo "✅ Services stopped"
# Start everything (infrastructure + services)
dev-up:
@echo "Starting all services in development mode..."
@docker compose -f deploy/docker/docker-compose.infra.yml \
-f deploy/docker/docker-compose.services.yml up -d
@echo "✅ All services started"
@echo ""
@echo "Infrastructure endpoints:"
@echo " - etcd: localhost:2379"
@echo " - MySQL: localhost:3306"
@echo " - Redis: localhost:6379"
@echo " - Kafka: localhost:9092, localhost:9093"
@echo ""
@echo "Run 'make infra-status' to check service health"
# Stop everything
dev-down:
@echo "Stopping all services..."
@docker compose -f deploy/docker/docker-compose.infra.yml \
-f deploy/docker/docker-compose.services.yml down
@echo "✅ All services stopped"
# Start IM Chat System (simplified)
im-up:
@echo "Starting IM Chat System..."
@./scripts/start-im-system.sh
# Stop IM Chat System
im-down:
@echo "Stopping IM Chat System..."
@docker compose -f deploy/docker/docker-compose.infra.yml \
-f deploy/docker/docker-compose.services.yml down
@echo "✅ IM Chat System stopped"
# ===== Observability Stack =====
.PHONY: observability-up observability-down observability-restart observability-logs observability-status
# Start observability stack
observability-up:
@echo "Starting observability stack..."
@docker compose -f deploy/docker/docker-compose.observability.yml up -d
@echo "✅ Observability stack started"
@echo ""
@echo "Access UIs:"
@echo " - Grafana: http://localhost:3000 (admin/admin)"
@echo " - Jaeger: http://localhost:16686"
@echo " - Prometheus: http://localhost:9090"
@echo " - Loki: http://localhost:3100"
@echo ""
@echo "OTLP Endpoints:"
@echo " - gRPC: localhost:4317"
@echo " - HTTP: localhost:4318"
# Stop observability stack
observability-down:
@echo "Stopping observability stack..."
@docker compose -f deploy/docker/docker-compose.observability.yml down
@echo "✅ Observability stack stopped"
# Restart observability stack
observability-restart:
@echo "Restarting observability stack..."
@docker compose -f deploy/docker/docker-compose.observability.yml restart
@echo "✅ Observability stack restarted"
# View observability logs
observability-logs:
@echo "Viewing observability logs (Ctrl+C to exit)..."
@docker compose -f deploy/docker/docker-compose.observability.yml logs -f
# Check observability status
observability-status:
@echo "Observability Stack Status:"
@docker compose -f deploy/docker/docker-compose.observability.yml ps
# Clean observability data (WARNING: Deletes all data!)
observability-clean:
@echo "⚠️ WARNING: This will delete all observability data!"
@read -p "Are you sure? [y/N] " -n 1 -r; \
echo; \
if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
docker compose -f deploy/docker/docker-compose.observability.yml down -v; \
echo "✅ Observability data cleaned"; \
else \
echo "Cancelled"; \
fi
# ===== End Observability Stack =====
# Restart services (keep infrastructure running)
dev-restart:
@echo "Restarting application services..."
@docker compose -f deploy/docker/docker-compose.services.yml restart
@echo "✅ Services restarted"
# View infrastructure logs
infra-logs:
@echo "Viewing infrastructure logs (Ctrl+C to exit)..."
@docker compose -f deploy/docker/docker-compose.infra.yml logs -f
# Check infrastructure status
infra-status:
@echo "Checking infrastructure service status..."
@docker compose -f deploy/docker/docker-compose.infra.yml ps
@echo ""
@echo "Testing connectivity..."
@echo -n " etcd: "
@docker compose -f deploy/docker/docker-compose.infra.yml exec -T etcd etcdctl endpoint health 2>/dev/null && echo "✅" || echo "❌"
@echo -n " MySQL: "
@docker compose -f deploy/docker/docker-compose.infra.yml exec -T mysql mysqladmin ping -h localhost 2>/dev/null && echo "✅" || echo "❌"
@echo -n " Redis: "
@docker compose -f deploy/docker/docker-compose.infra.yml exec -T redis redis-cli ping 2>/dev/null && echo "✅" || echo "❌"
@echo -n " Kafka: "
@docker compose -f deploy/docker/docker-compose.infra.yml exec -T kafka kafka-broker-api-versions.sh --bootstrap-server localhost:9092 2>/dev/null >/dev/null && echo "✅" || echo "❌"
# Clean infrastructure data (WARNING: Deletes all data!)
infra-clean:
@echo "WARNING: This will delete all infrastructure data!"
@read -p "Are you sure? [y/N] " -n 1 -r; \
echo; \
if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
echo "Stopping and removing infrastructure..."; \
docker compose -f deploy/docker/docker-compose.infra.yml down -v; \
echo "✅ Infrastructure cleaned."; \
else \
echo "Cancelled."; \
fi
# Development mode (legacy alias)
dev:
@echo "Starting all services in development mode..."
@./scripts/dev.sh
# Pre-commit checks (run all quality checks before commit)
pre-commit:
@echo "Running pre-commit checks..."
@./scripts/pre-commit-checks.sh
# ===== Kubernetes Deployment =====
.PHONY: k8s-deploy-dev k8s-deploy-prod k8s-infra-deploy k8s-validate prepare-k8s-resources
# Deploy to Kubernetes development environment
k8s-deploy-dev:
@echo "Deploying to Kubernetes development environment..."
@kubectl apply -k deploy/k8s/overlays/development
@echo "✅ Deployed to development"
# Deploy to Kubernetes production environment
k8s-deploy-prod:
@echo "Deploying to Kubernetes production environment..."
@kubectl apply -k deploy/k8s/overlays/production
@echo "✅ Deployed to production"
# Deploy infrastructure to Kubernetes (Helm charts)
k8s-infra-deploy:
@echo "Deploying infrastructure to Kubernetes..."
@./deploy/k8s/infra/deploy-all.sh
@echo "✅ Infrastructure deployed"
# Validate Kubernetes manifests
k8s-validate:
@echo "Validating Kubernetes manifests..."
@kubectl apply --dry-run=client -k deploy/k8s/overlays/development
@kubectl apply --dry-run=client -k deploy/k8s/overlays/production
@echo "✅ Manifests validated"