|
| 1 | +# DharmaGuard Enterprise Platform Makefile |
| 2 | +# Comprehensive automation for development, testing, and deployment |
| 3 | + |
| 4 | +.PHONY: help dev test build clean docker deploy lint format security benchmark docs |
| 5 | + |
| 6 | +# Colors for output |
| 7 | +RED=\033[0;31m |
| 8 | +GREEN=\033[0;32m |
| 9 | +YELLOW=\033[1;33m |
| 10 | +BLUE=\033[0;34m |
| 11 | +NC=\033[0m # No Color |
| 12 | + |
| 13 | +# Default target |
| 14 | +help: ## Show this help message |
| 15 | + @echo "$(BLUE)DharmaGuard Platform - Available Commands$(NC)" |
| 16 | + @echo "=================================================" |
| 17 | + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(GREEN)%-20s$(NC) %s\n", $$1, $$2}' |
| 18 | + |
| 19 | +# Development commands |
| 20 | +dev: ## Start development environment |
| 21 | + @echo "$(YELLOW)Starting DharmaGuard development environment...$(NC)" |
| 22 | + docker-compose up -d postgres redis clickhouse kafka zookeeper |
| 23 | + @echo "$(GREEN)Development environment started!$(NC)" |
| 24 | + @echo "Access points:" |
| 25 | + @echo "- Frontend: http://localhost:3000" |
| 26 | + @echo "- API Gateway: http://localhost:8080" |
| 27 | + @echo "- Grafana: http://localhost:3001" |
| 28 | + |
| 29 | +dev-full: ## Start complete development stack |
| 30 | + @echo "$(YELLOW)Starting complete DharmaGuard stack...$(NC)" |
| 31 | + docker-compose up -d |
| 32 | + @echo "$(GREEN)Complete stack started!$(NC)" |
| 33 | + |
| 34 | +dev-stop: ## Stop development environment |
| 35 | + @echo "$(YELLOW)Stopping development environment...$(NC)" |
| 36 | + docker-compose down |
| 37 | + @echo "$(GREEN)Development environment stopped!$(NC)" |
| 38 | + |
| 39 | +dev-clean: ## Clean development environment (removes volumes) |
| 40 | + @echo "$(RED)Cleaning development environment (this will remove all data)...$(NC)" |
| 41 | + docker-compose down -v --remove-orphans |
| 42 | + docker system prune -f |
| 43 | + @echo "$(GREEN)Development environment cleaned!$(NC)" |
| 44 | + |
| 45 | +# Database commands |
| 46 | +db-migrate: ## Run database migrations |
| 47 | + @echo "$(YELLOW)Running database migrations...$(NC)" |
| 48 | + docker-compose exec postgres psql -U dharmaguard -d dharmaguard -f /docker-entrypoint-initdb.d/001_schema.sql |
| 49 | + docker-compose exec postgres psql -U dharmaguard -d dharmaguard -f /docker-entrypoint-initdb.d/002_compliance_schema.sql |
| 50 | + @echo "$(GREEN)Database migrations completed!$(NC)" |
| 51 | + |
| 52 | +db-seed: ## Seed database with test data |
| 53 | + @echo "$(YELLOW)Seeding database with test data...$(NC)" |
| 54 | + ./scripts/database/seed-test-data.sh |
| 55 | + @echo "$(GREEN)Database seeded successfully!$(NC)" |
| 56 | + |
| 57 | +db-reset: ## Reset database (WARNING: destroys all data) |
| 58 | + @echo "$(RED)Resetting database (this will destroy all data)...$(NC)" |
| 59 | + docker-compose exec postgres psql -U postgres -c "DROP DATABASE IF EXISTS dharmaguard;" |
| 60 | + docker-compose exec postgres psql -U postgres -c "CREATE DATABASE dharmaguard OWNER dharmaguard;" |
| 61 | + $(MAKE) db-migrate |
| 62 | + @echo "$(GREEN)Database reset completed!$(NC)" |
| 63 | + |
| 64 | +# Build commands |
| 65 | +build: build-core build-services build-gateway build-frontend ## Build all components |
| 66 | + |
| 67 | +build-core: ## Build core surveillance engine |
| 68 | + @echo "$(YELLOW)Building core surveillance engine...$(NC)" |
| 69 | + cd core-engine && mkdir -p build && cd build && \ |
| 70 | + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=23 .. && \ |
| 71 | + make -j$$(nproc) |
| 72 | + @echo "$(GREEN)Core engine built successfully!$(NC)" |
| 73 | + |
| 74 | +build-services: ## Build all Rust microservices |
| 75 | + @echo "$(YELLOW)Building Rust microservices...$(NC)" |
| 76 | + cd microservices/user-service && cargo build --release |
| 77 | + cd microservices/compliance-service && cargo build --release |
| 78 | + cd microservices/reporting-service && cargo build --release |
| 79 | + cd microservices/audit-service && cargo build --release |
| 80 | + @echo "$(GREEN)Microservices built successfully!$(NC)" |
| 81 | + |
| 82 | +build-gateway: ## Build API gateway |
| 83 | + @echo "$(YELLOW)Building API gateway...$(NC)" |
| 84 | + cd api-gateway && go build -o bin/api-gateway . |
| 85 | + @echo "$(GREEN)API gateway built successfully!$(NC)" |
| 86 | + |
| 87 | +build-frontend: ## Build frontend application |
| 88 | + @echo "$(YELLOW)Building frontend application...$(NC)" |
| 89 | + cd frontend && npm ci && npm run build |
| 90 | + @echo "$(GREEN)Frontend built successfully!$(NC)" |
| 91 | + |
| 92 | +build-ml: ## Build ML platform |
| 93 | + @echo "$(YELLOW)Building ML platform...$(NC)" |
| 94 | + cd ml-platform && pip install -r requirements.txt |
| 95 | + @echo "$(GREEN)ML platform built successfully!$(NC)" |
| 96 | + |
| 97 | +# Docker commands |
| 98 | +docker: ## Build all Docker images |
| 99 | + @echo "$(YELLOW)Building Docker images...$(NC)" |
| 100 | + docker build -t dharmaguard/surveillance-engine:latest ./core-engine |
| 101 | + docker build -t dharmaguard/user-service:latest ./microservices/user-service |
| 102 | + docker build -t dharmaguard/compliance-service:latest ./microservices/compliance-service |
| 103 | + docker build -t dharmaguard/reporting-service:latest ./microservices/reporting-service |
| 104 | + docker build -t dharmaguard/audit-service:latest ./microservices/audit-service |
| 105 | + docker build -t dharmaguard/api-gateway:latest ./api-gateway |
| 106 | + docker build -t dharmaguard/frontend:latest ./frontend |
| 107 | + docker build -t dharmaguard/ml-platform:latest ./ml-platform |
| 108 | + @echo "$(GREEN)Docker images built successfully!$(NC)" |
| 109 | + |
| 110 | +docker-push: ## Push Docker images to registry |
| 111 | + @echo "$(YELLOW)Pushing Docker images to registry...$(NC)" |
| 112 | + docker push dharmaguard/surveillance-engine:latest |
| 113 | + docker push dharmaguard/user-service:latest |
| 114 | + docker push dharmaguard/compliance-service:latest |
| 115 | + docker push dharmaguard/reporting-service:latest |
| 116 | + docker push dharmaguard/audit-service:latest |
| 117 | + docker push dharmaguard/api-gateway:latest |
| 118 | + docker push dharmaguard/frontend:latest |
| 119 | + docker push dharmaguard/ml-platform:latest |
| 120 | + @echo "$(GREEN)Docker images pushed successfully!$(NC)" |
| 121 | + |
| 122 | +# Testing commands |
| 123 | +test: test-unit test-integration ## Run all tests |
| 124 | + |
| 125 | +test-unit: ## Run unit tests for all components |
| 126 | + @echo "$(YELLOW)Running unit tests...$(NC)" |
| 127 | + # Core engine tests |
| 128 | + cd core-engine/build && ctest --output-on-failure |
| 129 | + # Rust service tests |
| 130 | + cd microservices/user-service && cargo test |
| 131 | + cd microservices/compliance-service && cargo test |
| 132 | + cd microservices/reporting-service && cargo test |
| 133 | + cd microservices/audit-service && cargo test |
| 134 | + # Go gateway tests |
| 135 | + cd api-gateway && go test -v ./... |
| 136 | + # Frontend tests |
| 137 | + cd frontend && npm test -- --coverage --watchAll=false |
| 138 | + @echo "$(GREEN)Unit tests completed!$(NC)" |
| 139 | + |
| 140 | +test-integration: ## Run integration tests |
| 141 | + @echo "$(YELLOW)Running integration tests...$(NC)" |
| 142 | + docker-compose -f docker-compose.test.yml up -d |
| 143 | + sleep 30 |
| 144 | + ./scripts/testing/run-integration-tests.sh |
| 145 | + docker-compose -f docker-compose.test.yml down |
| 146 | + @echo "$(GREEN)Integration tests completed!$(NC)" |
| 147 | + |
| 148 | +test-load: ## Run load tests |
| 149 | + @echo "$(YELLOW)Running load tests...$(NC)" |
| 150 | + k6 run testing/load/api-gateway.js |
| 151 | + k6 run testing/load/surveillance-engine.js |
| 152 | + @echo "$(GREEN)Load tests completed!$(NC)" |
| 153 | + |
| 154 | +test-security: ## Run security tests |
| 155 | + @echo "$(YELLOW)Running security tests...$(NC)" |
| 156 | + trivy fs --security-checks vuln,config . |
| 157 | + # Run SAST scans |
| 158 | + semgrep --config=auto . |
| 159 | + @echo "$(GREEN)Security tests completed!$(NC)" |
| 160 | + |
| 161 | +# Code quality commands |
| 162 | +lint: lint-rust lint-go lint-frontend lint-python ## Run all linters |
| 163 | + |
| 164 | +lint-rust: ## Lint Rust code |
| 165 | + @echo "$(YELLOW)Linting Rust code...$(NC)" |
| 166 | + cd microservices/user-service && cargo clippy -- -D warnings |
| 167 | + cd microservices/compliance-service && cargo clippy -- -D warnings |
| 168 | + cd microservices/reporting-service && cargo clippy -- -D warnings |
| 169 | + cd microservices/audit-service && cargo clippy -- -D warnings |
| 170 | + |
| 171 | +lint-go: ## Lint Go code |
| 172 | + @echo "$(YELLOW)Linting Go code...$(NC)" |
| 173 | + cd api-gateway && golangci-lint run |
| 174 | + |
| 175 | +lint-frontend: ## Lint frontend code |
| 176 | + @echo "$(YELLOW)Linting frontend code...$(NC)" |
| 177 | + cd frontend && npm run lint |
| 178 | + |
| 179 | +lint-python: ## Lint Python code |
| 180 | + @echo "$(YELLOW)Linting Python code...$(NC)" |
| 181 | + cd ml-platform && flake8 src/ |
| 182 | + cd ml-platform && black --check src/ |
| 183 | + |
| 184 | +format: format-rust format-go format-frontend format-python ## Format all code |
| 185 | + |
| 186 | +format-rust: ## Format Rust code |
| 187 | + @echo "$(YELLOW)Formatting Rust code...$(NC)" |
| 188 | + cd microservices/user-service && cargo fmt |
| 189 | + cd microservices/compliance-service && cargo fmt |
| 190 | + cd microservices/reporting-service && cargo fmt |
| 191 | + cd microservices/audit-service && cargo fmt |
| 192 | + |
| 193 | +format-go: ## Format Go code |
| 194 | + @echo "$(YELLOW)Formatting Go code...$(NC)" |
| 195 | + cd api-gateway && gofmt -w . |
| 196 | + |
| 197 | +format-frontend: ## Format frontend code |
| 198 | + @echo "$(YELLOW)Formatting frontend code...$(NC)" |
| 199 | + cd frontend && npm run format |
| 200 | + |
| 201 | +format-python: ## Format Python code |
| 202 | + @echo "$(YELLOW)Formatting Python code...$(NC)" |
| 203 | + cd ml-platform && black src/ |
| 204 | + |
| 205 | +# Security commands |
| 206 | +security: security-scan security-audit ## Run all security checks |
| 207 | + |
| 208 | +security-scan: ## Run security scans |
| 209 | + @echo "$(YELLOW)Running security scans...$(NC)" |
| 210 | + trivy fs --security-checks vuln,config,secret . |
| 211 | + docker scout cves --only-severity critical,high dharmaguard/surveillance-engine:latest || true |
| 212 | + |
| 213 | +security-audit: ## Run security audits |
| 214 | + @echo "$(YELLOW)Running security audits...$(NC)" |
| 215 | + cd microservices/user-service && cargo audit |
| 216 | + cd api-gateway && go mod audit || true |
| 217 | + cd frontend && npm audit --audit-level=high |
| 218 | + |
| 219 | +# Benchmark commands |
| 220 | +benchmark: benchmark-core benchmark-services ## Run all benchmarks |
| 221 | + |
| 222 | +benchmark-core: ## Run core engine benchmarks |
| 223 | + @echo "$(YELLOW)Running core engine benchmarks...$(NC)" |
| 224 | + cd core-engine/build && ./performance_benchmarks --benchmark_format=json --benchmark_out=benchmark_results.json |
| 225 | + |
| 226 | +benchmark-services: ## Run service benchmarks |
| 227 | + @echo "$(YELLOW)Running service benchmarks...$(NC)" |
| 228 | + cd microservices/user-service && cargo bench |
| 229 | + cd api-gateway && go test -bench=. -benchmem ./... |
| 230 | + |
| 231 | +# Documentation commands |
| 232 | +docs: docs-api docs-architecture ## Generate all documentation |
| 233 | + |
| 234 | +docs-api: ## Generate API documentation |
| 235 | + @echo "$(YELLOW)Generating API documentation...$(NC)" |
| 236 | + swagger-codegen generate -i docs/api/openapi.yaml -l html2 -o docs/api/html |
| 237 | + |
| 238 | +docs-architecture: ## Generate architecture documentation |
| 239 | + @echo "$(YELLOW)Generating architecture documentation...$(NC)" |
| 240 | + # Generate architecture diagrams from code |
| 241 | + @echo "Architecture documentation would be generated here" |
| 242 | + |
| 243 | +# Deployment commands |
| 244 | +deploy-dev: ## Deploy to development environment |
| 245 | + @echo "$(YELLOW)Deploying to development environment...$(NC)" |
| 246 | + kubectl apply -f infrastructure/kubernetes/namespace.yaml |
| 247 | + kubectl apply -f infrastructure/kubernetes/configmap.yaml |
| 248 | + kubectl apply -f infrastructure/kubernetes/secrets.yaml |
| 249 | + helm upgrade --install dharmaguard infrastructure/helm/dharmaguard \ |
| 250 | + --namespace dharmaguard-dev \ |
| 251 | + --values infrastructure/helm/dharmaguard/values-dev.yaml |
| 252 | + |
| 253 | +deploy-staging: ## Deploy to staging environment |
| 254 | + @echo "$(YELLOW)Deploying to staging environment...$(NC)" |
| 255 | + helm upgrade --install dharmaguard infrastructure/helm/dharmaguard \ |
| 256 | + --namespace dharmaguard-staging \ |
| 257 | + --values infrastructure/helm/dharmaguard/values-staging.yaml |
| 258 | + |
| 259 | +deploy-prod: ## Deploy to production environment |
| 260 | + @echo "$(RED)Deploying to production environment...$(NC)" |
| 261 | + @echo "$(RED)WARNING: This will deploy to production!$(NC)" |
| 262 | + @read -p "Are you sure? [y/N] " -n 1 -r; \ |
| 263 | + echo; \ |
| 264 | + if [[ $$REPLY =~ ^[Yy]$$ ]]; then \ |
| 265 | + helm upgrade --install dharmaguard infrastructure/helm/dharmaguard \ |
| 266 | + --namespace dharmaguard \ |
| 267 | + --values infrastructure/helm/dharmaguard/values-prod.yaml; \ |
| 268 | + fi |
| 269 | + |
| 270 | +# Infrastructure commands |
| 271 | +infra-plan: ## Plan infrastructure changes |
| 272 | + @echo "$(YELLOW)Planning infrastructure changes...$(NC)" |
| 273 | + cd infrastructure/terraform && terraform plan -var-file="environments/dev.tfvars" |
| 274 | + |
| 275 | +infra-apply: ## Apply infrastructure changes |
| 276 | + @echo "$(YELLOW)Applying infrastructure changes...$(NC)" |
| 277 | + cd infrastructure/terraform && terraform apply -var-file="environments/dev.tfvars" |
| 278 | + |
| 279 | +infra-destroy: ## Destroy infrastructure (WARNING: destroys everything) |
| 280 | + @echo "$(RED)WARNING: This will destroy all infrastructure!$(NC)" |
| 281 | + @read -p "Are you sure? [y/N] " -n 1 -r; \ |
| 282 | + echo; \ |
| 283 | + if [[ $$REPLY =~ ^[Yy]$$ ]]; then \ |
| 284 | + cd infrastructure/terraform && terraform destroy -var-file="environments/dev.tfvars"; \ |
| 285 | + fi |
| 286 | + |
| 287 | +# Monitoring commands |
| 288 | +monitoring-setup: ## Setup monitoring stack |
| 289 | + @echo "$(YELLOW)Setting up monitoring stack...$(NC)" |
| 290 | + helm repo add prometheus-community https://prometheus-community.github.io/helm-charts |
| 291 | + helm repo add grafana https://grafana.github.io/helm-charts |
| 292 | + helm repo add jaegertracing https://jaegertracing.github.io/helm-charts |
| 293 | + helm repo update |
| 294 | + helm install prometheus prometheus-community/kube-prometheus-stack --namespace monitoring --create-namespace |
| 295 | + helm install jaeger jaegertracing/jaeger --namespace monitoring |
| 296 | + |
| 297 | +logs: ## View application logs |
| 298 | + @echo "$(BLUE)Viewing application logs...$(NC)" |
| 299 | + kubectl logs -f deployment/surveillance-engine -n dharmaguard |
| 300 | + |
| 301 | +metrics: ## View metrics dashboard |
| 302 | + @echo "$(BLUE)Opening metrics dashboard...$(NC)" |
| 303 | + kubectl port-forward service/grafana 3000:80 -n monitoring & |
| 304 | + open http://localhost:3000 |
| 305 | + |
| 306 | +# Utility commands |
| 307 | +clean: ## Clean build artifacts |
| 308 | + @echo "$(YELLOW)Cleaning build artifacts...$(NC)" |
| 309 | + rm -rf core-engine/build |
| 310 | + cd microservices/user-service && cargo clean |
| 311 | + cd microservices/compliance-service && cargo clean |
| 312 | + cd microservices/reporting-service && cargo clean |
| 313 | + cd microservices/audit-service && cargo clean |
| 314 | + cd api-gateway && rm -rf bin/ |
| 315 | + cd frontend && rm -rf .next/ dist/ |
| 316 | + @echo "$(GREEN)Build artifacts cleaned!$(NC)" |
| 317 | + |
| 318 | +deps: ## Install/update dependencies |
| 319 | + @echo "$(YELLOW)Installing/updating dependencies...$(NC)" |
| 320 | + cd frontend && npm install |
| 321 | + cd microservices/user-service && cargo update |
| 322 | + cd microservices/compliance-service && cargo update |
| 323 | + cd microservices/reporting-service && cargo update |
| 324 | + cd microservices/audit-service && cargo update |
| 325 | + cd api-gateway && go mod tidy |
| 326 | + cd ml-platform && pip install -r requirements.txt --upgrade |
| 327 | + @echo "$(GREEN)Dependencies updated!$(NC)" |
| 328 | + |
| 329 | +check: ## Check system requirements and dependencies |
| 330 | + @echo "$(YELLOW)Checking system requirements...$(NC)" |
| 331 | + ./scripts/setup/check-requirements.sh |
| 332 | + @echo "$(GREEN)System check completed!$(NC)" |
| 333 | + |
| 334 | +# Convenience commands |
| 335 | +all: clean deps build test ## Clean, install deps, build, and test everything |
| 336 | + |
| 337 | +quick-test: ## Run quick smoke tests |
| 338 | + @echo "$(YELLOW)Running quick smoke tests...$(NC)" |
| 339 | + curl -f http://localhost:8080/health || echo "API Gateway not running" |
| 340 | + curl -f http://localhost:3000 || echo "Frontend not running" |
| 341 | + |
| 342 | +status: ## Show status of all services |
| 343 | + @echo "$(BLUE)DharmaGuard Service Status:$(NC)" |
| 344 | + @echo "==================================" |
| 345 | + docker-compose ps |
| 346 | + |
| 347 | +backup: ## Backup development data |
| 348 | + @echo "$(YELLOW)Backing up development data...$(NC)" |
| 349 | + ./scripts/backup/backup-dev-data.sh |
| 350 | + @echo "$(GREEN)Backup completed!$(NC)" |
| 351 | + |
| 352 | +restore: ## Restore development data from backup |
| 353 | + @echo "$(YELLOW)Restoring development data...$(NC)" |
| 354 | + ./scripts/backup/restore-dev-data.sh |
| 355 | + @echo "$(GREEN)Restore completed!$(NC)" |
0 commit comments