-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
193 lines (158 loc) · 6.52 KB
/
Makefile
File metadata and controls
193 lines (158 loc) · 6.52 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
.PHONY: help docker-up docker-down docker-restart docker-logs docker-clean docker-reset db-connect db-backup db-restore playwright-test
# Docker Compose file and env file
COMPOSE_FILE := docker-compose.yml
ENV_FILE := .env.docker.local
# Colors for output
BLUE := \033[0;34m
GREEN := \033[0;32m
YELLOW := \033[1;33m
RED := \033[0;31m
NC := \033[0m # No Color
help: ## Show this help message
@echo "$(BLUE)JudgeFinder Docker Commands$(NC)"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-20s$(NC) %s\n", $$1, $$2}'
@echo ""
# Setup and initialization
setup: ## Initial setup - copy env file
@echo "$(BLUE)Setting up environment...$(NC)"
@if [ ! -f $(ENV_FILE) ]; then \
cp .env.docker $(ENV_FILE); \
echo "$(GREEN)Created $(ENV_FILE) from template$(NC)"; \
echo "$(YELLOW)Please edit $(ENV_FILE) and update passwords!$(NC)"; \
else \
echo "$(YELLOW)$(ENV_FILE) already exists$(NC)"; \
fi
# Docker operations
docker-up: ## Start all Docker services
@echo "$(BLUE)Starting Docker services...$(NC)"
@docker-compose --env-file $(ENV_FILE) up -d
@echo "$(GREEN)Services started!$(NC)"
@echo "$(BLUE)Supabase Studio:$(NC) http://localhost:54323"
@echo "$(BLUE)API Gateway:$(NC) http://localhost:54321"
@echo "$(BLUE)PostgreSQL:$(NC) localhost:54322"
docker-down: ## Stop all Docker services
@echo "$(BLUE)Stopping Docker services...$(NC)"
@docker-compose down
@echo "$(GREEN)Services stopped$(NC)"
docker-restart: ## Restart all Docker services
@echo "$(BLUE)Restarting Docker services...$(NC)"
@docker-compose --env-file $(ENV_FILE) restart
@echo "$(GREEN)Services restarted$(NC)"
docker-logs: ## View logs from all services
@docker-compose logs -f
docker-logs-db: ## View PostgreSQL logs
@docker-compose logs -f db
docker-logs-auth: ## View Auth service logs
@docker-compose logs -f auth
docker-logs-rest: ## View PostgREST logs
@docker-compose logs -f rest
docker-logs-storage: ## View Storage service logs
@docker-compose logs -f storage
docker-ps: ## Show status of all services
@docker-compose ps
docker-clean: ## Remove stopped containers and networks
@echo "$(BLUE)Cleaning up Docker resources...$(NC)"
@docker-compose down
@docker system prune -f
@echo "$(GREEN)Cleanup complete$(NC)"
docker-reset: ## DANGER: Reset everything (deletes all data)
@echo "$(RED)WARNING: This will delete ALL data!$(NC)"
@read -p "Are you sure? (yes/no): " confirm; \
if [ "$$confirm" = "yes" ]; then \
echo "$(BLUE)Resetting Docker environment...$(NC)"; \
docker-compose down -v; \
docker volume rm -f judgefinder-db-data judgefinder-storage-data judgefinder-logs-data judgefinder-edge-functions-cache judgefinder-playwright-cache 2>/dev/null || true; \
echo "$(GREEN)Reset complete$(NC)"; \
else \
echo "$(YELLOW)Reset cancelled$(NC)"; \
fi
# Database operations
db-connect: ## Connect to PostgreSQL via psql
@docker exec -it supabase-db psql -U postgres -d postgres
db-status: ## Check database health
@docker exec supabase-db pg_isready -U postgres
db-backup: ## Backup database to backup.sql
@echo "$(BLUE)Backing up database...$(NC)"
@docker exec supabase-db pg_dump -U postgres postgres > backup-$$(date +%Y%m%d-%H%M%S).sql
@echo "$(GREEN)Backup complete$(NC)"
db-restore: ## Restore database from backup.sql (provide file with FILE=backup.sql)
@if [ -z "$(FILE)" ]; then \
echo "$(RED)Error: Please provide backup file: make db-restore FILE=backup.sql$(NC)"; \
exit 1; \
fi
@echo "$(BLUE)Restoring database from $(FILE)...$(NC)"
@docker exec -i supabase-db psql -U postgres -d postgres < $(FILE)
@echo "$(GREEN)Restore complete$(NC)"
db-migrate: ## Apply pending migrations
@echo "$(BLUE)Applying migrations...$(NC)"
@npx supabase db push
@echo "$(GREEN)Migrations applied$(NC)"
db-reset-migrations: ## Reset database and reapply all migrations
@echo "$(RED)WARNING: This will reset the database!$(NC)"
@read -p "Are you sure? (yes/no): " confirm; \
if [ "$$confirm" = "yes" ]; then \
echo "$(BLUE)Resetting database...$(NC)"; \
docker-compose down db; \
docker volume rm -f judgefinder-db-data; \
docker-compose --env-file $(ENV_FILE) up -d db; \
sleep 10; \
npx supabase db push; \
echo "$(GREEN)Database reset complete$(NC)"; \
else \
echo "$(YELLOW)Reset cancelled$(NC)"; \
fi
# Playwright testing
playwright-install: ## Install Playwright in container
@echo "$(BLUE)Installing Playwright...$(NC)"
@docker-compose exec playwright npm install
@docker-compose exec playwright npx playwright install
@echo "$(GREEN)Playwright installed$(NC)"
playwright-test: ## Run E2E tests in Playwright container
@echo "$(BLUE)Running E2E tests...$(NC)"
@docker-compose exec playwright npm run test:e2e
playwright-test-ui: ## Run Playwright tests with UI
@echo "$(BLUE)Running E2E tests with UI...$(NC)"
@docker-compose exec playwright npx playwright test --ui
playwright-shell: ## Open shell in Playwright container
@docker-compose exec playwright /bin/bash
# Studio operations
studio-open: ## Open Supabase Studio in browser
@echo "$(BLUE)Opening Supabase Studio...$(NC)"
@open http://localhost:54323 || xdg-open http://localhost:54323 || echo "$(YELLOW)Please open http://localhost:54323 manually$(NC)"
# Development workflow
dev: docker-up ## Start Docker services and Next.js dev server
@echo "$(BLUE)Starting development environment...$(NC)"
@sleep 5
@npm run dev
dev-logs: ## View logs from all services and Next.js
@docker-compose logs -f & npm run dev
# Health check
health: ## Check health of all services
@echo "$(BLUE)Checking service health...$(NC)"
@echo "$(YELLOW)Kong API Gateway:$(NC)"
@curl -s http://localhost:54321/health || echo "$(RED)Not responding$(NC)"
@echo ""
@echo "$(YELLOW)PostgreSQL:$(NC)"
@docker exec supabase-db pg_isready -U postgres || echo "$(RED)Not ready$(NC)"
@echo ""
@echo "$(YELLOW)Studio:$(NC)"
@curl -s -o /dev/null -w "%%{http_code}" http://localhost:54323 || echo "$(RED)Not responding$(NC)"
@echo ""
# Volume management
volumes-list: ## List all Docker volumes
@docker volume ls | grep judgefinder
volumes-inspect: ## Inspect volume usage
@docker system df -v | grep judgefinder
# Generate keys (useful for production-like setup)
generate-jwt: ## Generate a new JWT secret
@echo "$(BLUE)Generated JWT Secret:$(NC)"
@openssl rand -base64 32
generate-password: ## Generate a strong password
@echo "$(BLUE)Generated Password:$(NC)"
@openssl rand -base64 24
# Monitoring
stats: ## Show Docker container resource usage
@docker stats --no-stream $$(docker-compose ps -q)
top: ## Show running processes in containers
@docker-compose top