-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
148 lines (130 loc) · 4.24 KB
/
Makefile
File metadata and controls
148 lines (130 loc) · 4.24 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
# GoBalancer Makefile
# Provides convenient targets for building, testing, and releasing
.PHONY: help build build-all run test test-quick bench fmt lint clean deps docker docker-run cross release
# Variables
BINARY_NAME=gobalancer
LOAD_TESTER=load-tester
VERSION?=dev
COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS=-ldflags "-X main.Version=$(VERSION) -X main.Commit=$(COMMIT) -X main.BuildTime=$(BUILD_TIME)"
# Default target
help:
@echo "GoBalancer Makefile"
@echo ""
@echo "Usage: make <target>"
@echo ""
@echo "Targets:"
@echo " build Build the load balancer for current platform"
@echo " build-all Build both load balancer and load tester"
@echo " run Build and run the load balancer"
@echo " test Run tests with coverage"
@echo " test-quick Run short tests without race detector"
@echo " bench Run internal Go benchmarks"
@echo " fmt Run go fmt and go mod tidy"
@echo " lint Run linters (go vet + golangci-lint)"
@echo " clean Clean build artifacts"
@echo " deps Download and tidy dependencies"
@echo " docker Build Docker image"
@echo " docker-run Run load balancer in Docker"
@echo " cross Cross-compile for all platforms"
@echo " release Create a release (requires VERSION=vX.Y.Z)"
@echo ""
# Build load balancer
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p bin
@go build -trimpath $(LDFLAGS) -o bin/$(BINARY_NAME) main.go
@echo "✓ Build complete: bin/$(BINARY_NAME)"
# Build load tester
build-tools:
@echo "Building $(LOAD_TESTER)..."
@mkdir -p bin
@go build -trimpath -o bin/$(LOAD_TESTER) cmd/load_tester/main.go
@echo "✓ Build complete: bin/$(LOAD_TESTER)"
build-all: build build-tools
# Build and run
run: build
@echo "Starting $(BINARY_NAME)..."
@./bin/$(BINARY_NAME)
# Run tests with coverage
test:
@echo "Running tests..."
@mkdir -p coverage
@go test -race -v -coverprofile=coverage/coverage.out -covermode=atomic ./...
@go tool cover -func=coverage/coverage.out | grep total
@go tool cover -html=coverage/coverage.out -o coverage/coverage.html
@echo "✓ Coverage report: coverage/coverage.html"
# Quick tests (short, no race detector)
test-quick:
@echo "Running quick tests..."
@go test -short ./...
# Run benchmarks
bench:
@echo "Running benchmarks..."
@mkdir -p coverage
@go test -v -bench=. -benchmem -run=^$$ ./... | tee coverage/bench.txt
# Format code
fmt:
@echo "Formatting code..."
@go fmt ./...
@go mod tidy
@echo "✓ Formatting complete"
# Run linters
lint:
@echo "Running go vet..."
@go vet ./...
@echo "✓ go vet passed"
@if command -v golangci-lint >/dev/null 2>&1; then \
echo "Running golangci-lint..."; \
golangci-lint run ./...; \
echo "✓ golangci-lint passed"; \
else \
echo "⚠ golangci-lint not found"; \
fi
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
@rm -rf bin/ release/ coverage/
@rm -f $(BINARY_NAME) $(LOAD_TESTER) LoadBalancer lb *.exe
@echo "✓ Clean complete"
# Download and tidy dependencies
deps:
@echo "Downloading dependencies..."
@go mod download
@echo "Tidying dependencies..."
@go mod tidy
@echo "✓ Dependencies updated"
# Build Docker image
docker:
@echo "Building Docker image..."
@docker build -f deployments/docker/Dockerfile -t $(BINARY_NAME):latest .
@echo "✓ Docker image built: $(BINARY_NAME):latest"
# Run in Docker
docker-run:
@echo "Running $(BINARY_NAME) in Docker..."
@docker run -p 8080:8080 -p 8081:8081 -v $$(pwd)/config:/app/config $(BINARY_NAME):latest
# Cross-compile for all platforms
cross:
@echo "Cross-compiling for all platforms..."
@if [ -f "./scripts/build.sh" ]; then \
./scripts/build.sh --cross --release; \
else \
echo "Error: scripts/build.sh not found"; \
exit 1; \
fi
@echo "✓ Cross-compilation complete"
# Create a release
release:
@if [ -z "$(VERSION)" ] || [ "$(VERSION)" = "dev" ]; then \
echo "Error: VERSION must be set (e.g., make release VERSION=v1.0.0)"; \
exit 1; \
fi
@echo "Creating release $(VERSION)..."
@if [ -f "./scripts/release.sh" ]; then \
./scripts/release.sh $(VERSION); \
else \
echo "Error: scripts/release.sh not found"; \
exit 1; \
fi
@echo "✓ Release $(VERSION) created"