-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
171 lines (145 loc) · 5.72 KB
/
Makefile
File metadata and controls
171 lines (145 loc) · 5.72 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
.PHONY: all build test lint clean docker run-server run-worker help
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=gofmt
# Binary names
BINARY_SERVER=goqueue-server
BINARY_WORKER=goqueue-worker
BINARY_CLI=goqueue
# Build directories
BUILD_DIR=bin
DIST_DIR=dist
# Version
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS=-ldflags "-w -s -X main.version=$(VERSION) -X main.buildTime=$(BUILD_TIME)"
# Default target
all: lint test build
## help: Show this help message
help:
@echo "GoQueue - Distributed Task Queue"
@echo ""
@echo "Usage:"
@echo " make [target]"
@echo ""
@echo "Targets:"
@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/## / /'
## build: Build all binaries
build: build-server build-worker build-cli
## build-server: Build server binary
build-server:
@echo "Building server..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_SERVER) ./cmd/server
## build-worker: Build worker binary
build-worker:
@echo "Building worker..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_WORKER) ./cmd/worker
## build-cli: Build CLI binary
build-cli:
@echo "Building CLI..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_CLI) ./cmd/cli
## test: Run all tests
test:
@echo "Running tests..."
$(GOTEST) -v -race -coverprofile=coverage.out ./...
## test-coverage: Run tests with coverage report
test-coverage: test
@echo "Generating coverage report..."
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
## test-integration: Run integration tests
test-integration:
@echo "Running integration tests..."
$(GOTEST) -v -tags=integration ./tests/integration/...
## lint: Run linters
lint:
@echo "Running linters..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./...; \
else \
echo "golangci-lint not installed, running basic checks..."; \
$(GOFMT) -d -s .; \
$(GOCMD) vet ./...; \
fi
## fmt: Format code
fmt:
@echo "Formatting code..."
$(GOFMT) -w -s .
## tidy: Tidy and verify dependencies
tidy:
@echo "Tidying dependencies..."
$(GOMOD) tidy
$(GOMOD) verify
## clean: Clean build artifacts
clean:
@echo "Cleaning..."
@rm -rf $(BUILD_DIR) $(DIST_DIR)
@rm -f coverage.out coverage.html
@rm -f goqueue.db
## docker-build: Build Docker images
docker-build:
@echo "Building Docker images..."
docker build --target server -t goqueue/server:$(VERSION) -t goqueue/server:latest .
docker build --target worker -t goqueue/worker:$(VERSION) -t goqueue/worker:latest .
docker build --target cli -t goqueue/cli:$(VERSION) -t goqueue/cli:latest .
## docker-up: Start Docker services
docker-up:
@echo "Starting Docker services..."
docker compose -f docker/docker-compose.yml up -d
## docker-down: Stop Docker services
docker-down:
@echo "Stopping Docker services..."
docker compose -f docker/docker-compose.yml down
## docker-logs: View Docker logs
docker-logs:
docker compose -f docker/docker-compose.yml logs -f
## run-server: Run server locally
run-server: build-server
@echo "Starting server..."
$(BUILD_DIR)/$(BINARY_SERVER) --log-format=console --log-level=debug
## run-worker: Run worker locally
run-worker: build-worker
@echo "Starting worker..."
$(BUILD_DIR)/$(BINARY_WORKER) --log-format=console --log-level=debug
## run-example: Run basic example
run-example:
@echo "Running example..."
$(GOCMD) run ./examples/basic/
## install: Install binaries to $GOPATH/bin
install:
@echo "Installing binaries..."
$(GOCMD) install $(LDFLAGS) ./cmd/server
$(GOCMD) install $(LDFLAGS) ./cmd/worker
$(GOCMD) install $(LDFLAGS) ./cmd/cli
## release: Build release binaries for all platforms
release:
@echo "Building release binaries..."
@mkdir -p $(DIST_DIR)
# Linux AMD64
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_SERVER)-linux-amd64 ./cmd/server
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_WORKER)-linux-amd64 ./cmd/worker
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_CLI)-linux-amd64 ./cmd/cli
# Linux ARM64
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_SERVER)-linux-arm64 ./cmd/server
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_WORKER)-linux-arm64 ./cmd/worker
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_CLI)-linux-arm64 ./cmd/cli
# macOS AMD64
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_SERVER)-darwin-amd64 ./cmd/server
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_WORKER)-darwin-amd64 ./cmd/worker
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_CLI)-darwin-amd64 ./cmd/cli
# macOS ARM64
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_SERVER)-darwin-arm64 ./cmd/server
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_WORKER)-darwin-arm64 ./cmd/worker
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_CLI)-darwin-arm64 ./cmd/cli
# Windows AMD64
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_SERVER)-windows-amd64.exe ./cmd/server
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_WORKER)-windows-amd64.exe ./cmd/worker
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_CLI)-windows-amd64.exe ./cmd/cli
@echo "Release binaries built in $(DIST_DIR)/"