-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
executable file
Β·488 lines (401 loc) Β· 15.9 KB
/
Makefile
File metadata and controls
executable file
Β·488 lines (401 loc) Β· 15.9 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
# Second Brain - Docker-First Development
# Zero host Python dependencies required
.PHONY: help
help: ## Show this help message
@echo "Second Brain - Docker-First Development Commands"
@echo "================================================"
@echo ""
@echo "π³ Docker-first approach: All commands prefer Docker, fallback to .venv"
@echo ""
@awk 'BEGIN {FS = ":.*##"; printf "\033[36m%-20s\033[0m %s\n", "Command", "Description"} /^[a-zA-Z_-]+:.*?##/ { printf "\033[36m%-20s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
# Variables
DOCKER_COMPOSE = docker-compose
DOCKER = docker
VERSION ?= 3.0.0
REGISTRY ?= secondbrain
APP_NAME = secondbrain
# Core development commands (Docker-first with .venv fallback)
.PHONY: setup
setup: ## Set up development environment (Docker + .venv fallback)
@python scripts/dev start
.PHONY: dev
dev: ## Start development environment (Docker-first)
@python scripts/dev start
.PHONY: dev-stop
dev-stop: ## Stop development environment
@python scripts/dev stop
.PHONY: dev-logs
dev-logs: ## Show development logs
$(DOCKER_COMPOSE) logs -f app
.PHONY: shell
shell: ## Enter development shell (Docker-first)
@python scripts/dev shell
.PHONY: status
status: ## Show development environment status
@python scripts/dev status
.PHONY: db-shell
db-shell: ## Enter PostgreSQL shell
$(DOCKER_COMPOSE) exec postgres psql -U secondbrain
# Enhanced Testing - Tiered CI/CD Strategy
.PHONY: test
test: ## Run all tests (legacy command)
@python scripts/ci_runner.py --stage all
.PHONY: test-smoke
test-smoke: ## Run smoke tests (critical path, <60s)
@python scripts/ci_runner.py --stage smoke
.PHONY: test-fast
test-fast: ## Run fast feedback tests (core functionality, <5min)
@python scripts/ci_runner.py --stage fast
.PHONY: test-fast-unit
test-fast-unit: ## Run fast unit tests only
@python scripts/ci_runner.py --stage fast --group unit
.PHONY: test-fast-integration
test-fast-integration: ## Run fast integration tests only
@python scripts/ci_runner.py --stage fast --group integration-basic
.PHONY: test-fast-api
test-fast-api: ## Run fast API tests only
@python scripts/ci_runner.py --stage fast --group api-core
.PHONY: test-comprehensive
test-comprehensive: ## Run comprehensive validation tests (<15min)
@python scripts/ci_runner.py --stage comprehensive
.PHONY: test-performance
test-performance: ## Run performance benchmarks (<20min)
@python scripts/ci_runner.py --stage performance
# Legacy test commands (for backward compatibility)
.PHONY: test-unit
test-unit: ## Run unit tests (legacy)
@python -m pytest tests/unit/ -v -m "unit and not slow"
.PHONY: test-integration
test-integration: ## Run integration tests (legacy)
@python -m pytest tests/integration/ -v -m "integration and not slow"
.PHONY: test-validation
test-validation: ## Run validation tests (legacy)
@python -m pytest tests/validation/ -v
# CI/CD Pipeline Simulation
.PHONY: ci-smoke
ci-smoke: ## Simulate CI smoke tests stage
@echo "π₯ Simulating CI Smoke Tests..."
@python scripts/ci_runner.py --stage smoke --exit-on-failure
.PHONY: ci-fast
ci-fast: ## Simulate CI fast feedback stage
@echo "β‘ Simulating CI Fast Feedback..."
@python scripts/ci_runner.py --stage fast --exit-on-failure
.PHONY: ci-comprehensive
ci-comprehensive: ## Simulate CI comprehensive stage
@echo "π Simulating CI Comprehensive Tests..."
@python scripts/ci_runner.py --stage comprehensive --exit-on-failure
.PHONY: ci-performance
ci-performance: ## Simulate CI performance stage
@echo "π Simulating CI Performance Tests..."
@python scripts/ci_runner.py --stage performance
.PHONY: ci-full
ci-full: ## Run complete CI pipeline simulation
@echo "π€ Running Full CI Pipeline Simulation..."
@python scripts/ci_runner.py --stage all --save-report ci_simulation_report.json
.PHONY: ci-local
ci-local: ## Run CI pipeline locally with reporting
@echo "π Running Local CI Pipeline..."
@python scripts/ci_runner.py --stage all --save-report local_ci_report.json
# Code Quality
.PHONY: lint
lint: ## Run linters (ruff, black, mypy)
@echo "π Running linters..."
$(DOCKER_COMPOSE) run --rm app ruff check .
$(DOCKER_COMPOSE) run --rm app black --check .
$(DOCKER_COMPOSE) run --rm app mypy . --strict
.PHONY: format
format: ## Format code with black and ruff
@echo "π¨ Formatting code..."
$(DOCKER_COMPOSE) run --rm app black .
$(DOCKER_COMPOSE) run --rm app ruff check --fix .
.PHONY: security
security: ## Run security checks (bandit, safety)
@echo "π Running security checks..."
$(DOCKER_COMPOSE) run --rm app bandit -r app/
$(DOCKER_COMPOSE) run --rm app safety check
# Database
.PHONY: db-migrate
db-migrate: ## Run database migrations
$(DOCKER_COMPOSE) run --rm app alembic upgrade head
.PHONY: db-rollback
db-rollback: ## Rollback last migration
$(DOCKER_COMPOSE) run --rm app alembic downgrade -1
.PHONY: db-reset
db-reset: ## Reset database (WARNING: destroys data)
@echo "β οΈ This will destroy all data. Continue? [y/N]" && read ans && [ $${ans:-N} = y ]
$(DOCKER_COMPOSE) down -v
$(DOCKER_COMPOSE) up -d postgres
sleep 5
$(MAKE) db-migrate
# Docker
.PHONY: build
build: ## Build Docker images
@echo "ποΈ Building Docker images..."
$(DOCKER_COMPOSE) build
.PHONY: build-prod
build-prod: ## Build production Docker image
@echo "ποΈ Building production image..."
$(DOCKER) build -f docker/Dockerfile --target runtime -t $(REGISTRY)/$(APP_NAME):$(VERSION) .
.PHONY: push
push: build-prod ## Push Docker image to registry
@echo "π€ Pushing to registry..."
$(DOCKER) push $(REGISTRY)/$(APP_NAME):$(VERSION)
$(DOCKER) tag $(REGISTRY)/$(APP_NAME):$(VERSION) $(REGISTRY)/$(APP_NAME):latest
$(DOCKER) push $(REGISTRY)/$(APP_NAME):latest
# Deployment
.PHONY: deploy-local
deploy-local: ## Deploy to local Docker
@echo "π Deploying locally..."
$(DOCKER_COMPOSE) up -d
.PHONY: deploy-swarm
deploy-swarm: ## Deploy to Docker Swarm
@echo "π Deploying to Swarm..."
docker stack deploy -c compose.yaml secondbrain
.PHONY: deploy-k8s
deploy-k8s: ## Deploy to Kubernetes (future)
@echo "π Deploying to Kubernetes..."
@echo "TODO: Implement Helm deployment"
# helm upgrade --install secondbrain ./helm/secondbrain
# Monitoring
.PHONY: logs
logs: ## Show all logs
$(DOCKER_COMPOSE) logs -f
.PHONY: stats
stats: ## Show container stats
$(DOCKER) stats
.PHONY: health
health: ## Check service health
@echo "π₯ Checking health..."
@curl -f http://localhost:8000/health || echo "β App unhealthy"
@curl -f http://localhost:9090/metrics || echo "β Metrics unavailable"
@$(DOCKER_COMPOSE) ps
# Cleanup
.PHONY: clean
clean: ## Clean up containers and volumes
@echo "π§Ή Cleaning up..."
$(DOCKER_COMPOSE) down
.PHONY: clean-all
clean-all: ## Clean everything including volumes (WARNING: destroys data)
@echo "β οΈ This will destroy all data. Continue? [y/N]" && read ans && [ $${ans:-N} = y ]
$(DOCKER_COMPOSE) down -v
$(DOCKER) system prune -af
# Utilities
.PHONY: backup
backup: ## Backup database and data
@echo "πΎ Creating backup..."
@mkdir -p backups
$(DOCKER_COMPOSE) exec postgres pg_dump -U secondbrain > backups/db_$(shell date +%Y%m%d_%H%M%S).sql
$(DOCKER_COMPOSE) run --rm -v $(PWD)/backups:/backup app tar czf /backup/data_$(shell date +%Y%m%d_%H%M%S).tar.gz /app/data
.PHONY: restore
restore: ## Restore from backup (specify BACKUP_FILE)
@echo "π₯ Restoring from backup..."
@test -n "$(BACKUP_FILE)" || (echo "β Please specify BACKUP_FILE" && exit 1)
$(DOCKER_COMPOSE) exec -T postgres psql -U secondbrain < $(BACKUP_FILE)
.PHONY: version
version: ## Show version information
@echo "Second Brain v$(VERSION)"
@echo "Docker: $(shell docker --version)"
@echo "Docker Compose: $(shell docker compose version)"
@echo "Python: $(shell $(PYTHON) --version)"
# Performance Testing (Enhanced)
.PHONY: benchmark
benchmark: ## Run performance benchmarks
@echo "β‘ Running performance benchmarks..."
@python scripts/run_performance_tests.py --type benchmark
.PHONY: load-test
load-test: ## Run load tests (moderate intensity)
@echo "π Running load tests..."
@python scripts/run_performance_tests.py --type load --load-intensity moderate
.PHONY: load-test-basic
load-test-basic: ## Run basic load tests (CI-friendly)
@echo "π Running basic load tests..."
@python scripts/run_performance_tests.py --type load --load-intensity basic
.PHONY: load-test-intensive
load-test-intensive: ## Run intensive load tests
@echo "π Running intensive load tests..."
@python scripts/run_performance_tests.py --type load --load-intensity intensive
.PHONY: perf-test
perf-test: ## Run complete performance test suite
@echo "β‘ Running complete performance test suite..."
@python scripts/run_performance_tests.py --type both --load-intensity moderate
.PHONY: perf-test-quick
perf-test-quick: ## Run quick performance tests (CI/CD)
@echo "β‘ Running quick performance tests..."
@python scripts/run_performance_tests.py --type both --quick
.PHONY: profile
profile: ## Profile application
@echo "π Profiling application..."
$(DOCKER_COMPOSE) run --rm -e PROFILING=true app
# Development Workflow
.PHONY: setup
setup: ## Initial project setup
@echo "π§ Setting up project..."
@cp -n .env.example .env || true
@$(MAKE) build
@$(MAKE) db-migrate
@echo "β
Setup complete! Run 'make dev' to start."
.PHONY: update
update: ## Update dependencies
@echo "π¦ Updating dependencies..."
$(DOCKER_COMPOSE) run --rm app pip-compile --upgrade requirements.in
$(DOCKER_COMPOSE) run --rm app pip-compile --upgrade requirements-dev.in
.PHONY: check
check: lint test security ## Run all checks (lint, test, security)
@echo "β
All checks passed!"
# Enhanced CI/CD
.PHONY: ci
ci: ## Run CI pipeline locally (new tiered approach)
@echo "π€ Running Enhanced CI Pipeline..."
@$(MAKE) ci-full
# Security & Compliance
.PHONY: security-scan
security-scan: ## Run comprehensive security scans
@echo "π Running security scans..."
@python scripts/ci_runner.py --stage security --save-report security_report.json
.PHONY: license-check
license-check: ## Check license compliance
@echo "π Checking license compliance..."
@python scripts/ci_runner.py --stage license-check --save-report license_report.json
.PHONY: vulnerability-scan
vulnerability-scan: ## Scan for vulnerabilities
@echo "π‘οΈ Scanning for vulnerabilities..."
@python scripts/ci_runner.py --stage vulnerability --save-report vulnerability_report.json
# Advanced Testing
.PHONY: test-parallel
test-parallel: ## Run tests in parallel
@echo "β‘ Running tests in parallel..."
@python -m pytest -n auto tests/
.PHONY: test-coverage
test-coverage: ## Generate detailed coverage report
@echo "π Generating coverage report..."
@python -m pytest --cov=app --cov-report=html --cov-report=xml --cov-report=json
.PHONY: test-mutation
test-mutation: ## Run mutation testing (when available)
@echo "𧬠Running mutation tests..."
@echo "TODO: Implement mutation testing with mutmut"
# Performance & Load Testing
.PHONY: stress-test
stress-test: ## Run stress tests
@echo "πͺ Running stress tests..."
@python scripts/run_performance_tests.py --type stress
.PHONY: memory-test
memory-test: ## Run memory usage tests
@echo "π§ Running memory tests..."
@python scripts/run_performance_tests.py --type memory
.PHONY: cpu-profile
cpu-profile: ## Profile CPU usage
@echo "β‘ Profiling CPU usage..."
@python scripts/run_performance_tests.py --type cpu-profile
# Code Quality Enhancement
.PHONY: type-check
type-check: ## Run type checking with mypy
@echo "π Running type checks..."
$(DOCKER_COMPOSE) run --rm app mypy app/ --strict --show-error-codes
.PHONY: complexity-check
complexity-check: ## Check code complexity
@echo "π Checking code complexity..."
$(DOCKER_COMPOSE) run --rm app python -m mccabe --min 10 app/
.PHONY: dead-code
dead-code: ## Find dead code
@echo "π Finding dead code..."
$(DOCKER_COMPOSE) run --rm app vulture app/
# Documentation & Reporting
.PHONY: generate-docs
generate-docs: ## Generate API documentation
@echo "π Generating documentation..."
@python scripts/update_documentation.py --generate-all
.PHONY: api-spec
api-spec: ## Generate OpenAPI specification
@echo "π Generating API spec..."
@python scripts/generate_openapi_spec.py
.PHONY: metrics-report
metrics-report: ## Generate metrics and health report
@echo "π Generating metrics report..."
@python scripts/generate_metrics_report.py
# Docker Testing Enhancement
.PHONY: docker-test
docker-test: ## Run tests in Docker containers
@echo "π³ Running tests in Docker..."
$(DOCKER_COMPOSE) -f docker-compose.test.yml up --build --abort-on-container-exit
.PHONY: docker-security
docker-security: ## Scan Docker images for security issues
@echo "π³π Scanning Docker images..."
@docker run --rm -v /var/run/docker.sock:/var/run/docker.sock aquasec/trivy image secondbrain:latest
# Environment Validation
.PHONY: validate-env
validate-env: ## Validate environment configuration
@echo "β
Validating environment..."
@python scripts/validate_environment.py --comprehensive
.PHONY: validate-deps
validate-deps: ## Validate dependencies
@echo "π¦ Validating dependencies..."
@python scripts/validate_dependencies.py --check-security
.PHONY: validate-config
validate-config: ## Validate configuration files
@echo "βοΈ Validating configuration..."
@python scripts/validate_configurations.py --check-security
# Project Standards Validation (NEW)
.PHONY: validate-naming
validate-naming: ## Validate naming conventions across project
@echo "π Validating naming conventions..."
@python scripts/validate_naming_conventions.py --verbose
.PHONY: validate-docs
validate-docs: ## Validate documentation consistency
@echo "π Validating documentation consistency..."
@python scripts/validate_documentation.py --verbose
.PHONY: validate-standards
validate-standards: ## Validate all project standards (naming, docs, config)
@echo "π― Validating all project standards..."
@python scripts/validate_naming_conventions.py
@python scripts/validate_documentation.py
@python scripts/validate_configurations.py --check-security
@echo "β
All project standards validated!"
.PHONY: fix-standards
fix-standards: ## Attempt to fix standards violations (dry-run)
@echo "π§ Attempting to fix standards violations (dry-run)..."
@python scripts/validate_naming_conventions.py --fix --dry-run
@echo "Run without --dry-run to apply fixes"
# Test Reporting
.PHONY: test-report
test-report: ## Generate comprehensive test report
@echo "π Generating test report..."
@python scripts/ci_runner.py --stage all --save-report comprehensive_test_report.json
@python scripts/generate_test_summary.py --report comprehensive_test_report.json --output test_summary.html
# Developer Convenience Commands
.PHONY: pre-commit
pre-commit: ## Run pre-commit checks (standards + smoke + fast tests)
@echo "π§ Running pre-commit checks..."
@$(MAKE) validate-standards
@$(MAKE) test-smoke
@$(MAKE) test-fast-unit
.PHONY: pre-push
pre-push: ## Run pre-push checks (comprehensive tests)
@echo "π Running pre-push checks..."
@$(MAKE) test-comprehensive
.PHONY: pre-release
pre-release: ## Run pre-release checks (all tests + performance)
@echo "π― Running pre-release checks..."
@$(MAKE) ci-full
@$(MAKE) perf-test-quick
# Help sections
.PHONY: help-testing
help-testing: ## Show detailed testing help
@echo "π§ͺ Testing Commands - Tiered Strategy"
@echo "====================================="
@echo ""
@echo "Quick Testing (for development):"
@echo " make test-smoke - Critical path tests (<60s)"
@echo " make test-fast - Core functionality tests (<5min)"
@echo " make pre-commit - Pre-commit validation"
@echo ""
@echo "Comprehensive Testing:"
@echo " make test-comprehensive - Full validation (<15min)"
@echo " make test-performance - Performance benchmarks (<20min)"
@echo " make ci-full - Complete CI simulation"
@echo ""
@echo "Development Workflow:"
@echo " make pre-commit - Before committing code"
@echo " make pre-push - Before pushing to remote"
@echo " make pre-release - Before releasing"
# Default target
.DEFAULT_GOAL := help