-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
220 lines (177 loc) Β· 10.7 KB
/
Copy pathMakefile
File metadata and controls
220 lines (177 loc) Β· 10.7 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
# ============================================================
# NDSEP β National Data Sovereignty Enforcement Platform
# Makefile β Production-grade build, test, and deployment tasks
# ============================================================
.DEFAULT_GOAL := help
SHELL := /bin/bash
.PHONY: help install build test lint typecheck clean dev docker-up docker-down \
docker-build docker-push k8s-apply k8s-delete smoke-test seed-db \
db-push db-migrate db-reset workers-build workers-clean audit-security \
audit-deps logs-tail health-check backup-db restore-db
# βββ Variables ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
APP_NAME := ndsep
APP_VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "v3.0.0")
DOCKER_REPO := ghcr.io/ndpc/ndsep
DOCKER_TAG := $(APP_VERSION)
K8S_NAMESPACE := ndsep-production
GO_DIR := workers/go
PYTHON_DIR := workers/python
RUST_DIR := workers/rust
NODE_ENV ?= development
# βββ Colours βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
RESET := \033[0m
# βββ Help βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
help: ## Show this help message
@echo ""
@echo "$(GREEN)NDSEP β National Data Sovereignty Enforcement Platform$(RESET)"
@echo "$(YELLOW)Version: $(APP_VERSION)$(RESET)"
@echo ""
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make $(GREEN)<target>$(RESET)\n\nTargets:\n"} \
/^[a-zA-Z_0-9-]+:.*?##/ { printf " $(GREEN)%-22s$(RESET) %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
@echo ""
# βββ Development ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
install: ## Install all Node.js dependencies
@echo "$(GREEN)Installing dependencies...$(RESET)"
pnpm install --frozen-lockfile
dev: ## Start development server with hot reload
@echo "$(GREEN)Starting development server...$(RESET)"
NODE_ENV=development pnpm dev
build: ## Build production assets (TypeScript + Vite)
@echo "$(GREEN)Building production assets...$(RESET)"
pnpm run build
clean: ## Remove build artifacts and caches
@echo "$(YELLOW)Cleaning build artifacts...$(RESET)"
rm -rf dist client/dist .turbo .vite node_modules/.cache
find . -name "*.js.map" -not -path "*/node_modules/*" -delete
# βββ Testing ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
test: ## Run full Vitest test suite
@echo "$(GREEN)Running test suite...$(RESET)"
pnpm test -- --reporter=verbose
test-watch: ## Run tests in watch mode
pnpm test -- --watch
test-coverage: ## Run tests with coverage report
pnpm test -- --coverage
smoke-test: ## Run smoke tests against running server
@echo "$(GREEN)Running smoke tests...$(RESET)"
@node scripts/smoke-test.mjs || (echo "$(RED)Smoke tests FAILED$(RESET)" && exit 1)
@echo "$(GREEN)Smoke tests PASSED$(RESET)"
# βββ Code Quality βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
lint: ## Run ESLint
@echo "$(GREEN)Running ESLint...$(RESET)"
pnpm eslint . --ext .ts,.tsx --max-warnings 0
typecheck: ## Run TypeScript type checking
@echo "$(GREEN)Running TypeScript check...$(RESET)"
pnpm tsc --noEmit
audit-security: ## Run security audit scan
@echo "$(GREEN)Running security audit...$(RESET)"
pnpm audit --audit-level=high
@echo "$(GREEN)Security audit complete$(RESET)"
audit-deps: ## Check for outdated dependencies
pnpm outdated
# βββ Database βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
db-push: ## Push Drizzle schema changes to database
@echo "$(GREEN)Pushing schema changes...$(RESET)"
pnpm db:push
db-migrate: ## Run pending database migrations
@echo "$(GREEN)Running migrations...$(RESET)"
pnpm db:migrate
db-reset: ## Reset database (DESTRUCTIVE β dev only)
@echo "$(RED)WARNING: This will destroy all data!$(RESET)"
@read -p "Type 'yes' to confirm: " confirm && [ "$$confirm" = "yes" ] || exit 1
psql "$$DATABASE_URL" -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"
pnpm db:push
seed-db: ## Seed database with realistic Nigerian test data
@echo "$(GREEN)Seeding database...$(RESET)"
node scripts/seed.mjs
@echo "$(GREEN)Database seeded successfully$(RESET)"
backup-db: ## Create a timestamped database backup
@echo "$(GREEN)Creating database backup...$(RESET)"
@mkdir -p backups
pg_dump "$$DATABASE_URL" --no-owner --no-acl -F c \
-f "backups/ndsep_$(shell date +%Y%m%d_%H%M%S).dump"
@echo "$(GREEN)Backup created in backups/$(RESET)"
restore-db: ## Restore database from backup (BACKUP_FILE=path/to/file.dump)
@test -n "$(BACKUP_FILE)" || (echo "$(RED)Set BACKUP_FILE=path/to/backup.dump$(RESET)" && exit 1)
pg_restore "$$DATABASE_URL" --no-owner --no-acl -d ndsep_db "$(BACKUP_FILE)"
# βββ Workers ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
workers-build: ## Build all Go and Rust worker binaries
@echo "$(GREEN)Building Go workers...$(RESET)"
cd $(GO_DIR) && /usr/local/go/bin/go build -o bin/nip_rtgs_processor ./cmd/nip_rtgs_processor/...
cd $(GO_DIR) && /usr/local/go/bin/go build -o bin/dpi_engine ./cmd/dpi_engine/... 2>/dev/null || true
cd $(GO_DIR) && /usr/local/go/bin/go build -o bin/discovery_agent ./cmd/discovery_agent/... 2>/dev/null || true
cd $(GO_DIR) && /usr/local/go/bin/go build -o bin/compliance_engine ./cmd/compliance_engine/... 2>/dev/null || true
@echo "$(GREEN)Building Rust workers...$(RESET)"
cd $(RUST_DIR) && cargo build --release 2>/dev/null || true
@echo "$(GREEN)Workers built$(RESET)"
workers-clean: ## Remove compiled worker binaries
rm -rf $(GO_DIR)/bin/*
rm -rf $(RUST_DIR)/target/release/
# βββ Docker βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
docker-build: ## Build Docker image
@echo "$(GREEN)Building Docker image $(DOCKER_REPO):$(DOCKER_TAG)...$(RESET)"
docker build \
--build-arg APP_VERSION=$(APP_VERSION) \
--build-arg BUILD_DATE=$(shell date -u +%Y-%m-%dT%H:%M:%SZ) \
-t $(DOCKER_REPO):$(DOCKER_TAG) \
-t $(DOCKER_REPO):latest \
.
docker-push: ## Push Docker image to registry
@echo "$(GREEN)Pushing $(DOCKER_REPO):$(DOCKER_TAG)...$(RESET)"
docker push $(DOCKER_REPO):$(DOCKER_TAG)
docker push $(DOCKER_REPO):latest
docker-up: ## Start all infrastructure services (dev)
@echo "$(GREEN)Starting infrastructure services...$(RESET)"
docker compose up -d --wait
@echo "$(GREEN)Services running. Ports: PG=5432, Redis=6379, Kafka=9092, Prometheus=9090, Grafana=3001$(RESET)"
docker-down: ## Stop all infrastructure services
docker compose down
docker-logs: ## Follow logs for all services
docker compose logs -f
docker-prod-up: ## Start production stack
docker compose -f docker-compose.production.yml up -d --wait
docker-prod-down: ## Stop production stack
docker compose -f docker-compose.production.yml down
# βββ Kubernetes βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
k8s-apply: ## Apply all Kubernetes manifests
@echo "$(GREEN)Applying K8s manifests to namespace $(K8S_NAMESPACE)...$(RESET)"
kubectl apply -f infra/k8s/namespace.yaml
kubectl apply -f infra/k8s/configmap.yaml
kubectl apply -f infra/k8s/network-policy.yaml
kubectl apply -f infra/k8s/api-deployment.yaml
kubectl apply -f infra/k8s/workers-deployment.yaml
kubectl apply -f infra/k8s/hpa.yaml
kubectl apply -f infra/k8s/ingress.yaml
@echo "$(GREEN)K8s manifests applied$(RESET)"
k8s-delete: ## Delete all Kubernetes resources
@echo "$(RED)Deleting K8s resources from namespace $(K8S_NAMESPACE)...$(RESET)"
kubectl delete -f infra/k8s/ --ignore-not-found=true
k8s-status: ## Show Kubernetes deployment status
kubectl get pods,svc,ingress -n $(K8S_NAMESPACE)
k8s-logs: ## Stream logs from API pods
kubectl logs -f -l app=ndsep-api -n $(K8S_NAMESPACE) --max-log-requests=5
k8s-rollout: ## Trigger a rolling restart of API deployment
kubectl rollout restart deployment/ndsep-api -n $(K8S_NAMESPACE)
kubectl rollout status deployment/ndsep-api -n $(K8S_NAMESPACE)
# βββ Health & Monitoring ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
health-check: ## Check platform health endpoints
@echo "$(GREEN)Checking platform health...$(RESET)"
@curl -sf http://localhost:3000/api/health | python3 -m json.tool || echo "$(RED)API health check FAILED$(RESET)"
@curl -sf http://localhost:3000/api/workers/status | python3 -m json.tool | grep -c '"status":"running"' | \
xargs -I{} echo "$(GREEN){} workers running$(RESET)"
logs-tail: ## Tail application logs
tail -f .manus-logs/devserver.log
# βββ CI/CD Pipeline βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ci: install typecheck lint test ## Run full CI pipeline (install + typecheck + lint + test)
@echo "$(GREEN)CI pipeline complete$(RESET)"
release: ci build docker-build docker-push ## Full release pipeline
@echo "$(GREEN)Release $(APP_VERSION) complete$(RESET)"
# βββ Utilities ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
version: ## Show application version
@echo "$(APP_VERSION)"
env-check: ## Validate required environment variables
@node -e "require('./server/_core/env.js')" 2>&1 | head -20
format: ## Format code with Prettier
pnpm prettier --write "**/*.{ts,tsx,json,md}" --ignore-path .gitignore