Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
120 lines (103 loc) · 4.18 KB
/
Copy pathMakefile
File metadata and controls
120 lines (103 loc) · 4.18 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
# Makefile for the Credit Risk Intelligence Platform.
# All targets are documented. Run `make help` for a summary.
.PHONY: help lint test test-integration test-load format run-local \
stop-local plan-infra clean
PYTHON := python3
PIP := pip3
SRC := src
TESTS := tests
CONFIGS := configs
# Default target - show help.
help:
@echo ""
@echo "Credit Risk Intelligence Platform - available targets:"
@echo ""
@echo " make lint Run Black, isort, flake8, and mypy checks."
@echo " make test Run unit tests with coverage (fails below 80%)."
@echo " make test-integration Run integration tests (requires Docker Compose up)."
@echo " make test-load Run Locust load test against a live endpoint."
@echo " make format Auto-format code with Black and isort."
@echo " make run-local Start Docker Compose services and the consumer."
@echo " make stop-local Stop and remove Docker Compose containers."
@echo " make plan-infra Run terraform plan for all infra modules."
@echo " make clean Remove __pycache__, .coverage, and build artefacts."
@echo ""
# ---------------------------------------------------------------------------
# Code quality
# ---------------------------------------------------------------------------
lint:
@echo "--- Black (check) ---"
black --check $(SRC) $(TESTS)
@echo "--- isort (check) ---"
isort --check-only $(SRC) $(TESTS)
@echo "--- flake8 ---"
flake8 $(SRC) $(TESTS) --max-line-length 88 --extend-ignore E203,W503
@echo "--- mypy ---"
mypy $(SRC) --ignore-missing-imports
@echo "Lint passed."
format:
black $(SRC) $(TESTS)
isort $(SRC) $(TESTS)
@echo "Format complete."
# ---------------------------------------------------------------------------
# Tests
# ---------------------------------------------------------------------------
test:
@echo "--- Unit tests ---"
$(PYTHON) -m pytest $(TESTS)/unit -v \
--cov=$(SRC) \
--cov-report=term-missing \
--cov-fail-under=80
test-integration:
@echo "--- Integration tests (requires docker compose up) ---"
$(PYTHON) -m pytest $(TESTS)/integration -v
test-load:
@echo "--- Locust load test ---"
@echo "Set LOAD_TEST_HOST to the target endpoint (e.g. http://localhost:8000)."
locust -f $(TESTS)/load/locustfile.py \
--host=$${LOAD_TEST_HOST:-http://localhost:8000} \
--headless \
--users 10000 \
--spawn-rate 100 \
--run-time 300s
# ---------------------------------------------------------------------------
# Local development environment
# ---------------------------------------------------------------------------
run-local:
@echo "--- Starting Docker Compose services ---"
docker compose up -d zookeeper kafka redis localstack
@echo "--- Waiting for Kafka to be ready (up to 60s) ---"
@timeout 60 bash -c \
'until docker compose exec -T kafka kafka-broker-api-versions \
--bootstrap-server localhost:9092 >/dev/null 2>&1; \
do echo "Waiting for Kafka..."; sleep 3; done'
@echo "--- Creating Kafka topics ---"
KAFKA_BOOTSTRAP_SERVERS=localhost:9092 $(PYTHON) scripts/create-local-topics.py
@echo "--- Starting Kafka consumer ---"
KAFKA_BOOTSTRAP_SERVERS=localhost:9092 \
KAFKA_CONSUMER_GROUP_ID=loan-applications-consumer-local \
CONFIG_PATH=$(CONFIGS)/base.yaml \
$(PYTHON) $(SRC)/ingestion/kafka-consumer.py
stop-local:
docker compose down -v
@echo "Local environment stopped."
# ---------------------------------------------------------------------------
# Infrastructure
# ---------------------------------------------------------------------------
plan-infra:
@for module in kafka emr redis s3; do \
echo "--- terraform plan: $$module ---"; \
cd infra/terraform/$$module && \
terraform init -backend=false -input=false && \
terraform validate && \
cd ../../..; \
done
@echo "All Terraform modules validated."
# ---------------------------------------------------------------------------
# Cleanup
# ---------------------------------------------------------------------------
clean:
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -delete 2>/dev/null || true
rm -rf .coverage .mypy_cache .pytest_cache dist build *.egg-info
@echo "Clean complete."