-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
210 lines (157 loc) · 6.51 KB
/
Makefile
File metadata and controls
210 lines (157 loc) · 6.51 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
# pgSentinel Makefile
# ===================
# Convenient commands for development and deployment
.PHONY: help install dev build start stop restart logs clean test lint format
# Default target
.DEFAULT_GOAL := help
# Colors for output
BLUE := \033[0;34m
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
NC := \033[0m # No Color
##@ General
help: ## Display this help message
@echo "$(GREEN)pgSentinel - Makefile Commands$(NC)"
@echo ""
@awk 'BEGIN {FS = ":.*##"; printf "Usage: make $(BLUE)<target>$(NC)\n\n"} /^[a-zA-Z_-]+:.*?##/ { printf " $(BLUE)%-15s$(NC) %s\n", $$1, $$2 } /^##@/ { printf "\n$(YELLOW)%s$(NC)\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
install: ## Install all dependencies
@echo "$(BLUE)Installing backend dependencies...$(NC)"
cd backend && python3 -m venv venv && . venv/bin/activate && pip install -r requirements.txt
@echo "$(BLUE)Installing frontend dependencies...$(NC)"
cd frontend && npm install
@echo "$(GREEN)✓ All dependencies installed$(NC)"
dev: ## Start development environment
@echo "$(BLUE)Starting development environment...$(NC)"
docker-compose -f docker-compose.dev.yml up
dev-backend: ## Start backend only in dev mode
@echo "$(BLUE)Starting backend in development mode...$(NC)"
cd backend && . venv/bin/activate && uvicorn main:app --reload --host 0.0.0.0 --port 8000
dev-frontend: ## Start frontend only in dev mode
@echo "$(BLUE)Starting frontend in development mode...$(NC)"
cd frontend && npm run dev
##@ Docker Operations
build: ## Build all Docker images
@echo "$(BLUE)Building Docker images...$(NC)"
docker-compose build
@echo "$(GREEN)✓ Build complete$(NC)"
start: ## Start all services
@echo "$(BLUE)Starting all services...$(NC)"
docker-compose up -d
@echo "$(GREEN)✓ Services started$(NC)"
@echo ""
@echo "Access points:"
@echo " Dashboard: http://localhost:3000"
@echo " API Docs: http://localhost:8000/docs"
@echo " Prometheus: http://localhost:9090"
@echo " Grafana: http://localhost:3001"
stop: ## Stop all services
@echo "$(YELLOW)Stopping all services...$(NC)"
docker-compose down
@echo "$(GREEN)✓ Services stopped$(NC)"
restart: stop start ## Restart all services
logs: ## View logs from all services
docker-compose logs -f
logs-backend: ## View backend logs
docker-compose logs -f backend
logs-frontend: ## View frontend logs
docker-compose logs -f frontend
ps: ## Show running containers
@docker-compose ps
##@ Database
db-shell: ## Open PostgreSQL shell
@docker-compose exec postgres-primary psql -U postgres -d pgsentinel
db-backup: ## Backup database
@echo "$(BLUE)Creating database backup...$(NC)"
@docker-compose exec -T postgres-primary pg_dump -U postgres pgsentinel > backup_$$(date +%Y%m%d_%H%M%S).sql
@echo "$(GREEN)✓ Backup created$(NC)"
db-restore: ## Restore database from backup (Usage: make db-restore FILE=backup.sql)
@echo "$(BLUE)Restoring database...$(NC)"
@docker-compose exec -T postgres-primary psql -U postgres pgsentinel < $(FILE)
@echo "$(GREEN)✓ Database restored$(NC)"
##@ Testing
test: ## Run all tests
@echo "$(BLUE)Running backend tests...$(NC)"
cd backend && . venv/bin/activate && pytest
@echo "$(BLUE)Running frontend tests...$(NC)"
cd frontend && npm test
test-backend: ## Run backend tests only
cd backend && . venv/bin/activate && pytest
test-frontend: ## Run frontend tests only
cd frontend && npm test
test-e2e: ## Run end-to-end tests
cd frontend && npm run test:e2e
##@ Code Quality
lint: ## Run linters
@echo "$(BLUE)Linting backend...$(NC)"
cd backend && . venv/bin/activate && ruff check .
@echo "$(BLUE)Linting frontend...$(NC)"
cd frontend && npm run lint
lint-fix: ## Fix linting issues
@echo "$(BLUE)Fixing backend linting issues...$(NC)"
cd backend && . venv/bin/activate && ruff check --fix .
@echo "$(BLUE)Fixing frontend linting issues...$(NC)"
cd frontend && npm run lint --fix
format: ## Format code
@echo "$(BLUE)Formatting backend code...$(NC)"
cd backend && . venv/bin/activate && black .
@echo "$(BLUE)Formatting frontend code...$(NC)"
cd frontend && npm run format
type-check: ## Run type checking
@echo "$(BLUE)Type checking frontend...$(NC)"
cd frontend && npm run type-check
##@ Monitoring
prometheus: ## Open Prometheus UI
@open http://localhost:9090 || xdg-open http://localhost:9090
grafana: ## Open Grafana UI
@open http://localhost:3001 || xdg-open http://localhost:3001
metrics: ## View current metrics
@curl -s http://localhost:8000/metrics | head -50
##@ Cleanup
clean: ## Remove containers and volumes
@echo "$(YELLOW)Removing containers and volumes...$(NC)"
docker-compose down -v
@echo "$(GREEN)✓ Cleanup complete$(NC)"
clean-all: clean ## Remove everything including images
@echo "$(YELLOW)Removing images...$(NC)"
docker-compose down -v --rmi all
@echo "$(GREEN)✓ Full cleanup complete$(NC)"
prune: ## Prune Docker system
@echo "$(YELLOW)Pruning Docker system...$(NC)"
docker system prune -af
@echo "$(GREEN)✓ System pruned$(NC)"
##@ Production
deploy: ## Deploy to production
@echo "$(BLUE)Deploying to production...$(NC)"
docker-compose -f docker-compose.prod.yml up -d --build
@echo "$(GREEN)✓ Deployment complete$(NC)"
scale-backend: ## Scale backend workers (Usage: make scale-backend N=4)
@docker-compose up -d --scale backend=$(N)
@echo "$(GREEN)✓ Backend scaled to $(N) instances$(NC)"
health: ## Check health of all services
@echo "$(BLUE)Checking service health...$(NC)"
@curl -s http://localhost:8000/health && echo "" || echo "$(RED)Backend unhealthy$(NC)"
@curl -s http://localhost:3000 > /dev/null && echo "$(GREEN)Frontend healthy$(NC)" || echo "$(RED)Frontend unhealthy$(NC)"
@curl -s http://localhost:9090/-/healthy > /dev/null && echo "$(GREEN)Prometheus healthy$(NC)" || echo "$(RED)Prometheus unhealthy$(NC)"
##@ Documentation
docs: ## Generate API documentation
@echo "$(BLUE)API documentation available at:$(NC)"
@echo " http://localhost:8000/docs"
serve-docs: ## Serve documentation locally
@cd docs && python3 -m http.server 8080
##@ Quick Actions
quick-start: build start logs ## Quick start everything
status: ## Show status of all services
@echo "$(BLUE)Service Status:$(NC)"
@docker-compose ps
@echo ""
@echo "$(BLUE)Resource Usage:$(NC)"
@docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}"
backup-all: db-backup ## Backup everything
@echo "$(BLUE)Creating full backup...$(NC)"
@tar -czf backup_full_$$(date +%Y%m%d_%H%M%S).tar.gz \
monitoring/grafana/dashboards \
monitoring/prometheus/rules \
docker-compose.yml
@echo "$(GREEN)✓ Full backup created$(NC)"