forked from ent0n29/aware
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
248 lines (199 loc) · 14.3 KB
/
Makefile
File metadata and controls
248 lines (199 loc) · 14.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
# ═══════════════════════════════════════════════════════════════════════════════
# AWARE Fund - Makefile
# ═══════════════════════════════════════════════════════════════════════════════
# The Vanguard of Prediction Markets
#
# Usage: make <target>
# Run 'make help' to see all available targets
# ═══════════════════════════════════════════════════════════════════════════════
.PHONY: help local up down build logs status clean deploy-dev deploy-prod test
# Default target
.DEFAULT_GOAL := help
# Colors
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
BLUE := $(shell tput -Txterm setaf 4)
RESET := $(shell tput -Txterm sgr0)
# ═══════════════════════════════════════════════════════════════════════════════
# HELP
# ═══════════════════════════════════════════════════════════════════════════════
help: ## Show this help
@echo ''
@echo '${GREEN}AWARE Fund${RESET} - The Vanguard of Prediction Markets'
@echo ''
@echo '${YELLOW}Quick Start:${RESET}'
@echo ' ${BLUE}make build${RESET} Rebuild Docker images (after code changes)'
@echo ' ${BLUE}make local${RESET} Start everything (services + analytics)'
@echo ' ${BLUE}make down${RESET} Stop everything'
@echo ''
@echo '${YELLOW}ML Training:${RESET}'
@echo ' ${BLUE}make train${RESET} Quick (10K traders, ~8 min)'
@echo ' ${BLUE}make train-all${RESET} All eligible traders (currently ~4K)'
@echo ''
@echo '${YELLOW}Other:${RESET}'
@echo ' ${BLUE}make analytics${RESET} Run analytics only'
@echo ' ${BLUE}make logs${RESET} View logs'
@echo ' ${BLUE}make status${RESET} Health check'
@echo ''
# ═══════════════════════════════════════════════════════════════════════════════
# LOCAL DEVELOPMENT
# ═══════════════════════════════════════════════════════════════════════════════
local: docker-check ## Start everything + run analytics (one command!)
@echo '${GREEN}Starting AWARE Fund local stack...${RESET}'
docker compose -f docker-compose.local.yaml up -d
@echo ''
@echo '${YELLOW}Waiting for services to be ready...${RESET}'
@sleep 10
@echo '${GREEN}Running analytics pipeline...${RESET}'
@docker exec aware-analytics python3 run_all.py 2>&1 | grep -E "(INFO|WARNING|Complete)" | tail -20 || true
@echo ''
@echo '${GREEN}✓ AWARE Fund ready!${RESET}'
@echo ''
@echo ' Web Dashboard: http://localhost:3000'
@echo ' Python API: http://localhost:8000'
@echo ' Strategy Service: http://localhost:8081'
@echo ' ClickHouse: http://localhost:8123'
@echo ''
@echo 'Commands: ${BLUE}make train${RESET} (retrain ML) | ${BLUE}make logs${RESET} | ${BLUE}make down${RESET}'
up: local ## Alias for 'make local'
down: ## Stop all local services
@echo '${YELLOW}Stopping all services...${RESET}'
docker compose -f docker-compose.local.yaml down
@echo '${GREEN}Done!${RESET}'
build: docker-check ## Rebuild and start local stack
@echo '${GREEN}Rebuilding AWARE Fund...${RESET}'
docker compose -f docker-compose.local.yaml build
docker compose -f docker-compose.local.yaml up -d
logs: ## View logs (usage: make logs or make logs SERVICE=strategy)
@if [ -z "$(SERVICE)" ]; then \
docker compose -f docker-compose.local.yaml logs -f --tail=100; \
else \
docker compose -f docker-compose.local.yaml logs -f --tail=100 $(SERVICE); \
fi
status: ## Check service health status
@echo '${GREEN}Service Status:${RESET}'
@echo ''
@docker compose -f docker-compose.local.yaml ps
@echo ''
@echo '${GREEN}Health Checks:${RESET}'
@curl -s http://localhost:8080/api/polymarket/health > /dev/null 2>&1 && echo ' ✓ Executor (8080)' || echo ' ✗ Executor (8080)'
@curl -s http://localhost:8081/api/strategy/status > /dev/null 2>&1 && echo ' ✓ Strategy (8081)' || echo ' ✗ Strategy (8081)'
@curl -s http://localhost:8000/api/health > /dev/null 2>&1 && echo ' ✓ API (8000)' || echo ' ✗ API (8000)'
@curl -s http://localhost:3000 > /dev/null 2>&1 && echo ' ✓ Web (3000)' || echo ' ✗ Web (3000)'
@curl -s http://localhost:8123 > /dev/null 2>&1 && echo ' ✓ ClickHouse (8123)' || echo ' ✗ ClickHouse (8123)'
clean: ## Stop all services and remove volumes
@echo '${YELLOW}Stopping and removing all containers and volumes...${RESET}'
docker compose -f docker-compose.local.yaml down -v
@echo '${GREEN}Cleaned!${RESET}'
monitor: docker-check ## Start with Prometheus + Grafana monitoring
docker compose -f docker-compose.local.yaml --profile monitoring up -d
@echo ''
@echo '${GREEN}Monitoring started:${RESET}'
@echo ' Grafana: http://localhost:3001 (admin/admin)'
@echo ' Prometheus: http://localhost:9090'
# ═══════════════════════════════════════════════════════════════════════════════
# INFRASTRUCTURE ONLY (for running Java services from IDE)
# ═══════════════════════════════════════════════════════════════════════════════
infra: docker-check ## Start only infrastructure (ClickHouse, Kafka) for IDE dev
@echo '${GREEN}Starting infrastructure only...${RESET}'
docker compose -f docker-compose.analytics.yaml up -d
@echo ''
@echo '${GREEN}Infrastructure ready:${RESET}'
@echo ' ClickHouse: localhost:8123'
@echo ' Kafka: localhost:9092'
infra-down: ## Stop infrastructure
docker compose -f docker-compose.analytics.yaml down
# ═══════════════════════════════════════════════════════════════════════════════
# JAVA SERVICES (run from Maven, not Docker)
# ═══════════════════════════════════════════════════════════════════════════════
java-build: ## Build all Java services
@echo '${GREEN}Building Java services...${RESET}'
mvn clean package -DskipTests
java-test: ## Run Java tests
mvn test
executor: ## Start executor-service (requires infra)
cd executor-service && mvn spring-boot:run -Dspring-boot.run.profiles=develop
strategy: ## Start strategy-service (requires infra + executor)
cd strategy-service && mvn spring-boot:run -Dspring-boot.run.profiles=develop
ingestor: ## Start ingestor-service (requires infra)
cd ingestor-service && mvn spring-boot:run -Dspring-boot.run.profiles=develop
# ═══════════════════════════════════════════════════════════════════════════════
# PYTHON SERVICES
# ═══════════════════════════════════════════════════════════════════════════════
python-setup: ## Setup Python virtual environments
@echo '${GREEN}Setting up Python environments...${RESET}'
cd aware-fund/services/analytics && python -m venv .venv && .venv/bin/pip install -r requirements.txt
cd aware-fund/services/api && python -m venv .venv && .venv/bin/pip install -r requirements.txt
python-analytics: ## Run analytics jobs ONCE (requires infra)
cd aware-fund/services/analytics && source .venv/bin/activate && CLICKHOUSE_HOST=localhost python run_all.py
python-analytics-continuous: ## Run ML analytics continuously (hourly updates)
@echo '${GREEN}Starting ML analytics pipeline (continuous mode)...${RESET}'
cd aware-fund/services/analytics && source .venv/bin/activate && CLICKHOUSE_HOST=localhost python run_all.py --continuous --interval 3600
python-api: ## Start Python API (requires infra)
cd aware-fund/services/api && source .venv/bin/activate && CLICKHOUSE_HOST=localhost uvicorn main:app --reload --host 0.0.0.0 --port 8000
# ═══════════════════════════════════════════════════════════════════════════════
# ML PIPELINE
# ═══════════════════════════════════════════════════════════════════════════════
train: ## Retrain ML models (quick: 10K traders, ~8 min)
@echo '${GREEN}Retraining ML models (quick mode)...${RESET}'
@echo 'Training on 10K traders, 50 epochs (~8 min)'
@docker exec aware-analytics python3 -m ml.training.train --max-traders 10000 --epochs 50
@echo ''
@echo '${GREEN}Running analytics with new model...${RESET}'
@docker exec aware-analytics python3 run_all.py 2>&1 | grep -E "(INFO|Complete)" | tail -10
@echo '${GREEN}✓ Training complete! Refresh UI to see changes.${RESET}'
train-all: ## Retrain on ALL eligible traders (no limit)
@echo '${GREEN}Retraining ML models on ALL data...${RESET}'
@echo 'Training on all eligible traders, 100 epochs'
@docker exec aware-analytics python3 -m ml.training.train --max-traders 999999 --epochs 100
@echo ''
@echo '${GREEN}Running analytics with new model...${RESET}'
@docker exec aware-analytics python3 run_all.py 2>&1 | grep -E "(INFO|Complete)" | tail -10
@echo '${GREEN}✓ Training complete! Refresh UI to see changes.${RESET}'
analytics: ## Run analytics pipeline only (no training)
@echo '${GREEN}Running analytics...${RESET}'
@docker exec aware-analytics python3 run_all.py 2>&1 | grep -E "(INFO|WARNING|Complete)" | tail -20
# ═══════════════════════════════════════════════════════════════════════════════
# WEB DASHBOARD
# ═══════════════════════════════════════════════════════════════════════════════
web-install: ## Install web dependencies
cd aware-fund/services/web && npm install
web-dev: ## Start web dashboard in dev mode
cd aware-fund/services/web && npm run dev
web-build: ## Build web dashboard for production
cd aware-fund/services/web && npm run build
# ═══════════════════════════════════════════════════════════════════════════════
# SERVER DEPLOYMENT
# ═══════════════════════════════════════════════════════════════════════════════
deploy-dev: ## Deploy to development server
@echo '${GREEN}Deploying to DEV server...${RESET}'
ssh aware-dev 'cd /opt/aware && git pull && make server-restart ENV=dev'
deploy-prod: ## Deploy to production server (requires confirmation)
@echo '${YELLOW}⚠️ You are about to deploy to PRODUCTION${RESET}'
@read -p "Type 'yes' to confirm: " confirm && [ "$$confirm" = "yes" ] || exit 1
@echo '${GREEN}Deploying to PROD server...${RESET}'
ssh aware-prod 'cd /opt/aware && git pull && make server-restart ENV=prod'
server-restart: ## Restart services on server (used by deploy)
docker compose -f deploy/docker-compose.$(ENV).yaml build
docker compose -f deploy/docker-compose.$(ENV).yaml up -d
server-logs: ## View server logs
docker compose -f deploy/docker-compose.$(ENV).yaml logs -f --tail=100
server-status: ## Check server status
docker compose -f deploy/docker-compose.$(ENV).yaml ps
# ═══════════════════════════════════════════════════════════════════════════════
# UTILITIES
# ═══════════════════════════════════════════════════════════════════════════════
docker-check:
@docker info > /dev/null 2>&1 || (echo '${YELLOW}Docker is not running. Please start Docker.${RESET}' && exit 1)
clickhouse-shell: ## Open ClickHouse SQL shell
docker exec -it aware-clickhouse clickhouse-client
redpanda-shell: ## Open Redpanda/Kafka shell
docker exec -it aware-redpanda rpk topic list
psql: ## Alias for clickhouse-shell
$(MAKE) clickhouse-shell
# Show fund status
fund-status: ## Show all fund status
@curl -s http://localhost:8081/api/strategy/funds/all | python3 -m json.tool
# Run PSI index rebuild
psi-rebuild: ## Rebuild all PSI indices
cd aware-fund/services/analytics && source .venv/bin/activate && CLICKHOUSE_HOST=localhost python -c "from psi_index import *; import clickhouse_connect; c=clickhouse_connect.get_client(host='localhost',port=8123,database='polybot'); b=PSIIndexBuilder(c); [b.save_index(b.build_index(t)) for t in [IndexType.PSI_10, IndexType.PSI_25, IndexType.PSI_CRYPTO, IndexType.PSI_SPORTS, IndexType.PSI_ALPHA]]"