-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
296 lines (262 loc) · 9.52 KB
/
Makefile
File metadata and controls
296 lines (262 loc) · 9.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
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
.PHONY: help docker-up docker-down docker-stop docker-restart docker-logs \
docker-build docker-clean docker-prune \
up down stop restart logs build clean \
up-backend up-frontend logs-backend logs-frontend \
build-backend build-frontend shell-backend shell-frontend setup-hooks generate-api \
clean-node-modules \
up-localstack up-backend-localstack logs-localstack
# Default target - show help
.DEFAULT_GOAL := help
# ------------------------
# OS Detection
# ------------------------
OS := $(shell uname 2>/dev/null || echo Windows_NT)
ifeq ($(OS),Windows_NT)
DOCKER_COMPOSE = docker compose
WATCH_CMD = docker watch
else
DOCKER_COMPOSE = docker compose
WATCH_FLAG = --watch
endif
# ------------------------
# Colors
# ------------------------
RED := \033[0;31m
GREEN := \033[0;32m
YELLOW := \033[1;33m
BLUE := \033[0;34m
CYAN := \033[0;36m
NC := \033[0m
BOLD := \033[1m
# ------------------------
# Help
# ------------------------
help:
@echo "$(BOLD)SkillSpark - Docker Commands$(NC)"
@echo ""
@echo "$(BLUE)Main Commands:$(NC)"
@echo " make up - Start all services with hot reload"
@echo " make down - Stop and remove all containers"
@echo " make restart - Restart all services"
@echo " make logs - View logs from all services"
@echo " make build - Build all services"
@echo ""
@echo "$(BLUE)Individual Services:$(NC)"
@echo " make up-backend - Start only backend with hot reload"
@echo " make up-frontend - Start only frontend with hot reload"
@echo " make logs-backend - View backend logs"
@echo " make logs-frontend - View frontend logs"
@echo " make build-backend - Build only backend"
@echo " make build-frontend - Build only frontend"
@echo ""
@echo "$(BLUE)Container Management:$(NC)"
@echo " make stop - Stop all services (without removing)"
@echo " make shell-backend - Open shell in backend container"
@echo " make shell-frontend - Open shell in frontend container"
@echo " make ps - Show running containers"
@echo ""
@echo "$(BLUE)Cleanup:$(NC)"
@echo " make clean - Remove containers and volumes"
@echo " make prune - Remove all unused Docker resources"
@echo ""
@echo "$(BLUE)Dependencies:$(NC)"
@echo " make clean-node-modules - Remove all node_modules and reinstall dependencies"
@echo "$(BLUE)LocalStack (local AWS emulation):$(NC)"
@echo " make up-localstack - Start all services + LocalStack"
@echo " make up-backend-localstack - Start only backend + LocalStack"
@echo " make logs-localstack - View LocalStack logs"
@echo ""
ifeq ($(OS),Windows_NT)
@echo "$(YELLOW)Note: On Windows, hot reload uses 'docker watch' in a separate terminal$(NC)"
endif
# ------------------------
# Main Commands
# ------------------------
up:
@echo "$(BOLD)Starting all services...$(NC)"
ifeq ($(OS),Windows_NT)
@echo "$(YELLOW)On Windows: Starting containers. Run 'docker watch' in another terminal for hot reload.$(NC)"
@$(DOCKER_COMPOSE) up --build
else
@$(DOCKER_COMPOSE) up --build $(WATCH_FLAG)
endif
@sleep 2
@echo ""
@echo "$(GREEN)✓ Services started successfully!$(NC)"
@echo ""
@echo "$(BOLD)Access your application:$(NC)"
@echo " $(BLUE)Frontend:$(NC) http://localhost"
@echo " $(BLUE)Backend:$(NC) http://localhost:8080"
@echo ""
@echo "$(BOLD)Useful commands:$(NC)"
@echo " $(YELLOW)make logs$(NC) - View logs"
@echo " $(YELLOW)make down$(NC) - Stop services"
@echo " $(YELLOW)make restart$(NC) - Restart services"
@echo ""
down:
@echo "$(BOLD)Stopping all services...$(NC)"
@$(DOCKER_COMPOSE) down
@echo "$(GREEN)All services stopped$(NC)"
stop:
@echo "$(BOLD)Stopping all services (containers preserved)...$(NC)"
@$(DOCKER_COMPOSE) stop
@echo "$(GREEN)All services stopped$(NC)"
restart:
@echo "$(BOLD)Restarting all services...$(NC)"
@$(DOCKER_COMPOSE) restart
@echo "$(GREEN)All services restarted$(NC)"
logs:
@echo "$(BOLD)Viewing logs (Ctrl+C to exit)...$(NC)"
@$(DOCKER_COMPOSE) logs -f
build:
@echo "$(BOLD)Building all services...$(NC)"
@$(DOCKER_COMPOSE) build
@echo "$(GREEN)Build complete$(NC)"
ps:
@echo "$(BOLD)Running containers:$(NC)"
@$(DOCKER_COMPOSE) ps
# ------------------------
# Backend Commands
# ------------------------
up-backend:
@echo "$(BOLD)Starting backend service...$(NC)"
ifeq ($(OS),Windows_NT)
@echo "$(YELLOW)On Windows: Starting backend. Run 'docker watch' in another terminal for hot reload.$(NC)"
@$(DOCKER_COMPOSE) up --build backend
else
@$(DOCKER_COMPOSE) up --build $(WATCH_FLAG) backend
endif
logs-backend:
@echo "$(BOLD)Viewing backend logs (Ctrl+C to exit)...$(NC)"
@$(DOCKER_COMPOSE) logs -f backend
build-backend:
@echo "$(BOLD)Building backend...$(NC)"
@$(DOCKER_COMPOSE) build backend
@echo "$(GREEN)Backend build complete$(NC)"
shell-backend:
@echo "$(BOLD)Opening shell in backend container...$(NC)"
@$(DOCKER_COMPOSE) exec backend sh
restart-backend:
@echo "$(BOLD)Restarting backend...$(NC)"
@$(DOCKER_COMPOSE) restart backend
@echo "$(GREEN)Backend restarted$(NC)"
# ------------------------
# Frontend Commands
# ------------------------
up-frontend:
@echo "$(BOLD)Starting frontend service...$(NC)"
ifeq ($(OS),Windows_NT)
@echo "$(YELLOW)On Windows: Starting frontend. Run 'docker watch' in another terminal for hot reload.$(NC)"
@$(DOCKER_COMPOSE) up --build frontend
else
@$(DOCKER_COMPOSE) up --build $(WATCH_FLAG) frontend
endif
logs-frontend:
@echo "$(BOLD)Viewing frontend logs (Ctrl+C to exit)...$(NC)"
@$(DOCKER_COMPOSE) logs -f frontend
build-frontend:
@echo "$(BOLD)Building frontend...$(NC)"
@$(DOCKER_COMPOSE) build frontend
@echo "$(GREEN)Frontend build complete$(NC)"
shell-frontend:
@echo "$(BOLD)Opening shell in frontend container...$(NC)"
@$(DOCKER_COMPOSE) exec frontend sh
restart-frontend:
@echo "$(BOLD)Restarting frontend...$(NC)"
@$(DOCKER_COMPOSE) restart frontend
@echo "$(GREEN)Frontend restarted$(NC)"
# ------------------------
# Cleanup Commands
# ------------------------
clean:
@echo "$(BOLD)Removing all containers and volumes...$(NC)"
@$(DOCKER_COMPOSE) down -v
@echo "$(GREEN)Cleanup complete$(NC)"
prune:
@echo "$(BOLD)Removing all unused Docker resources...$(NC)"
@echo "$(YELLOW)This will remove:$(NC)"
@echo " - All stopped containers"
@echo " - All networks not used by containers"
@echo " - All dangling images"
@echo " - All build cache"
@echo ""
@docker system prune -af --volumes
@echo "$(GREEN)Docker pruned$(NC)"
# ------------------------
# Development Helpers
# ------------------------
rebuild:
@echo "$(BOLD)Rebuilding all services (no cache)...$(NC)"
@$(DOCKER_COMPOSE) build --no-cache
@echo "$(GREEN)Rebuild complete$(NC)"
rebuild-backend:
@echo "$(BOLD)Rebuilding backend (no cache)...$(NC)"
@$(DOCKER_COMPOSE) build --no-cache backend
@echo "$(GREEN)Backend rebuild complete$(NC)"
rebuild-frontend:
@echo "$(BOLD)Rebuilding frontend (no cache)...$(NC)"
@$(DOCKER_COMPOSE) build --no-cache frontend
@echo "$(GREEN)Frontend rebuild complete$(NC)"
# ------------------------
# Watch Helper (for Windows)
# ------------------------
watch:
ifeq ($(OS),Windows_NT)
@echo "$(BOLD)Starting Docker watch for hot reload...$(NC)"
@echo "$(YELLOW)Make sure containers are running with 'make up' first$(NC)"
@docker watch
else
@echo "$(YELLOW)Watch is built into 'make up' on Unix systems$(NC)"
@echo "Use 'make up' to start with hot reload enabled"
endif
setup-hooks:
@echo "Installing git hooks..."
@ln -sf ../../scripts/hooks/pre-commit .git/hooks/pre-commit
@echo "✅ Hooks installed!"
generate-api:
cd frontend/packages/api-client && bun run generate
clean-node-modules:
@echo "$(BOLD)Searching for and removing all node_modules folders...$(NC)"
@find . -type d -name "node_modules" -exec rm -rf {} + 2>/dev/null || true
@echo "$(GREEN)All node_modules folders removed$(NC)"
@echo ""
@echo "$(BOLD)Reinstalling dependencies in all locations...$(NC)"
@for dir in $$(find . -name "package.json" -not -path "*/node_modules/*" -exec dirname {} \;); do \
echo "$(BLUE)Installing in: $$dir$(NC)"; \
(cd "$$dir" && bun install) || true; \
done
@echo "$(GREEN)All dependencies reinstalled$(NC)"
# ------------------------
# LocalStack
# ------------------------
up-localstack:
@echo "$(BOLD)Building Lambda binary for LocalStack...$(NC)"
@docker run --rm \
-v "$(CURDIR)/infra/modules/main/lambda:/src:ro" \
-v "$(CURDIR)/scripts/build-lambda-local.sh:/build.sh:ro" \
-v "$(CURDIR)/infra/modules/main:/output" \
golang:1.24-alpine sh /build.sh
@echo "$(BOLD)Starting all services with LocalStack...$(NC)"
ifeq ($(OS),Windows_NT)
@$(DOCKER_COMPOSE) --profile localstack up --build
else
@$(DOCKER_COMPOSE) --profile localstack up --build $(WATCH_FLAG)
endif
up-backend-localstack:
@echo "$(BOLD)Cleaning up stale containers and networks...$(NC)"
@$(DOCKER_COMPOSE) --profile localstack down --remove-orphans 2>/dev/null || true
@echo "$(BOLD)Building Lambda binary for LocalStack...$(NC)"
@docker run --rm \
-v "$(CURDIR)/infra/modules/main/lambda:/src:ro" \
-v "$(CURDIR)/scripts/build-lambda-local.sh:/build.sh:ro" \
-v "$(CURDIR)/infra/modules/main:/output" \
golang:1.24-alpine sh /build.sh
@echo "$(BOLD)Starting backend + LocalStack...$(NC)"
ifeq ($(OS),Windows_NT)
@$(DOCKER_COMPOSE) --profile localstack up --build backend localstack
else
@$(DOCKER_COMPOSE) --profile localstack up --build $(WATCH_FLAG) backend localstack
endif
logs-localstack:
@echo "$(BOLD)Viewing LocalStack logs (Ctrl+C to exit)...$(NC)"
@$(DOCKER_COMPOSE) logs -f localstack