-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
354 lines (309 loc) · 13.8 KB
/
Copy pathMakefile
File metadata and controls
354 lines (309 loc) · 13.8 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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# TaskForge Makefile
.PHONY: help build test clean install lint format deps run-api run-worker run-scheduler docker-build docker-up docker-down
# Default target
.DEFAULT_GOAL := help
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=gofmt
GOLINT=golangci-lint
# Build parameters
BINARY_DIR=bin
API_BINARY=$(BINARY_DIR)/taskforge-api
WORKER_BINARY=$(BINARY_DIR)/taskforge-worker
SCHEDULER_BINARY=$(BINARY_DIR)/taskforge-scheduler
CLI_BINARY=$(BINARY_DIR)/taskforge-cli
DEMO_BINARY=$(BINARY_DIR)/redis-demo
WORKER_ENGINE_DEMO_BINARY=$(BINARY_DIR)/worker-engine-demo
# Docker parameters
DOCKER_REGISTRY=2bxtech
IMAGE_TAG=latest
# Colors for output
RED=\033[0;31m
GREEN=\033[0;32m
YELLOW=\033[1;33m
BLUE=\033[0;34m
NC=\033[0m # No Color
help: ## Show this help message
@echo "$(BLUE)TaskForge - Distributed Task Queue System$(NC)"
@echo ""
@echo "$(YELLOW)Available commands:$(NC)"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " $(GREEN)%-15s$(NC) %s\n", $$1, $$2}' $(MAKEFILE_LIST)
deps: ## Download and install dependencies
@echo "$(BLUE)Installing dependencies...$(NC)"
$(GOMOD) download
$(GOMOD) tidy
@echo "$(GREEN)Dependencies installed successfully!$(NC)"
build: deps ## Build all binaries
@echo "$(BLUE)Building all binaries...$(NC)"
@mkdir -p $(BINARY_DIR)
$(GOBUILD) -o $(API_BINARY) ./cmd/api
$(GOBUILD) -o $(WORKER_BINARY) ./cmd/worker
$(GOBUILD) -o $(SCHEDULER_BINARY) ./cmd/scheduler
$(GOBUILD) -o $(CLI_BINARY) ./cmd/cli
@echo "$(GREEN)All binaries built successfully!$(NC)"
build-demo: deps ## Build demo binary
@echo "$(BLUE)Building demo binary...$(NC)"
@mkdir -p $(BINARY_DIR)
@if [ -f "./examples/redis-demo/main.go" ]; then \
$(GOBUILD) -o $(DEMO_BINARY) ./examples/redis-demo/main.go; \
echo "$(GREEN)Redis demo binary built successfully!$(NC)"; \
else \
echo "$(YELLOW)Redis demo source not found, skipping Redis demo build$(NC)"; \
fi
@if [ -f "./examples/worker-engine-demo/main.go" ]; then \
$(GOBUILD) -o $(WORKER_ENGINE_DEMO_BINARY) ./examples/worker-engine-demo/main.go; \
echo "$(GREEN)Worker engine demo binary built successfully!$(NC)"; \
else \
echo "$(YELLOW)Worker engine demo source not found, skipping worker engine demo build$(NC)"; \
fi
build-worker-engine-demo: deps ## Build worker engine demo binary
@echo "$(BLUE)Building worker engine demo binary...$(NC)"
@mkdir -p $(BINARY_DIR)
$(GOBUILD) -o $(WORKER_ENGINE_DEMO_BINARY) ./examples/worker-engine-demo/main.go
@echo "$(GREEN)Worker engine demo binary built successfully!$(NC)"
build-api: deps ## Build API server binary
@echo "$(BLUE)Building API server...$(NC)"
@mkdir -p $(BINARY_DIR)
$(GOBUILD) -o $(API_BINARY) ./cmd/api
@echo "$(GREEN)API server built successfully!$(NC)"
build-worker: deps ## Build worker binary
@echo "$(BLUE)Building worker...$(NC)"
@mkdir -p $(BINARY_DIR)
$(GOBUILD) -o $(WORKER_BINARY) ./cmd/worker
@echo "$(GREEN)Worker built successfully!$(NC)"
build-scheduler: deps ## Build scheduler binary
@echo "$(BLUE)Building scheduler...$(NC)"
@mkdir -p $(BINARY_DIR)
$(GOBUILD) -o $(SCHEDULER_BINARY) ./cmd/scheduler
@echo "$(GREEN)Scheduler built successfully!$(NC)"
build-cli: deps ## Build CLI binary
@echo "$(BLUE)Building CLI...$(NC)"
@mkdir -p $(BINARY_DIR)
$(GOBUILD) -o $(CLI_BINARY) ./cmd/cli
@echo "$(GREEN)CLI built successfully!$(NC)"
test: ## Run all tests
@echo "$(BLUE)Running tests...$(NC)"
$(GOTEST) -v ./...
@echo "$(GREEN)All tests passed!$(NC)"
test-coverage: ## Run tests with coverage
@echo "$(BLUE)Running tests with coverage...$(NC)"
@mkdir -p build/coverage
$(GOTEST) -race -covermode=atomic -coverprofile=build/coverage/cover.out -v ./...
$(GOCMD) tool cover -func=build/coverage/cover.out | tee build/coverage/coverage.txt
$(GOCMD) tool cover -html=build/coverage/cover.out -o build/coverage/coverage.html
@echo "$(GREEN)Coverage report generated: build/coverage/coverage.html$(NC)"
test-integration: ## Run integration tests (CI compatible)
@echo "$(BLUE)Running integration tests...$(NC)"
@# Check if we have actual integration tests
@if [ -d "./tests" ] && find ./tests -name "*_test.go" | head -1 | grep -q .; then \
echo "Running Go integration tests..."; \
$(GOTEST) -v -tags=integration ./tests/...; \
else \
echo "$(YELLOW)No Go integration test files found in ./tests$(NC)"; \
fi
@# Run shell-based integration tests if they exist
@if [ -f "tests/integration/redis_demo.sh" ]; then \
echo "Running Redis demo integration test..."; \
chmod +x tests/integration/redis_demo.sh; \
./tests/integration/redis_demo.sh; \
else \
echo "$(YELLOW)Redis demo integration test not found$(NC)"; \
fi
@if [ -f "tests/integration/smoke.sh" ]; then \
echo "Running smoke tests..."; \
chmod +x tests/integration/smoke.sh; \
./tests/integration/smoke.sh; \
else \
echo "$(YELLOW)Smoke tests not found$(NC)"; \
fi
@echo "$(GREEN)Integration tests completed!$(NC)"
ci: lint test ## Run CI pipeline locally
@echo "$(BLUE)Running CI pipeline...$(NC)"
$(GOMOD) verify
$(GOTEST) -race -covermode=atomic -coverprofile=coverage.out -v ./...
@echo "$(GREEN)CI pipeline completed successfully!$(NC)"
redis-demo: build-demo ## Run Redis queue demo
@echo "$(BLUE)Running TaskForge Redis Queue Demo...$(NC)"
@if [ -f "$(DEMO_BINARY)" ]; then \
echo "🔨 Running built Redis demo..."; \
./$(DEMO_BINARY); \
elif [ -f "./examples/redis-demo/main.go" ]; then \
echo "🔨 Building and running Redis demo..."; \
go run ./examples/redis-demo/main.go; \
else \
echo "❌ Redis demo not found"; \
exit 1; \
fi
@echo "$(GREEN)Demo completed!$(NC)"
worker-demo: build-worker-engine-demo ## Run worker engine demo
@echo "$(BLUE)Running TaskForge Worker Engine Demo...$(NC)"
@echo "$(YELLOW)Make sure Redis is running (docker-compose up redis -d)$(NC)"
@if [ -f "$(WORKER_ENGINE_DEMO_BINARY)" ]; then \
echo "🔨 Running built worker engine demo..."; \
./$(WORKER_ENGINE_DEMO_BINARY); \
elif [ -f "./examples/worker-engine-demo/main.go" ]; then \
echo "🔨 Building and running worker engine demo..."; \
go run ./examples/worker-engine-demo/main.go; \
else \
echo "❌ Worker engine demo not found"; \
exit 1; \
fi
@echo "$(GREEN)Worker engine demo completed!$(NC)"
# Backwards compatibility and convenience aliases
demo: redis-demo ## Alias for redis-demo (backwards compatibility)
demo-all: ## Run both Redis and Worker engine demos
@echo "$(BLUE)Running all TaskForge demos...$(NC)"
@echo "$(YELLOW)1. Redis Queue Demo$(NC)"
@make redis-demo
@echo ""
@echo "$(YELLOW)2. Worker Engine Demo$(NC)"
@make worker-demo
@echo "$(GREEN)All demos completed!$(NC)"
integration-test: ## Run integration tests (alias for test-integration)
@make test-integration
benchmark: ## Run benchmarks
@echo "$(BLUE)Running benchmarks...$(NC)"
$(GOTEST) -bench=. -benchmem ./...
@echo "$(GREEN)Benchmarks completed!$(NC)"
lint: ## Run linter
@echo "$(BLUE)Running linter...$(NC)"
$(GOLINT) run ./...
@echo "$(GREEN)Linting completed!$(NC)"
format: ## Format Go code
@echo "$(BLUE)Formatting code...$(NC)"
$(GOFMT) -s -w .
@echo "$(GREEN)Code formatted!$(NC)"
clean: ## Clean build artifacts
@echo "$(BLUE)Cleaning build artifacts...$(NC)"
$(GOCLEAN)
rm -rf $(BINARY_DIR)
rm -f coverage.out coverage.html gosec-results.sarif gosec.json
@echo "$(GREEN)Clean completed!$(NC)"
install: build ## Install binaries to $GOPATH/bin
@echo "$(BLUE)Installing binaries...$(NC)"
cp $(API_BINARY) $(GOPATH)/bin/
cp $(WORKER_BINARY) $(GOPATH)/bin/
cp $(SCHEDULER_BINARY) $(GOPATH)/bin/
cp $(CLI_BINARY) $(GOPATH)/bin/
@echo "$(GREEN)Binaries installed successfully!$(NC)"
run-api: build-api ## Run the API server
@echo "$(BLUE)Starting API server...$(NC)"
./$(API_BINARY)
run-worker: build-worker ## Run a worker
@echo "$(BLUE)Starting worker...$(NC)"
./$(WORKER_BINARY)
run-scheduler: build-scheduler ## Run the scheduler
@echo "$(BLUE)Starting scheduler...$(NC)"
./$(SCHEDULER_BINARY)
dev-setup: ## Set up development environment
@echo "$(BLUE)Setting up development environment...$(NC)"
@command -v golangci-lint >/dev/null 2>&1 || { \
echo "Installing golangci-lint..."; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.55.2; \
}
@command -v docker >/dev/null 2>&1 || { \
echo "$(YELLOW)Warning: Docker not found. Please install Docker for full development experience.$(NC)"; \
}
@command -v docker-compose >/dev/null 2>&1 || { \
echo "$(YELLOW)Warning: Docker Compose not found. Please install Docker Compose for full development experience.$(NC)"; \
}
@echo "$(GREEN)Development environment setup completed!$(NC)"
docker-build: ## Build Docker images
@echo "$(BLUE)Building Docker images...$(NC)"
docker build -t $(DOCKER_REGISTRY)/taskforge-api:$(IMAGE_TAG) -f deployments/docker/Dockerfile.api .
docker build -t $(DOCKER_REGISTRY)/taskforge-worker:$(IMAGE_TAG) -f deployments/docker/Dockerfile.worker .
docker build -t $(DOCKER_REGISTRY)/taskforge-scheduler:$(IMAGE_TAG) -f deployments/docker/Dockerfile.scheduler .
@echo "$(GREEN)Docker images built successfully!$(NC)"
docker-push: docker-build ## Build and push Docker images
@echo "$(BLUE)Pushing Docker images...$(NC)"
docker push $(DOCKER_REGISTRY)/taskforge-api:$(IMAGE_TAG)
docker push $(DOCKER_REGISTRY)/taskforge-worker:$(IMAGE_TAG)
docker push $(DOCKER_REGISTRY)/taskforge-scheduler:$(IMAGE_TAG)
@echo "$(GREEN)Docker images pushed successfully!$(NC)"
docker-up: ## Start services with Docker Compose
@echo "$(BLUE)Starting services with Docker Compose...$(NC)"
docker-compose up -d
@echo "$(GREEN)Services started successfully!$(NC)"
docker-down: ## Stop services with Docker Compose
@echo "$(BLUE)Stopping services with Docker Compose...$(NC)"
docker-compose down
@echo "$(GREEN)Services stopped successfully!$(NC)"
docker-logs: ## Show Docker Compose logs
@echo "$(BLUE)Showing Docker Compose logs...$(NC)"
docker-compose logs -f
security-scan: ## Run security scan
@echo "$(BLUE)Running security scan...$(NC)"
@command -v gosec >/dev/null 2>&1 || { \
echo "Installing gosec..."; \
go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest; \
}
@command -v govulncheck >/dev/null 2>&1 || { \
echo "Installing govulncheck..."; \
go install golang.org/x/vuln/cmd/govulncheck@latest; \
}
gosec -fmt sarif -out gosec-results.sarif ./... || true
gosec -fmt text ./... || true
govulncheck ./... || true
@echo "$(GREEN)Security scan completed!$(NC)"
mod-update: ## Update all dependencies
@echo "$(BLUE)Updating dependencies...$(NC)"
$(GOGET) -u ./...
$(GOMOD) tidy
@echo "$(GREEN)Dependencies updated!$(NC)"
proto-gen: ## Generate protobuf files (if using gRPC)
@echo "$(BLUE)Generating protobuf files...$(NC)"
# Add protobuf generation commands here when we implement gRPC
@echo "$(GREEN)Protobuf files generated!$(NC)"
release: clean test lint ## Prepare a release build
@echo "$(BLUE)Preparing release build...$(NC)"
@mkdir -p $(BINARY_DIR)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -ldflags="-w -s" -o $(API_BINARY)-linux-amd64 ./cmd/api
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -ldflags="-w -s" -o $(WORKER_BINARY)-linux-amd64 ./cmd/worker
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -ldflags="-w -s" -o $(SCHEDULER_BINARY)-linux-amd64 ./cmd/scheduler
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -ldflags="-w -s" -o $(CLI_BINARY)-linux-amd64 ./cmd/cli
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -ldflags="-w -s" -o $(API_BINARY)-windows-amd64.exe ./cmd/api
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -ldflags="-w -s" -o $(WORKER_BINARY)-windows-amd64.exe ./cmd/worker
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -ldflags="-w -s" -o $(SCHEDULER_BINARY)-windows-amd64.exe ./cmd/scheduler
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -ldflags="-w -s" -o $(CLI_BINARY)-windows-amd64.exe ./cmd/cli
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) -ldflags="-w -s" -o $(API_BINARY)-darwin-amd64 ./cmd/api
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) -ldflags="-w -s" -o $(WORKER_BINARY)-darwin-amd64 ./cmd/worker
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) -ldflags="-w -s" -o $(SCHEDULER_BINARY)-darwin-amd64 ./cmd/scheduler
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) -ldflags="-w -s" -o $(CLI_BINARY)-darwin-amd64 ./cmd/cli
@echo "$(GREEN)Release build completed!$(NC)"
watch: ## Watch for changes and rebuild
@echo "$(BLUE)Watching for changes...$(NC)"
@command -v air >/dev/null 2>&1 || { \
echo "Installing air for hot reloading..."; \
go install github.com/cosmtrek/air@latest; \
}
air
init-project: ## Initialize a new development environment
@echo "$(BLUE)Initializing TaskForge development environment...$(NC)"
@echo "Creating necessary directories..."
@mkdir -p {cmd/{api,worker,scheduler,cli},internal/{queue,worker,scheduler,task,api},pkg/{client,types},deployments/{k8s,docker,helm},examples,tests,docs}
@echo "Setting up git hooks..."
@git config core.hooksPath .githooks 2>/dev/null || true
@echo "$(GREEN)Project initialization completed!$(NC)"
@echo "$(YELLOW)Next steps:$(NC)"
@echo " 1. Run 'make dev-setup' to install development tools"
@echo " 2. Run 'make deps' to install Go dependencies"
@echo " 3. Run 'make docker-up' to start development services"
@echo " 4. Run 'make build' to build all components"
# Generate version info
version:
@echo "TaskForge Development Build"
@echo "Go version: $(shell go version)"
@echo "Git commit: $(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')"
@echo "Build time: $(shell date -u '+%Y-%m-%d %H:%M:%S UTC')"
# Show project statistics
stats:
@echo "$(BLUE)Project Statistics:$(NC)"
@echo "Go files: $(shell find . -name '*.go' | wc -l)"
@echo "Lines of code: $(shell find . -name '*.go' -exec wc -l {} + | tail -1 | awk '{print $$1}')"
@echo "Test files: $(shell find . -name '*_test.go' | wc -l)"
@echo "Packages: $(shell go list ./... | wc -l)"