-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
256 lines (206 loc) Β· 9.16 KB
/
Makefile
File metadata and controls
256 lines (206 loc) Β· 9.16 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
# =====================================================================
# Octopus Trading Platform - Production Makefile
# Secure, maintainable commands for development and deployment
# =====================================================================
.PHONY: help install setup dev build test deploy clean security-check lint
# Default target
.DEFAULT_GOAL := help
# Configuration
PROJECT_NAME := octopus-trading-platform
PYTHON := python3
PIP := pip3
DOCKER_COMPOSE := docker-compose
NODE := npm
# Environment setup
VENV_NAME := .venv
REQUIREMENTS := requirements/requirements.txt
DEV_REQUIREMENTS := requirements/requirements-dev.txt
# =====================================================================
# HELP & DOCUMENTATION
# =====================================================================
help: ## Show this help message
@echo "π Octopus Trading Platform - Development Commands"
@echo "=================================================="
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# =====================================================================
# ENVIRONMENT SETUP
# =====================================================================
install: ## Install Python dependencies
@echo "π¦ Installing Python dependencies..."
$(PIP) install -r $(REQUIREMENTS)
$(PIP) install -r $(DEV_REQUIREMENTS)
setup-env: ## Setup environment from template
@echo "π§ Setting up environment configuration..."
@if [ ! -f .env ]; then \
cp config/env.example .env; \
echo "β
Created .env from template. Please update with your values."; \
echo "π Generate secure secrets using: python -c \"import secrets; print(secrets.token_urlsafe(32))\""; \
else \
echo "β οΈ .env already exists. Use 'make reset-env' to recreate."; \
fi
setup: setup-env install ## Complete project setup
@echo "π Setting up Octopus Trading Platform..."
@$(PYTHON) -m venv $(VENV_NAME) || echo "Virtual environment already exists"
@echo "β
Setup complete! Activate venv with: source $(VENV_NAME)/bin/activate"
# =====================================================================
# DEVELOPMENT COMMANDS
# =====================================================================
dev: ## Start development server
@echo "π Starting FastAPI development server..."
$(PYTHON) -m uvicorn src.main_refactored:app --host 0.0.0.0 --port 8000 --reload
dev-frontend: ## Start frontend development server
@echo "π¨ Starting Next.js frontend..."
cd frontend-nextjs && $(NODE) run dev
dev-all: ## Start all development services
@echo "π Starting all development services..."
@echo "Starting backend in background..."
@$(PYTHON) -m uvicorn src.main_refactored:app --host 0.0.0.0 --port 8000 --reload &
@echo "Starting frontend..."
@cd frontend-nextjs && $(NODE) run dev
celery-worker: ## Start Celery worker
@echo "βοΈ Starting Celery worker..."
celery -A src.core.celery_app worker -l info
celery-beat: ## Start Celery beat scheduler
@echo "β° Starting Celery beat scheduler..."
celery -A src.core.celery_app beat -l info
# =====================================================================
# DOCKER COMMANDS
# =====================================================================
build: ## Build Docker images
@echo "π³ Building Docker images..."
$(DOCKER_COMPOSE) build
up: ## Start all services with Docker
@echo "π Starting all services with Docker..."
$(DOCKER_COMPOSE) up -d
down: ## Stop all Docker services
@echo "π Stopping all Docker services..."
$(DOCKER_COMPOSE) down
logs: ## View Docker logs
@echo "π Viewing Docker logs..."
$(DOCKER_COMPOSE) logs -f
restart: down up ## Restart all Docker services
# =====================================================================
# DATABASE COMMANDS
# =====================================================================
db-up: ## Start only database services
@echo "ποΈ Starting database services..."
$(DOCKER_COMPOSE) up -d db redis
db-migrate: ## Run database migrations
@echo "π Running database migrations..."
$(PYTHON) -m alembic upgrade head
db-reset: ## Reset database (CAUTION: Deletes all data)
@echo "β οΈ WARNING: This will delete all data!"
@read -p "Type 'YES' to confirm: " confirm; \
if [ "$$confirm" = "YES" ]; then \
$(DOCKER_COMPOSE) down -v; \
$(DOCKER_COMPOSE) up -d db redis; \
sleep 5; \
$(PYTHON) -m alembic upgrade head; \
echo "β
Database reset complete"; \
else \
echo "β Database reset cancelled"; \
fi
# =====================================================================
# TESTING & QUALITY ASSURANCE
# =====================================================================
test: ## Run all tests
@echo "π§ͺ Running tests..."
$(PYTHON) -m pytest tests/ -v --cov=src --cov-report=html --cov-report=term
test-fast: ## Run tests without coverage
@echo "β‘ Running fast tests..."
$(PYTHON) -m pytest tests/ -v -x
lint: ## Run code linting
@echo "π Running code linting..."
$(PYTHON) -m flake8 src/ tests/
$(PYTHON) -m black --check src/ tests/
$(PYTHON) -m isort --check-only src/ tests/
format: ## Format code
@echo "β¨ Formatting code..."
$(PYTHON) -m black src/ tests/
$(PYTHON) -m isort src/ tests/
security-check: ## Run security checks
@echo "π Running security checks..."
$(PYTHON) -m bandit -r src/ -ll
$(PYTHON) -m safety check
# =====================================================================
# MAINTENANCE & CLEANUP
# =====================================================================
clean: ## Clean up temporary files
@echo "π§Ή Cleaning up temporary files..."
find . -type f -name "*.pyc" -delete
find . -type d -name "__pycache__" -delete
find . -type d -name "*.egg-info" -exec rm -rf {} +
find . -type f -name ".coverage" -delete
find . -type d -name "htmlcov" -exec rm -rf {} +
find . -type d -name ".pytest_cache" -exec rm -rf {} +
find . -type f -name "*.log" -delete
clean-docker: ## Clean Docker resources
@echo "π³ Cleaning Docker resources..."
$(DOCKER_COMPOSE) down -v --remove-orphans
docker image prune -f
docker volume prune -f
reset-env: ## Reset environment file
@echo "π Resetting environment file..."
@rm -f .env
@cp config/env.example .env
@echo "β
Environment file reset. Please update with your values."
# =====================================================================
# DEPLOYMENT COMMANDS
# =====================================================================
deploy-staging: ## Deploy to staging environment
@echo "π Deploying to staging..."
@echo "ENVIRONMENT=staging" > .env.staging
@cat config/env.example >> .env.staging
$(DOCKER_COMPOSE) -f docker-compose.yml --env-file .env.staging up -d
deploy-prod: ## Deploy to production environment
@echo "π Deploying to production..."
@echo "β οΈ WARNING: Production deployment!"
@read -p "Type 'DEPLOY' to confirm: " confirm; \
if [ "$$confirm" = "DEPLOY" ]; then \
echo "ENVIRONMENT=production" > .env.production; \
cat config/env.example >> .env.production; \
$(DOCKER_COMPOSE) -f docker-compose.yml --env-file .env.production up -d; \
echo "β
Production deployment complete"; \
else \
echo "β Production deployment cancelled"; \
fi
# =====================================================================
# MONITORING & HEALTH
# =====================================================================
health: ## Check service health
@echo "π₯ Checking service health..."
@curl -f http://localhost:8000/health || echo "β API not responding"
@curl -f http://localhost:3000 || echo "β Frontend not responding"
@curl -f http://localhost:9090 || echo "β Prometheus not responding"
@curl -f http://localhost:3001 || echo "β Grafana not responding"
status: ## Show service status
@echo "π Service Status:"
@$(DOCKER_COMPOSE) ps
# =====================================================================
# UTILITY COMMANDS
# =====================================================================
generate-secrets: ## Generate secure secrets
@echo "π Generating secure secrets..."
@echo "SECRET_KEY=$$(python -c 'import secrets; print(secrets.token_urlsafe(32))')"
@echo "JWT_SECRET_KEY=$$(python -c 'import secrets; print(secrets.token_urlsafe(32))')"
backup-data: ## Backup important data
@echo "πΎ Creating data backup..."
@mkdir -p backups
@$(DOCKER_COMPOSE) exec db pg_dump -U postgres trading_db > backups/backup_$$(date +%Y%m%d_%H%M%S).sql
@echo "β
Database backup created in backups/"
# =====================================================================
# DEVELOPMENT UTILITIES
# =====================================================================
shell: ## Open Python shell with app context
@echo "π Opening Python shell..."
$(PYTHON) -c "from src.main_refactored import app; import IPython; IPython.start_ipython(argv=[])"
db-shell: ## Open database shell
@echo "ποΈ Opening database shell..."
$(DOCKER_COMPOSE) exec db psql -U postgres trading_db
redis-shell: ## Open Redis shell
@echo "π¦ Opening Redis shell..."
$(DOCKER_COMPOSE) exec redis redis-cli
docs: ## Generate API documentation
@echo "π Generating API documentation..."
@echo "API docs available at: http://localhost:8000/docs"
@echo "ReDoc available at: http://localhost:8000/redoc"