-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
100 lines (85 loc) · 3.33 KB
/
Makefile
File metadata and controls
100 lines (85 loc) · 3.33 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
# Project information
PROJECT_NAME := ezlb
MODULE_NAME := github.com/easzlab/ezlb
BUILD_TIME := $(shell date +%Y-%m-%d\ %H:%M:%S)
BUILD_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
#BUILD_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
# Build configuration
BUILD_DIR := build
# Linker flags for build information
LDFLAGS := -ldflags "-X 'main.BuildTime=$(BUILD_TIME)' \
-X 'main.BuildCommit=$(BUILD_COMMIT)' \
-s -w -extldflags -static"
# Default target
.PHONY: all
all: clean build
.PHONY: help
help: ## show help
@echo "Available targets: "
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.PHONY: build
build: ## build the binary
@echo "Building $(PROJECT_NAME) ..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 go build -tags integration $(LDFLAGS) -o build/ezlb cmd/ezlb/main.go
@echo "✓ Build completed."
.PHONY: build-dev
build-dev: ## build the binary with debug info
@echo "Building $(PROJECT_NAME) for development..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=1 go build -tags integration -race -o build/ezlb cmd/ezlb/main.go
@echo "✓ Development build completed."
.PHONY: build-linux
build-linux: ## build the binary for Linux
@echo "Building for Linux..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags integration $(LDFLAGS) -o build/ezlb-linux-amd64 cmd/ezlb/main.go
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -tags integration $(LDFLAGS) -o build/ezlb-linux-arm64 cmd/ezlb/main.go
@echo "✓ Linux build completed"
.PHONY: build-docker
build-docker: ## build docker image: easzlab/ezlb
@echo "Building easzlab/ezlb:latest ..."
@docker build -t easzlab/ezlb .
@echo "✓ Build completed."
.PHONY: test
test: ## run unit tests (all platforms, using fake IPVS)
@echo "Running unit tests..."
@go test -v ./...
@echo "✓ Tests completed"
.PHONY: test-cov
test-cov: ## run tests with coverage (all platforms, using fake IPVS)
@echo "Running tests with coverage..."
@go test -v -coverprofile=coverage.out ./...
@go tool cover -html=coverage.out -o coverage.html
@echo "✓ Coverage report generated: coverage.html"
# test-linux runs tests with real IPVS handle, serially (-p 1) because IPVS is a global kernel resource.
# Must be run as root on Linux.
.PHONY: test-linux
test-linux: ## run unit tests with real IPVS (Linux only)
@echo "Running unit tests for linux..."
@go test -count=1 -p 1 -tags integration ./...
@echo "✓ Tests completed"
# e2e tests compile the ezlb binary and verify IPVS kernel rules end-to-end.
# Must be run as root on Linux.
.PHONY: test-e2e
test-e2e: ## run end-to-end tests for Linux
@echo "Running e2e tests for linux..."
@go test -count=1 -v -p 1 -tags integration ./tests/e2e/
@echo "✓ Tests completed"
.PHONY: test-e2e-docker
test-e2e-docker: ## run e2e tests inside a Docker container
@echo "Running containerized e2e tests..."
@bash tests/e2e/run-e2e-container.sh
@echo "✓ Containerized e2e tests completed"
.PHONY: clean
clean: ## clean build artifacts
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR)
@rm -f coverage.out coverage.html
@echo "✓ Clean completed"
.PHONY: update
update: ## update dependencies
@echo "Updating dependencies..."
@go get -u ./...
@go mod tidy
@echo "✓ Dependencies updated"