-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
197 lines (146 loc) · 7.1 KB
/
Makefile
File metadata and controls
197 lines (146 loc) · 7.1 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
# CacheGrid Makefile
BINARY_NAME := cachegrid
BUILD_DIR := ./build
CMD_DIR := ./cmd/cachegrid
DOCKER_IMAGE := cachegrid
DOCKER_TAG := latest
# Go settings
GOFLAGS := -trimpath
LDFLAGS := -s -w
.PHONY: all build run run-disk test test-verbose test-race bench lint fmt vet clean \
docker-build docker-run docker-compose-up docker-compose-down help \
test-features test-cluster test-disk test-perf test-scripts
## ─── Build ──────────────────────────────────────────────
all: test build ## Run tests and build
build: ## Build the cachegrid binary
@mkdir -p $(BUILD_DIR)
go build $(GOFLAGS) -ldflags '$(LDFLAGS)' -o $(BUILD_DIR)/$(BINARY_NAME) $(CMD_DIR)
@echo "Built $(BUILD_DIR)/$(BINARY_NAME)"
install: ## Install cachegrid to GOPATH/bin
go install $(GOFLAGS) -ldflags '$(LDFLAGS)' $(CMD_DIR)
## ─── Run ────────────────────────────────────────────────
run: build ## Run standalone server (in-memory mode)
$(BUILD_DIR)/$(BINARY_NAME)
run-disk: build ## Run standalone server (disk mode)
CACHEGRID_STORAGE_MODE=disk CACHEGRID_DISK_PATH=./cachegrid-data $(BUILD_DIR)/$(BINARY_NAME)
run-cluster: build ## Run a 3-node local cluster
@echo "Starting node-1..."
@CACHEGRID_NODE_NAME=node-1 CACHEGRID_LISTEN_ADDR=:7946 CACHEGRID_HTTP_PORT=6380 \
CACHEGRID_RPC_PORT=7947 $(BUILD_DIR)/$(BINARY_NAME) &
@sleep 1
@echo "Starting node-2..."
@CACHEGRID_NODE_NAME=node-2 CACHEGRID_LISTEN_ADDR=:7948 CACHEGRID_HTTP_PORT=6381 \
CACHEGRID_RPC_PORT=7949 CACHEGRID_SEEDS=127.0.0.1:7946 $(BUILD_DIR)/$(BINARY_NAME) &
@sleep 1
@echo "Starting node-3..."
@CACHEGRID_NODE_NAME=node-3 CACHEGRID_LISTEN_ADDR=:7950 CACHEGRID_HTTP_PORT=6382 \
CACHEGRID_RPC_PORT=7951 CACHEGRID_SEEDS=127.0.0.1:7946 $(BUILD_DIR)/$(BINARY_NAME) &
@echo "Cluster running: http://localhost:6380, :6381, :6382"
## ─── Test ───────────────────────────────────────────────
test: ## Run all tests
go test ./... -count=1
test-verbose: ## Run all tests with verbose output
go test ./... -v -count=1
test-race: ## Run tests with race detector
go test ./... -race -count=1
test-cover: ## Run tests with coverage report
@mkdir -p $(BUILD_DIR)
go test ./... -coverprofile=$(BUILD_DIR)/coverage.out -count=1
go tool cover -html=$(BUILD_DIR)/coverage.out -o $(BUILD_DIR)/coverage.html
@echo "Coverage report: $(BUILD_DIR)/coverage.html"
test-short: ## Run only fast tests (skip slow ones)
go test ./... -short -count=1
## ─── Integration Tests (Scripts) ────────────────────────
test-features: build ## Run REST API feature tests (requires server)
@bash ./scripts/test-features.sh
test-cluster: build ## Run 3-node cluster tests
@bash ./scripts/test-cluster.sh
test-disk: build ## Run disk persistence tests
@bash ./scripts/test-disk.sh
test-perf: build ## Run performance/benchmark tests
@bash ./scripts/test-performance.sh
test-scripts: build ## Run ALL integration test scripts
@bash ./scripts/test-all.sh
test-scripts-quick: build ## Run quick integration tests (skip cluster/disk/perf)
@bash ./scripts/test-all.sh --quick
## ─── Benchmark ──────────────────────────────────────────
bench: ## Run benchmarks
go test -bench=. -benchmem -count=1
bench-cpu: ## Run benchmarks with CPU profile
@mkdir -p $(BUILD_DIR)
go test -bench=. -benchmem -cpuprofile=$(BUILD_DIR)/cpu.prof -count=1
@echo "CPU profile: go tool pprof $(BUILD_DIR)/cpu.prof"
bench-mem: ## Run benchmarks with memory profile
@mkdir -p $(BUILD_DIR)
go test -bench=. -benchmem -memprofile=$(BUILD_DIR)/mem.prof -count=1
@echo "Mem profile: go tool pprof $(BUILD_DIR)/mem.prof"
## ─── Code Quality ───────────────────────────────────────
fmt: ## Format all Go files
gofmt -s -w .
vet: ## Run go vet
go vet ./...
lint: vet ## Run linter (requires golangci-lint)
@which golangci-lint > /dev/null 2>&1 || \
(echo "Install golangci-lint: https://golangci-lint.run/usage/install/" && exit 1)
golangci-lint run ./...
tidy: ## Tidy go.mod and go.sum
go mod tidy
## ─── Docker ─────────────────────────────────────────────
docker-build: ## Build Docker image
docker build -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
docker-run: docker-build ## Run in Docker (single node)
docker run -d --name cachegrid -p 6380:6380 -p 7946:7946 $(DOCKER_IMAGE):$(DOCKER_TAG)
@echo "Running at http://localhost:6380"
docker-run-disk: docker-build ## Run in Docker with disk storage
docker run -d --name cachegrid-disk \
-p 6380:6380 -p 7946:7946 \
-e CACHEGRID_STORAGE_MODE=disk \
-e CACHEGRID_DISK_PATH=/data \
-v cachegrid-data:/data \
$(DOCKER_IMAGE):$(DOCKER_TAG)
@echo "Running at http://localhost:6380 (disk mode, volume: cachegrid-data)"
docker-stop: ## Stop and remove Docker container
docker stop cachegrid 2>/dev/null || true
docker rm cachegrid 2>/dev/null || true
docker stop cachegrid-disk 2>/dev/null || true
docker rm cachegrid-disk 2>/dev/null || true
docker-compose-up: ## Start 3-node cluster via Docker Compose
docker compose up -d
@echo "Cluster running: http://localhost:6380, :6381, :6382"
docker-compose-down: ## Stop Docker Compose cluster
docker compose down
## ─── Kubernetes ─────────────────────────────────────────
k8s-deploy: ## Deploy to Kubernetes
kubectl apply -f kubernetes.yaml
k8s-delete: ## Delete Kubernetes deployment
kubectl delete -f kubernetes.yaml
## ─── Utility ────────────────────────────────────────────
clean: ## Remove build artifacts
rm -rf $(BUILD_DIR)
rm -rf ./cachegrid-data
deps: ## Download dependencies
go mod download
check: fmt vet test ## Format, vet, and test (pre-commit check)
health: ## Check health of running server
@curl -s http://localhost:6380/health | head -c 200
@echo
smoke: build ## Quick smoke test: start server, set/get, stop
@echo "Starting server..."
@$(BUILD_DIR)/$(BINARY_NAME) &
@SERVER_PID=$$!; \
sleep 1; \
echo "Setting key..."; \
curl -s -X PUT http://localhost:6380/cache/test -H "X-TTL: 1m" -d '"hello"'; \
echo; \
echo "Getting key..."; \
curl -s http://localhost:6380/cache/test; \
echo; \
echo "Health check..."; \
curl -s http://localhost:6380/health; \
echo; \
kill $$SERVER_PID 2>/dev/null; \
echo "Smoke test passed."
## ─── Help ───────────────────────────────────────────────
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'