-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
346 lines (297 loc) · 11.3 KB
/
Makefile
File metadata and controls
346 lines (297 loc) · 11.3 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
# Heimdall SDR - Development Makefile
# Cross-platform compatible commands
.PHONY: help dev-up dev-down test test-local test-api get-token lint format build-docker db-migrate clean setup lock-deps audit-deps deps-check test-unit test-integration test-e2e test-coverage coverage-report test-watch test-failed type-check type-check-strict type-check-watch type-coverage lint-types check-types
# Default target
help:
@echo "Heimdall SDR Development Commands:"
@echo ""
@echo " 🚀 QUICK START:"
@echo " setup Setup dev environment (first time only)"
@echo ""
@echo " INFRASTRUCTURE (Phase 1):"
@echo " dev-up Start development environment"
@echo " dev-down Stop development environment"
@echo " infra-status Show docker compose status"
@echo " health-check Run health check script"
@echo " postgres-connect Connect to PostgreSQL CLI"
@echo " redis-cli Connect to Redis CLI"
@echo ""
@echo " UI DASHBOARDS:"
@echo " rabbitmq-ui Open RabbitMQ management UI"
@echo " minio-ui Open MinIO console"
@echo " grafana-ui Open Grafana dashboards"
@echo " prometheus-ui Open Prometheus metrics"
@echo ""
@echo " DEVELOPMENT:"
@echo " test Run all tests in Docker containers (with auth)"
@echo " test-local Run tests locally (without Docker)"
@echo " test-unit Run unit tests only"
@echo " test-integration Run integration tests only"
@echo " test-e2e Run E2E tests only"
@echo " test-coverage Run tests with coverage report"
@echo " coverage-report Generate coverage analysis"
@echo " test-watch Run tests in watch mode"
@echo " test-failed Re-run only failed tests"
@echo " test-api Test API Gateway with authentication"
@echo " get-token Get Keycloak authentication token"
@echo " lint Run code linting"
@echo " format Auto-format code"
@echo " db-migrate Run database migrations"
@echo ""
@echo " TYPE CHECKING:"
@echo " type-check Run comprehensive type checking"
@echo " type-check-strict Run mypy in strict mode"
@echo " type-check-watch Run mypy in watch mode"
@echo " type-coverage Generate type coverage report"
@echo " lint-types Run pylint type-related checks"
@echo " check-types Run all type checks (mypy + pylint)"
@echo ""
@echo " MAINTENANCE:"
@echo " clean Clean all generated files"
@echo ""
@echo " DEPENDENCY MANAGEMENT:"
@echo " lock-deps Generate lock files from requirements"
@echo " audit-deps Audit dependencies for conflicts and vulnerabilities"
@echo " deps-check Run lock-deps and audit-deps"
@echo ""
# Development Environment
dev-up:
docker compose up -d
@echo "Development environment started. Waiting for services to be healthy..."
@timeout /t 10 /nobreak
docker compose ps
dev-down:
docker compose down
@echo "Development environment stopped."
dev-logs:
docker compose logs -f
# Infrastructure Operations (Phase 1)
infra-status:
docker compose ps
infra-logs:
docker compose logs -f
postgres-connect:
docker compose exec postgres psql -U heimdall_user -d heimdall
postgres-cli:
docker compose exec postgres bash
redis-cli:
docker compose exec redis redis-cli -a changeme
rabbitmq-ui:
@echo "RabbitMQ UI: http://localhost:15672 (guest/guest)"
minio-ui:
@echo "MinIO UI: http://localhost:9001 (minioadmin/minioadmin)"
grafana-ui:
@echo "Grafana UI: http://localhost:3000 (admin/admin)"
prometheus-ui:
@echo "Prometheus UI: http://localhost:9090"
# Testing
test:
@echo "Running tests in all services..."
@echo "Getting authentication token from Keycloak..."
@if ! TOKEN=$$(./scripts/get-keycloak-token.sh 2>/dev/null); then \
echo "⚠ WARNING: Failed to get Keycloak token. Tests may fail if authentication is required."; \
TOKEN=""; \
else \
echo "✓ Authentication token obtained successfully"; \
fi; \
export KEYCLOAK_TOKEN="$$TOKEN"; \
for service in services/*/; do \
if [ -d "$$service/tests" ]; then \
service_name=$$(basename $$service); \
echo "Testing $$service_name..."; \
if docker compose ps $$service_name 2>&1 | grep -q "Up"; then \
docker compose exec -T -e KEYCLOAK_TOKEN="$$TOKEN" $$service_name sh -c "if command -v pytest >/dev/null 2>&1; then \
if [ -d tests ]; then \
if pip list 2>/dev/null | grep -q pytest-cov; then \
pytest tests/ -v --cov=src/ --cov-report=term-missing || true; \
else \
pytest tests/ -v || true; \
fi; \
else \
echo 'No tests directory found in container'; \
fi; \
else \
echo 'pytest not installed in $$service_name'; \
fi" || echo "Failed to run tests in $$service_name"; \
else \
echo "⚠ Service $$service_name is not running - skipping tests"; \
fi; \
fi; \
done
@echo "Test run completed."
# Run tests locally (without Docker)
test-local:
@echo "Running tests locally..."
@if [ -d "venv" ] && [ -z "$$VIRTUAL_ENV" ]; then \
echo "⚠ Virtual environment exists but not activated."; \
echo " Activate it with: source venv/bin/activate"; \
echo " Or run: make setup"; \
exit 1; \
fi
@if command -v pytest >/dev/null 2>&1; then \
for service in services/*/; do \
if [ -d "$$service/tests" ]; then \
service_name=$$(basename $$service); \
echo ""; \
echo "=== Testing $$service_name ==="; \
cd "$$service" && pytest tests/ -v || true; \
cd ../..; \
fi; \
done; \
else \
echo "pytest not installed."; \
echo "Run 'make setup' to install all dependencies."; \
exit 1; \
fi
# Get Keycloak token (for manual testing)
get-token:
@if [ -f .env ]; then \
./scripts/get-keycloak-token.sh; \
else \
echo "ERROR: .env file not found. Copy .env.example to .env first."; \
exit 1; \
fi
# Test API Gateway with authentication
test-api:
@echo "Testing API Gateway with authentication..."
@TOKEN=$$(./scripts/get-keycloak-token.sh 2>/dev/null) || { echo "Failed to get token"; exit 1; }; \
API_GATEWAY_URL=$$(grep -v '^#' .env 2>/dev/null | grep API_GATEWAY_URL | cut -d'=' -f2 | tr -d '\r' || echo "http://localhost:8000"); \
echo "Calling $$API_GATEWAY_URL/health..."; \
curl -s -H "Authorization: Bearer $$TOKEN" "$$API_GATEWAY_URL/health" | jq . 2>/dev/null || \
curl -s -H "Authorization: Bearer $$TOKEN" "$$API_GATEWAY_URL/health"
# Code Quality
lint:
@echo "Running linting on all Python files..."
@find . -name "*.py" -type f | while read -r file; do \
echo "Linting $$file..."; \
black --check "$$file" && \
ruff check "$$file"; \
done
format:
@echo "Formatting all Python files..."
@find . -name "*.py" -type f | while read -r file; do \
echo "Formatting $$file..."; \
black "$$file" && \
ruff --fix "$$file"; \
done
# Docker Operations
build-docker:
@echo "Building all Docker images..."
@for service in services/*/; do \
if [ -f "$$service/Dockerfile" ]; then \
service_name=$$(basename $$service); \
echo "Building $$service_name..."; \
docker build -t heimdall:$$service_name "$$service"; \
fi; \
done
# Database Operations
db-migrate:
@if [ -d "db/migrations" ]; then \
echo "Running database migrations..."; \
docker compose exec postgres psql -U heimdall_user -d heimdall -c "SELECT 1;" && \
alembic upgrade head; \
else \
echo "No migrations directory found. Run infrastructure setup first."; \
fi
# Cleanup
clean:
@echo "Cleaning up..."
docker compose down -v --remove-orphans
docker system prune -f
@find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
@find . -type f -name "*.pyc" -delete 2>/dev/null || true
@find . -type d -name ".pytest_cache" -exec rm -rf {} + 2>/dev/null || true
@echo "Cleanup completed."
# Health Checks
health-check:
@echo "Checking service health..."
python scripts/health-check.py
health-check-postgres:
docker compose exec postgres pg_isready -U heimdall_user
health-check-rabbitmq:
docker compose exec rabbitmq rabbitmq-diagnostics -q ping
health-check-redis:
docker compose exec redis redis-cli -a changeme ping
health-check-minio:
@curl -f http://localhost:9000/minio/health/live || echo "MinIO health check failed"
# Documentation Audit (cross-platform)
audit-docs:
@echo "Running documentation audit..."
python scripts/audit_documentation.py --format=both
validate-doc-links:
@echo "Validating documentation links..."
python scripts/generate_doc_index.py --check-anchors
check-docs: audit-docs validate-doc-links
@echo ""
@echo "========================================="
@echo " Documentation audit complete"
@echo "========================================="
# Quick setup for new developers
setup:
@echo "Setting up Heimdall development environment..."
@if [ ! -f .env ]; then \
cp .env.example .env; \
echo "✓ Created .env file from .env.example"; \
else \
echo "✓ .env file already exists"; \
fi
@echo ""
@echo "Installing Python dependencies..."
@./scripts/setup-dev-environment.sh
@echo ""
@echo "Setup complete! Next steps:"
@echo " 1. Activate virtual environment: source venv/bin/activate"
@echo " 2. Start services: make dev-up"
@echo " 3. Run tests: make test-local"
# Testing targets
test-unit:
@echo "Running unit tests..."
pytest services -m "not integration and not e2e" -v --tb=short
test-integration:
@echo "Running integration tests..."
pytest services -m "integration" -v --tb=short
test-e2e:
@echo "Running E2E tests..."
pytest services -m "e2e" -v --tb=short
test-coverage:
@echo "Running tests with coverage..."
pytest services --cov=services --cov-report=html --cov-report=term -v
@echo "📊 Coverage report generated: htmlcov/index.html"
coverage-report:
@echo "Generating coverage analysis..."
python scripts/analyze_coverage.py
test-watch:
@echo "Running tests in watch mode..."
@if command -v pytest-watch >/dev/null 2>&1; then \
pytest-watch services; \
else \
echo "pytest-watch not installed. Install with: pip install pytest-watch"; \
exit 1; \
fi
test-failed:
@echo "Re-running failed tests..."
pytest services --lf -v --tb=short
# Dependency Management
lock-deps:
@echo "Generating lock files from requirements..."
python scripts/lock_requirements.py --verbose
audit-deps:
@echo "Auditing dependencies across all services..."
python scripts/audit_dependencies.py --format=all
deps-check: lock-deps audit-deps
@echo "✅ Dependency audit complete"
@echo "Check audit-results/ for detailed reports"
# Type Checking
type-check:
python scripts/check_types.py
type-check-strict:
mypy services --strict --show-error-codes
type-check-watch:
mypy services --follow-imports=skip --strict --watch
type-coverage:
mypy services --strict --html-report=mypy-report
@echo "Type coverage report generated in mypy-report/"
lint-types:
pylint services/*/src --disable=all --enable=E,F
check-types: type-check lint-types
@echo "✅ Type checking complete"