-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
206 lines (182 loc) · 6.26 KB
/
Makefile
File metadata and controls
206 lines (182 loc) · 6.26 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
# GitHub Reverse Proxy Makefile
# Variables
BINARY_NAME=github-proxy
MAIN_PATH=./cmd/server
BUILD_DIR=./build
CONFIG_PATH=./configs/config.yaml
DOCKER_IMAGE=github-proxy
DOCKER_TAG=latest
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=$(GOCMD) fmt
GOVET=$(GOCMD) vet
# Build flags
LDFLAGS=-ldflags "-s -w"
BUILD_FLAGS=-trimpath
.PHONY: all build test clean run install lint docker-build docker-run help build-all-platforms github-release
# Default target
all: test build
# Build the application
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)"
# Run tests
test:
@echo "Running tests..."
$(GOTEST) -v -race -coverprofile=coverage.out ./...
@echo "Tests complete"
# Run tests with coverage report
test-coverage: test
@echo "Generating coverage report..."
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Clean build artifacts
clean:
@echo "Cleaning..."
$(GOCLEAN)
@rm -rf $(BUILD_DIR)
@rm -f coverage.out coverage.html
@echo "Clean complete"
# Run the application
run:
@echo "Running $(BINARY_NAME)..."
$(GOCMD) run $(MAIN_PATH) -config $(CONFIG_PATH)
# Install dependencies
install:
@echo "Installing dependencies..."
$(GOMOD) download
$(GOMOD) tidy
@echo "Dependencies installed"
# Update dependencies
update:
@echo "Updating dependencies..."
$(GOGET) -u ./...
$(GOMOD) tidy
@echo "Dependencies updated"
# Run linters
lint:
@echo "Running linters..."
@command -v golangci-lint >/dev/null 2>&1 || { \
echo "golangci-lint not found, installing..."; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
}
golangci-lint run ./...
@echo "Linting complete"
# Format code
fmt:
@echo "Formatting code..."
$(GOFMT) ./...
@echo "Formatting complete"
# Run go vet
vet:
@echo "Running go vet..."
$(GOVET) ./...
@echo "Vet complete"
# Build Docker image
docker-build:
@echo "Building Docker image..."
docker build -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
@echo "Docker image built: $(DOCKER_IMAGE):$(DOCKER_TAG)"
# Run Docker container
docker-run:
@echo "Running Docker container..."
docker run -d \
-p 8080:8080 \
-p 2222:2222 \
-p 9090:9090 \
--name $(BINARY_NAME) \
$(DOCKER_IMAGE):$(DOCKER_TAG)
@echo "Docker container started"
# Stop Docker container
docker-stop:
@echo "Stopping Docker container..."
docker stop $(BINARY_NAME)
docker rm $(BINARY_NAME)
@echo "Docker container stopped"
# Build for multiple platforms (simple version)
build-all:
@echo "Building for multiple platforms..."
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 $(MAIN_PATH)
GOOS=linux GOARCH=arm64 $(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 $(MAIN_PATH)
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 $(MAIN_PATH)
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 $(MAIN_PATH)
GOOS=windows GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe $(MAIN_PATH)
@echo "Multi-platform build complete"
# Build for all platforms with archives (uses script)
build-all-platforms:
@echo "Building for all platforms with archives..."
@./scripts/build-all.sh
@echo "Build complete"
# Create release packages (simple version)
release: build-all
@echo "Creating release packages..."
@cd $(BUILD_DIR) && \
tar -czf $(BINARY_NAME)-linux-amd64.tar.gz $(BINARY_NAME)-linux-amd64 && \
tar -czf $(BINARY_NAME)-linux-arm64.tar.gz $(BINARY_NAME)-linux-arm64 && \
tar -czf $(BINARY_NAME)-darwin-amd64.tar.gz $(BINARY_NAME)-darwin-amd64 && \
tar -czf $(BINARY_NAME)-darwin-arm64.tar.gz $(BINARY_NAME)-darwin-arm64 && \
zip $(BINARY_NAME)-windows-amd64.zip $(BINARY_NAME)-windows-amd64.exe
@echo "Release packages created in $(BUILD_DIR)"
# Create GitHub release with all binaries
github-release:
@echo "Creating GitHub release..."
@if ! command -v gh >/dev/null 2>&1; then \
echo "Error: GitHub CLI (gh) is not installed"; \
echo "Install from: https://cli.github.com/"; \
exit 1; \
fi
@./scripts/release.sh $(VERSION)
@echo "GitHub release created"
# Install the binary to system
install-binary: build
@echo "Installing $(BINARY_NAME) to /usr/local/bin..."
@sudo cp $(BUILD_DIR)/$(BINARY_NAME) /usr/local/bin/
@echo "Installation complete"
# Display help
help:
@echo "GitHub Reverse Proxy - Makefile targets:"
@echo ""
@echo "Build targets:"
@echo " make build - Build the application"
@echo " make build-all - Build for multiple platforms (simple)"
@echo " make build-all-platforms - Build for all platforms with archives"
@echo " make release - Create release packages (simple)"
@echo " make github-release - Create GitHub release (requires gh CLI)"
@echo ""
@echo "Development targets:"
@echo " make test - Run tests"
@echo " make test-coverage - Run tests with coverage report"
@echo " make run - Run the application"
@echo " make clean - Clean build artifacts"
@echo " make install - Install dependencies"
@echo " make update - Update dependencies"
@echo ""
@echo "Code quality targets:"
@echo " make lint - Run linters"
@echo " make fmt - Format code"
@echo " make vet - Run go vet"
@echo ""
@echo "Docker targets:"
@echo " make docker-build - Build Docker image"
@echo " make docker-run - Run Docker container"
@echo " make docker-stop - Stop Docker container"
@echo ""
@echo "Installation targets:"
@echo " make install-binary - Install binary to system"
@echo ""
@echo "Other targets:"
@echo " make help - Display this help message"
@echo ""
@echo "Examples:"
@echo " make build # Build for current platform"
@echo " make build-all-platforms # Build for all platforms"
@echo " make github-release VERSION=v1.0.0 # Create GitHub release"
@echo ""