-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
284 lines (216 loc) · 8.55 KB
/
Copy pathMakefile
File metadata and controls
284 lines (216 loc) · 8.55 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
# Makefile — orchestration layer for node-ts-starter (multilingual: Node + Spring).
#
# Run `make` or `make help` for the full list of targets.
SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c
.ONESHELL:
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
# ---------- Config ----------
COMPOSE := docker compose
COMPOSE_DEV := $(COMPOSE) -f docker-compose.yml -f docker-compose.dev.yml
COMPOSE_OBS := $(COMPOSE) -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.obs.yml
DOCKER_BUILDKIT ?= 1
export DOCKER_BUILDKIT
NODE_API_DIR := services/node-api
SPRING_API_DIR := services/spring-api
# JAVA_HOME for Maven (Spring targets only — does NOT touch the user's shell
# JAVA_HOME for other tools). On macOS, resolves Java 21 via java_home -v 21
# (the canonical macOS way). On Linux, set SPRING_JAVA_HOME explicitly if
# your distro doesn't provide /usr/libexec/java_home.
SPRING_JAVA_HOME ?= $(shell /usr/libexec/java_home -v 21 2>/dev/null)
SPRING_MVN := $(if $(SPRING_JAVA_HOME),JAVA_HOME=$(SPRING_JAVA_HOME) ,)mvn
# ---------- Help (default) ----------
.DEFAULT_GOAL := help
.PHONY: help
help: ## Show this help.
@awk 'BEGIN {FS = ":.*?## "; printf "\nUsage: make <target>\n\nTargets:\n"} \
/^[a-zA-Z_-]+:.*?## / { printf " \033[36m%-22s\033[0m %s\n", $$1, $$2 } \
/^## ?---/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 4) }' \
$(MAKEFILE_LIST)
@echo
## --- Setup ---
.PHONY: install
install: install-node-api install-web ## Install all node-side dependencies (node-api + web).
.PHONY: install-node-api
install-node-api: ## Install node-api dependencies.
cd $(NODE_API_DIR) && npm install
.PHONY: install-web
install-web: ## Install frontend dependencies.
cd web && npm install
## --- Local dev (no docker) ---
.PHONY: dev-node-api
dev-node-api: ## Run node-api dev server with --watch (port 3000).
cd $(NODE_API_DIR) && npm run dev
.PHONY: dev-spring-api
dev-spring-api: ## Run spring-api dev server (port 8080).
cd $(SPRING_API_DIR) && $(SPRING_MVN) spring-boot:run
.PHONY: dev-web
dev-web: ## Run Vite dev server (port 5173).
cd web && npm run dev
.PHONY: dev
dev: ## Run node-api + web concurrently (use two terminals for clean output).
$(MAKE) -j 2 dev-node-api dev-web
## --- Quality: Node-API ---
.PHONY: node-typecheck
node-typecheck: ## Type-check node-api + web.
# Subshells so the second `cd` is relative to the original CWD even
# under `.ONESHELL` (which keeps all recipe lines in one shell).
( cd $(NODE_API_DIR) && npm run typecheck )
( cd web && npm run typecheck )
.PHONY: node-lint
node-lint: ## Lint with Biome across the repo (no writes).
npx --prefix $(NODE_API_DIR) biome check .
.PHONY: node-lint-fix
node-lint-fix: ## Lint and apply safe fixes.
npx --prefix $(NODE_API_DIR) biome check --write .
.PHONY: node-format
node-format: ## Format with Biome.
npx --prefix $(NODE_API_DIR) biome format --write .
.PHONY: node-test
node-test: ## Run node-api test suite.
cd $(NODE_API_DIR) && npm test
.PHONY: node-test-watch
node-test-watch: ## Run node-api tests in watch mode.
cd $(NODE_API_DIR) && npm run test:watch
.PHONY: node-test-coverage
node-test-coverage: ## Run node-api tests with coverage report.
cd $(NODE_API_DIR) && npm run test:coverage
.PHONY: node-test-postgres
node-test-postgres: ## Run node-api tests with TEST_DATABASE_URL pointing at local pg (must be running).
cd $(NODE_API_DIR) && TEST_DATABASE_URL=postgresql://postgres:postgres@localhost:$${DB_PORT:-55432}/app npm test
.PHONY: node-migrate
node-migrate: ## Apply pending Postgres migrations from node-api (uses DATABASE_URL from .env).
cd $(NODE_API_DIR) && npm run migrate
.PHONY: node-check
node-check: node-lint node-typecheck node-test ## Run all node-api quality gates.
## --- Quality: Spring-API ---
.PHONY: spring-test
spring-test: ## Run spring-api tests.
cd $(SPRING_API_DIR) && $(SPRING_MVN) test
.PHONY: spring-package
spring-package: ## Build spring-api jar (skip tests).
cd $(SPRING_API_DIR) && $(SPRING_MVN) -DskipTests package
.PHONY: spring-check
spring-check: ## Run spring-api full verify (compile + tests + checks).
cd $(SPRING_API_DIR) && $(SPRING_MVN) verify
## --- Combined ---
.PHONY: check
check: node-check spring-check ## Run all quality gates across both services.
.PHONY: ci ci-web-build
ci: check ci-web-build build ## Reproduce CI locally: check + web build + docker build.
ci-web-build:
cd web && npm run build
## --- Docker ---
.PHONY: build
build: ## Build all images (production).
$(COMPOSE) build
.PHONY: build-node-api
build-node-api: ## Build only the node-api image.
$(COMPOSE) build node-api
.PHONY: build-spring-api
build-spring-api: ## Build only the spring-api image.
$(COMPOSE) build spring-api
.PHONY: build-web
build-web: ## Build only the web image.
$(COMPOSE) build web
API_PORT ?= 3000
SPRING_API_PORT ?= 8080
WEB_PORT ?= 8081
export API_PORT SPRING_API_PORT WEB_PORT
.PHONY: up
up: ## Start the production stack in background (override ports via API_PORT, SPRING_API_PORT, WEB_PORT).
$(COMPOSE) up -d --remove-orphans
@echo
@echo " node-api: http://localhost:$(API_PORT)/health"
@echo " spring-api: http://localhost:$(SPRING_API_PORT)/actuator/health"
@echo " web: http://localhost:$(WEB_PORT)/"
@echo
.PHONY: up-fg
up-fg: ## Start the production stack in the foreground.
$(COMPOSE) up --remove-orphans
.PHONY: up-dev
up-dev: ## Start the stack with dev overrides (Vite on :5173, node-api with --watch).
$(COMPOSE_DEV) up --remove-orphans
.PHONY: obs-up
obs-up: ## Start dev stack + observability (Prometheus :9090, Tempo :3200, Grafana :3001).
$(COMPOSE_OBS) up -d --remove-orphans
@echo
@echo " node-api: http://localhost:3000/health"
@echo " spring-api: http://localhost:8080/actuator/health"
@echo " web: http://localhost:5173/"
@echo " Grafana: http://localhost:3001/"
@echo " Prometheus: http://localhost:9090/"
@echo " Tempo API: http://localhost:3200/ready"
@echo
.PHONY: obs-down
obs-down: ## Stop the observability stack (preserves volumes).
$(COMPOSE_OBS) down
.PHONY: obs-clean
obs-clean: ## Stop and wipe observability volumes (loses all metric/trace history).
$(COMPOSE_OBS) down -v
.PHONY: obs-logs
obs-logs: ## Tail logs from the observability services.
$(COMPOSE_OBS) logs -f --tail=100 prometheus tempo grafana
.PHONY: down
down: ## Stop the stack (preserves volumes).
$(COMPOSE) down
.PHONY: restart
restart: down up ## Restart the stack.
.PHONY: ps
ps: ## Show running services.
$(COMPOSE) ps
.PHONY: logs
logs: ## Tail logs from all services.
$(COMPOSE) logs -f --tail=100
.PHONY: logs-node-api
logs-node-api: ## Tail node-api logs.
$(COMPOSE) logs -f --tail=100 node-api
.PHONY: logs-spring-api
logs-spring-api: ## Tail spring-api logs.
$(COMPOSE) logs -f --tail=100 spring-api
.PHONY: logs-web
logs-web: ## Tail web logs.
$(COMPOSE) logs -f --tail=100 web
.PHONY: shell-node-api
shell-node-api: ## Open a shell inside the node-api container.
$(COMPOSE) exec node-api sh
.PHONY: shell-spring-api
shell-spring-api: ## Open a shell inside the spring-api container.
$(COMPOSE) exec spring-api sh
.PHONY: shell-web
shell-web: ## Open a shell inside the web container.
$(COMPOSE) exec web sh
.PHONY: db-up
db-up: ## Start ONLY the local Postgres dev container (for running tests/migrations).
$(COMPOSE_DEV) up -d db
@echo " postgres: postgresql://postgres:postgres@localhost:$${DB_PORT:-55432}/app"
.PHONY: db-down
db-down: ## Stop the local Postgres dev container.
$(COMPOSE_DEV) stop db
$(COMPOSE_DEV) rm -f db
.PHONY: db-shell
db-shell: ## Open a psql shell into the local Postgres dev container.
$(COMPOSE_DEV) exec db psql -U postgres -d app
.PHONY: smoke
smoke: ## Smoke-test the running stack (both apis + web index).
@echo "→ node-api health (port $(API_PORT)):"
@curl -fsS "http://localhost:$(API_PORT)/health" && echo
@echo "→ spring-api health (port $(SPRING_API_PORT)):"
@curl -fsS "http://localhost:$(SPRING_API_PORT)/actuator/health" && echo
@echo "→ web index (port $(WEB_PORT)):"
@curl -fsSI "http://localhost:$(WEB_PORT)/" | head -1
## --- Cleanup ---
.PHONY: clean
clean: ## Stop stack and remove containers + named volumes + local images.
$(COMPOSE) down -v --rmi local
.PHONY: clean-deps
clean-deps: ## Remove all node_modules.
rm -rf $(NODE_API_DIR)/node_modules web/node_modules node_modules
.PHONY: clean-spring
clean-spring: ## Remove Spring Maven target/ output.
cd $(SPRING_API_DIR) && $(SPRING_MVN) clean
.PHONY: clean-all
clean-all: clean clean-deps clean-spring ## Full reset: containers, volumes, images, node_modules, Maven target.
rm -rf web/dist $(NODE_API_DIR)/coverage