-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
138 lines (111 loc) · 4.1 KB
/
Makefile
File metadata and controls
138 lines (111 loc) · 4.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
# proxy-http-forward - Makefile
# High-performance HTTP/HTTPS proxy server in pure Go
BINARY_NAME := proxy
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "none")
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Go parameters
GOCMD := go
GOBUILD := $(GOCMD) build
GOTEST := $(GOCMD) test
GOMOD := $(GOCMD) mod
GOVET := $(GOCMD) vet
GOFMT := gofmt
# Build flags
LDFLAGS := -ldflags "-s -w \
-X main.version=$(VERSION) \
-X main.commit=$(COMMIT) \
-X main.buildDate=$(BUILD_DATE)"
# Directories
CMD_DIR := ./cmd/proxy
BUILD_DIR := ./build
DIST_DIR := ./dist
.PHONY: all build clean test fmt vet lint run docker help
# Default target
all: clean fmt vet test build
## Build targets
build: ## Build the binary
@echo "Building $(BINARY_NAME) $(VERSION)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(CMD_DIR)
@echo "Binary built: $(BUILD_DIR)/$(BINARY_NAME)"
build-linux: ## Build for Linux (amd64)
@echo "Building for Linux amd64..."
@mkdir -p $(DIST_DIR)
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-linux-amd64 $(CMD_DIR)
build-darwin: ## Build for macOS (arm64)
@echo "Building for macOS arm64..."
@mkdir -p $(DIST_DIR)
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-darwin-arm64 $(CMD_DIR)
build-all: build-linux build-darwin ## Build for all platforms
## Development targets
run: build ## Build and run the proxy
@echo "Starting proxy server..."
$(BUILD_DIR)/$(BINARY_NAME)
dev: ## Run in development mode with hot reload (requires air)
@which air > /dev/null || (echo "Installing air..." && go install github.com/air-verse/air@latest)
air
## Testing targets
test: ## Run tests
@echo "Running tests..."
$(GOTEST) -v -race -cover ./...
test-coverage: ## Run tests with coverage report
@echo "Running tests with coverage..."
$(GOTEST) -v -race -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
bench: ## Run benchmarks
@echo "Running benchmarks..."
$(GOTEST) -bench=. -benchmem ./...
## Code quality targets
fmt: ## Format code
@echo "Formatting code..."
$(GOFMT) -s -w .
vet: ## Run go vet
@echo "Running go vet..."
$(GOVET) ./...
lint: ## Run golangci-lint (requires golangci-lint)
@which golangci-lint > /dev/null || (echo "Installing golangci-lint..." && go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest)
golangci-lint run
## Dependencies targets
deps: ## Download dependencies
@echo "Downloading dependencies..."
$(GOMOD) download
deps-update: ## Update dependencies
@echo "Updating dependencies..."
$(GOMOD) tidy
$(GOMOD) download
deps-verify: ## Verify dependencies
@echo "Verifying dependencies..."
$(GOMOD) verify
## Docker targets
docker-build: ## Build Docker image
@echo "Building Docker image..."
docker build -t proxy-http-forward:$(VERSION) .
docker tag proxy-http-forward:$(VERSION) proxy-http-forward:latest
docker-run: ## Run Docker container
docker run -p 8080:8080 -p 9090:9090 proxy-http-forward:latest
docker-push: ## Push Docker image (requires DOCKER_REGISTRY env var)
@if [ -z "$(DOCKER_REGISTRY)" ]; then echo "DOCKER_REGISTRY not set"; exit 1; fi
docker tag proxy-http-forward:$(VERSION) $(DOCKER_REGISTRY)/proxy-http-forward:$(VERSION)
docker push $(DOCKER_REGISTRY)/proxy-http-forward:$(VERSION)
## Utility targets
clean: ## Clean build artifacts
@echo "Cleaning..."
rm -rf $(BUILD_DIR) $(DIST_DIR)
rm -f coverage.out coverage.html
version: ## Show version
@echo "Version: $(VERSION)"
@echo "Commit: $(COMMIT)"
@echo "Date: $(BUILD_DATE)"
## Help target
help: ## Show this help
@echo "proxy-http-forward - Available targets:"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "Example usage:"
@echo " make build # Build the binary"
@echo " make run # Build and run"
@echo " make test # Run tests"
@echo " make docker-build # Build Docker image"