-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
328 lines (265 loc) · 12.4 KB
/
Copy pathMakefile
File metadata and controls
328 lines (265 loc) · 12.4 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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# Makefile for dbrest development lifecycle
# Provides convenient commands for building, testing, benchmarking, and running
.PHONY: help build build-release clean run run-release test test-unit test-integration test-all test-ignored test-sse-sqlite test-sse-pg bench bench-micro bench-integration bench-load fmt lint clippy check doc docs-build docs-serve docs-clean docs-install bump-version install-hooks
# Default target
.DEFAULT_GOAL := help
# Variables
CARGO := cargo
# Rancher Desktop uses a non-standard Docker socket path
DOCKER_HOST ?= unix://$(HOME)/.rd/docker.sock
export DOCKER_HOST
BINARY_NAME := dbrest
BENCH_DIR := benches
TEST_DIR := tests
DOCS_DIR := docs
MDBOOK := mdbook
# Colors for output
BLUE := \033[0;34m
GREEN := \033[0;32m
YELLOW := \033[0;33m
NC := \033[0m # No Color
##@ General
help: ## Display this help message
@echo "$(BLUE)dbrest Development Commands$(NC)"
@echo ""
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make $(BLUE)<target>$(NC)\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " $(BLUE)%-20s$(NC) %s\n", $$1, $$2 } /^##@/ { printf "\n$(GREEN)%s$(NC)\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Building
build: ## Build the project in debug mode
@echo "$(BLUE)Building dbrest...$(NC)"
$(CARGO) build
build-release: ## Build the project in release mode
@echo "$(BLUE)Building dbrest (release)...$(NC)"
$(CARGO) build --release
clean: ## Clean build artifacts
@echo "$(BLUE)Cleaning build artifacts...$(NC)"
$(CARGO) clean
##@ Running
run: build ## Run the server in debug mode
@echo "$(BLUE)Running dbrest (debug)...$(NC)"
$(CARGO) run
run-release: build-release ## Run the server in release mode
@echo "$(BLUE)Running dbrest (release)...$(NC)"
$(CARGO) run --release
##@ Testing
test: ## Run unit tests only (no Docker required)
@echo "$(BLUE)Running unit tests...$(NC)"
$(CARGO) test --lib --tests -- --skip ignored
test-unit: test ## Alias for test
test-integration: ## Run integration tests including SSE (requires Docker)
@echo "$(BLUE)Running integration tests including SSE (requires Docker)...$(NC)"
@if ! docker info > /dev/null 2>&1; then \
echo "$(YELLOW)Warning: Docker is not running. Integration tests require Docker.$(NC)"; \
exit 1; \
fi
$(CARGO) test --test sse_sqlite -- --test-threads=8
$(CARGO) test --test sse_integration -- --ignored --test-threads=8
$(CARGO) test --test '*' -- --ignored --test-threads=8
test-sse-sqlite: ## Run SSE integration tests (SQLite, no Docker required)
@echo "$(BLUE)Running SSE integration tests (SQLite)...$(NC)"
$(CARGO) test --test sse_sqlite -- --test-threads=8
test-sse-pg: ## Run SSE integration tests (PostgreSQL, requires Docker)
@echo "$(BLUE)Running SSE integration tests (PostgreSQL, requires Docker)...$(NC)"
@if ! docker info > /dev/null 2>&1; then \
echo "$(YELLOW)Warning: Docker is not running. SSE PG tests require Docker.$(NC)"; \
exit 1; \
fi
$(CARGO) test --test sse_integration -- --ignored --test-threads=8
test-all: ## Run all tests including Docker-dependent ones
@echo "$(BLUE)Running all tests (including Docker-dependent)...$(NC)"
@if ! docker info > /dev/null 2>&1; then \
echo "$(YELLOW)Warning: Docker is not running. Some tests require Docker.$(NC)"; \
fi
$(CARGO) test --all-features -- --include-ignored --test-threads=8
test-ignored: ## Run only ignored tests (Docker-dependent)
@echo "$(BLUE)Running ignored tests (Docker-dependent)...$(NC)"
@if ! docker info > /dev/null 2>&1; then \
echo "$(YELLOW)Warning: Docker is not running. Ignored tests require Docker.$(NC)"; \
exit 1; \
fi
$(CARGO) test --all-features -- --ignored --test-threads=8
test-parallel: ## Run tests in parallel (faster, but may have Docker conflicts)
@echo "$(BLUE)Running tests in parallel...$(NC)"
@if ! docker info > /dev/null 2>&1; then \
echo "$(YELLOW)Warning: Docker is not running. Some tests require Docker.$(NC)"; \
fi
$(CARGO) test --all-features -- --include-ignored
test-e2e: ## Run end-to-end tests in parallel with 8 threads (requires Docker)
@echo "$(BLUE)Running E2E tests in parallel with 8 threads (requires Docker)...$(NC)"
@if ! docker info > /dev/null 2>&1; then \
echo "$(YELLOW)Error: Docker is not running. E2E tests require Docker.$(NC)"; \
exit 1; \
fi
$(CARGO) test --test e2e_app -- --test-threads=8
test-e2e-serial: ## Run end-to-end tests serially (single-threaded, more stable)
@echo "$(BLUE)Running E2E tests serially (requires Docker)...$(NC)"
@if ! docker info > /dev/null 2>&1; then \
echo "$(YELLOW)Error: Docker is not running. E2E tests require Docker.$(NC)"; \
exit 1; \
fi
$(CARGO) test --test e2e_app -- --test-threads=1
test-e2e-computed: ## Run computed field E2E tests in parallel with 8 threads (requires Docker)
@echo "$(BLUE)Running computed field E2E tests in parallel (requires Docker)...$(NC)"
@if ! docker info > /dev/null 2>&1; then \
echo "$(YELLOW)Error: Docker is not running. E2E tests require Docker.$(NC)"; \
exit 1; \
fi
$(CARGO) test --test e2e_app e2e_computed_field -- --test-threads=8
test-e2e-computed-serial: ## Run computed field E2E tests serially (single-threaded)
@echo "$(BLUE)Running computed field E2E tests serially (requires Docker)...$(NC)"
@if ! docker info > /dev/null 2>&1; then \
echo "$(YELLOW)Error: Docker is not running. E2E tests require Docker.$(NC)"; \
exit 1; \
fi
$(CARGO) test --test e2e_app e2e_computed_field -- --test-threads=1
##@ Benchmarking
bench: ## Run all benchmarks
@echo "$(BLUE)Running all benchmarks...$(NC)"
$(CARGO) bench --all
bench-micro: ## Run micro-benchmarks only
@echo "$(BLUE)Running micro-benchmarks...$(NC)"
$(CARGO) bench --bench micro_benchmarks
bench-integration: ## Run integration benchmarks (requires running server)
@echo "$(BLUE)Running integration benchmarks (requires server on localhost:3000)...$(NC)"
@if ! curl -s http://localhost:3000/ > /dev/null 2>&1; then \
echo "$(YELLOW)Warning: Server not running on localhost:3000$(NC)"; \
echo "$(YELLOW)Start server with: make run-release$(NC)"; \
fi
$(CARGO) bench --bench integration_benchmarks
bench-load: ## Run load tests (requires running server)
@echo "$(BLUE)Running load tests (requires server on localhost:3000)...$(NC)"
@if ! curl -s http://localhost:3000/ > /dev/null 2>&1; then \
echo "$(YELLOW)Warning: Server not running on localhost:3000$(NC)"; \
echo "$(YELLOW)Start server with: make run-release$(NC)"; \
fi
$(CARGO) bench --bench load_tester
bench-setup: ## Setup benchmark database (load schema and seed data)
@echo "$(BLUE)Setting up benchmark database...$(NC)"
@if ! docker info > /dev/null 2>&1; then \
echo "$(YELLOW)Warning: Docker is not running.$(NC)"; \
exit 1; \
fi
@echo "$(BLUE)Loading schema...$(NC)"
@psql -h localhost -U postgres -f $(TEST_DIR)/fixtures/schema.sql || \
echo "$(YELLOW)Note: If psql fails, ensure PostgreSQL is running and accessible$(NC)"
@echo "$(BLUE)Loading seed data...$(NC)"
@psql -h localhost -U postgres -f $(BENCH_DIR)/fixtures/seed_data.sql || \
echo "$(YELLOW)Note: If psql fails, ensure PostgreSQL is running and accessible$(NC)"
bench-docker-build: ## Build dbrest Docker image for benchmarks
@echo "$(BLUE)Building dbrest Docker image...$(NC)"
@if ! docker info > /dev/null 2>&1; then \
echo "$(YELLOW)Error: Docker is not running.$(NC)"; \
exit 1; \
fi
docker compose -f docker-compose.bench.yml --env-file .env.bench build
bench-docker-up: bench-docker-build ## Start Docker Compose services for benchmarks
@echo "$(BLUE)Starting Docker Compose services...$(NC)"
@if ! docker info > /dev/null 2>&1; then \
echo "$(YELLOW)Error: Docker is not running.$(NC)"; \
exit 1; \
fi
docker compose -f docker-compose.bench.yml --env-file .env.bench up -d
@echo "$(BLUE)Waiting for services to be healthy...$(NC)"
@timeout=60; \
while [ $$timeout -gt 0 ]; do \
if curl -s http://localhost:3000/ > /dev/null 2>&1; then \
echo "$(GREEN)Services are ready!$(NC)"; \
break; \
fi; \
sleep 2; \
timeout=$$((timeout - 2)); \
done; \
if [ $$timeout -le 0 ]; then \
echo "$(YELLOW)Warning: Services may not be fully ready$(NC)"; \
fi
bench-docker-down: ## Stop and remove Docker Compose services
@echo "$(BLUE)Stopping Docker Compose services...$(NC)"
@if ! docker info > /dev/null 2>&1; then \
echo "$(YELLOW)Warning: Docker is not running.$(NC)"; \
exit 0; \
fi
docker compose -f docker-compose.bench.yml --env-file .env.bench down
bench-docker-logs: ## View logs from benchmark containers
@if ! docker info > /dev/null 2>&1; then \
echo "$(YELLOW)Error: Docker is not running.$(NC)"; \
exit 1; \
fi
docker compose -f docker-compose.bench.yml --env-file .env.bench logs -f
bench-docker: bench-docker-up ## Full Docker benchmark workflow: build, start, run benchmarks, cleanup
@echo "$(BLUE)Running benchmarks against Docker services...$(NC)"
@set -e; \
$(CARGO) bench --bench integration_benchmarks --bench load_tester; \
bench_exit=$$?; \
make bench-docker-down; \
exit $$bench_exit
##@ Code Quality
fmt: ## Format code with rustfmt
@echo "$(BLUE)Formatting code...$(NC)"
$(CARGO) fmt
fmt-check: ## Check code formatting without modifying files
@echo "$(BLUE)Checking code formatting...$(NC)"
$(CARGO) fmt -- --check
lint: clippy ## Alias for clippy
clippy: ## Run clippy linter
@echo "$(BLUE)Running clippy...$(NC)"
$(CARGO) clippy --all-targets --all-features -- -D warnings
check: ## Check code without building
@echo "$(BLUE)Checking code...$(NC)"
$(CARGO) check --all-targets
check-all: check clippy fmt-check ## Run all checks (check + clippy + fmt-check)
##@ Documentation
doc: ## Generate Rust API documentation (cargo doc)
@echo "$(BLUE)Generating documentation...$(NC)"
$(CARGO) doc --no-deps --open
doc-build: ## Build Rust API documentation without opening
@echo "$(BLUE)Building documentation...$(NC)"
$(CARGO) doc --no-deps
##@ User Documentation (mdbook)
docs-build: ## Build user documentation (mdbook) into docs/book
@echo "$(BLUE)Building user documentation...$(NC)"
@command -v $(MDBOOK) >/dev/null 2>&1 || { echo "$(YELLOW)mdbook not found. Install with: make docs-install$(NC)"; exit 1; }
$(MDBOOK) build $(DOCS_DIR)
docs-serve: ## Serve user documentation for local preview (http://localhost:3000)
@echo "$(BLUE)Serving user documentation at http://localhost:3000$(NC)"
@command -v $(MDBOOK) >/dev/null 2>&1 || { echo "$(YELLOW)mdbook not found. Install with: make docs-install$(NC)"; exit 1; }
$(MDBOOK) serve $(DOCS_DIR)
docs-clean: ## Remove built user documentation (docs/book)
@echo "$(BLUE)Cleaning built documentation...$(NC)"
@rm -rf $(DOCS_DIR)/book
docs-install: ## Install mdbook (cargo install mdbook)
@echo "$(BLUE)Installing mdbook...$(NC)"
$(CARGO) install mdbook
##@ Version & Hooks
bump-version: ## Bump version across all crates (usage: make bump-version V=0.2.0)
@if [ -z "$(V)" ]; then \
echo "$(YELLOW)Usage: make bump-version V=0.2.0$(NC)"; \
exit 1; \
fi
@echo "$(BLUE)Bumping version to $(V) across all crates...$(NC)"
@cargo set-version $(V)
@echo "$(GREEN)Version bumped to $(V) in all Cargo.toml files$(NC)"
@git add Cargo.toml crates/dbrest-core/Cargo.toml crates/dbrest-postgres/Cargo.toml crates/dbrest-sqlite/Cargo.toml
@git commit -m "release: v$(V)"
@git tag v$(V)
@echo "$(GREEN)Committed and tagged v$(V)$(NC)"
@read -p "Push commit and tag to origin? [y/N] " ans && [ "$$ans" = "y" ] && git push origin main --tags || echo "$(YELLOW)Skipped push. Run manually: git push origin main --tags$(NC)"
install-hooks: ## Install git hooks from .githooks/
@echo "$(BLUE)Installing git hooks...$(NC)"
git config core.hooksPath .githooks
@echo "$(GREEN)Git hooks installed$(NC)"
##@ Development Workflow
dev-setup: ## Setup development environment (check Docker, install deps)
@echo "$(BLUE)Setting up development environment...$(NC)"
@if ! docker info > /dev/null 2>&1; then \
echo "$(YELLOW)Warning: Docker is not running. Some tests require Docker.$(NC)"; \
else \
echo "$(GREEN)Docker is running$(NC)"; \
fi
@echo "$(BLUE)Checking Rust toolchain...$(NC)"
@rustc --version || (echo "$(YELLOW)Error: Rust is not installed$(NC)" && exit 1)
@echo "$(GREEN)Development environment ready$(NC)"
ci: check fmt-check clippy test-all ## Run CI checks (check, format, lint, test)
pre-commit: fmt check clippy test ## Run pre-commit checks (format, check, lint, test unit)
##@ Quick Commands
quick-test: build test ## Quick test cycle (build + test)
quick-bench: build-release bench-micro ## Quick benchmark cycle (build release + micro-bench)
all: clean build-release test-all bench-micro ## Run everything (clean, build, test, benchmark)