-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
282 lines (243 loc) Β· 8.67 KB
/
Makefile
File metadata and controls
282 lines (243 loc) Β· 8.67 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# Makefile for roxie - Advanced Cluster Security Deployment Tool
# Default target
.DEFAULT_GOAL := build
# Go configuration
GOCMD := go
GOBUILD := $(GOCMD) build
GOTEST := $(GOCMD) test
GOVET := $(GOCMD) vet
GOFMT := gofmt
GOLINT := golangci-lint
BINARY_NAME := roxie
PKG_LIST := $(shell $(GOCMD) list ./... | grep -v /vendor/)
# Build output
BUILD_DIR := .
BINARY := $(BUILD_DIR)/$(BINARY_NAME)
# Convention is that the git tags are of the form
# v<major>.<minor>.<patch>-<build-number>-<commit-hash>[-dirty]
# or v<major>.<minor>.<patch>
#
# We use sed to drop the initial 'v' in case the whole tag matches any of the above patterns.
# Hence, the resulting version string will simply be
#
# <major>.<minor>.<patch> or <major>.<minor>.<patch>-<build-number>-<commit-hash>[-dirty]
#
# This will also become the tag of the docker images.
ROXIE_VERSION ?= $(shell git describe --tags --always --dirty | sed -E 's/^v([0-9]+\.[0-9]+\.[0-9]+-[0-9]+-[a-z0-9]+(-dirty)?$$)/\1/')
BUILD_DATE ?= $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
LDFLAGS := -X main.version=$(ROXIE_VERSION) -X main.buildDate=$(BUILD_DATE)
.PHONY: get-build-date
get-build-date:
@echo $(BUILD_DATE)
.PHONY: version
version:
@echo $(ROXIE_VERSION)
# Build targets
.PHONY: build
build: ## Build the roxie binary
@echo "π¨ Building roxie..."
$(GOBUILD) -ldflags "$(LDFLAGS)" -o $(BINARY) ./cmd
@echo "β
Build complete: $(BINARY)"
build-%: ## Build the roxie binary for a specific OS/ARCH (e.g., build-linux-amd64)
@$(eval PARTS := $(subst -, ,$*))
@$(eval TARGET_OS := $(word 1,$(PARTS)))
@$(eval TARGET_ARCH := $(word 2,$(PARTS)))
@if ! echo "linux darwin" | grep -qw "$(TARGET_OS)"; then \
echo "β Unsupported OS: $(TARGET_OS)"; \
echo "Supported: linux, darwin"; \
exit 1; \
fi
@if ! echo "amd64 arm64" | grep -qw "$(TARGET_ARCH)"; then \
echo "β Unsupported ARCH: $(TARGET_ARCH)"; \
echo "Supported: amd64, arm64"; \
exit 1; \
fi
@echo "π¨ Building roxie for $(TARGET_OS)/$(TARGET_ARCH)..."
CGO_ENABLED=0 GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH) $(GOBUILD) -ldflags "$(LDFLAGS)" -o $(BINARY)-$* ./cmd
@echo "β
Build complete: $(BINARY)-$*"
.PHONY: build-all
build-all: fmt vet build ## Format, vet, and build
.PHONY: install
install: ## Install roxie to $GOPATH/bin
@echo "π¦ Installing roxie..."
$(GOCMD) install -ldflags "$(LDFLAGS)" $(CMD_PATH)
# Development targets
.PHONY: fmt
fmt: ## Format Go code with gofmt
@echo "π¨ Formatting code..."
$(GOFMT) -s -w .
.PHONY: vet
vet: ## Run go vet
@echo "π Running go vet..."
$(GOVET) ./...
.PHONY: lint
lint: ## Run golangci-lint
@echo "π Running golangci-lint..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./...; \
else \
echo "β οΈ golangci-lint not installed. Install with:"; \
echo " go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
fi
.PHONY: check
check: fmt vet lint ## Run all code quality checks (fmt + vet + lint)
# Test targets
.PHONY: test
test: ## Run unit tests
@echo "π§ͺ Running unit tests..."
$(GOTEST) -v -race -coverprofile=coverage.out ./...
.PHONY: test-short
test-short: ## Run unit tests (short mode)
@echo "π§ͺ Running unit tests (short)..."
$(GOTEST) -v -short -race ./...
.PHONY: test-coverage
test-coverage: test ## Run tests with coverage report
@echo "π Generating coverage report..."
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "β
Coverage report: coverage.html"
.PHONY: run-test-e2e
run-test-e2e: ## Run end-to-end tests (requires roxie to be available in PATH, kubectl context and cluster access)
@echo "π§ͺ Running E2E tests..."
@echo ""; \
echo "Checking roxie binary is available..."; \
ROXIE=$$(command -v roxie); \
if [ -z "$$ROXIE" ]; then \
echo "β roxie not found in PATH."; \
exit 1; \
fi; \
echo "roxie found at $$ROXIE"; \
roxie version
@echo ""; \
echo "Checking a kubectl cluster context is set..."; \
CLUSTER_CONTEXT=$$(kubectl config current-context); \
if [ -z "$$CLUSTER_CONTEXT" ]; then \
echo "β No kubectl context found. Please configure kubectl first."; \
exit 1; \
fi; \
echo "using cluster context $$CLUSTER_CONTEXT"
@echo ""; \
echo "Invoking go test..."
$(GOTEST) -v -tags=e2e -timeout=120m -parallel=1 ./tests/e2e/...
.PHONY: test-e2e
test-e2e: build ## Run end-to-end tests (requires kubectl context and cluster access)
PATH="$$PWD:$$PATH" make run-test-e2e
.PHONY: test-integration
test-integration: ## Run integration tests (requires kubectl context and cluster access)
@echo ""; \
echo "Checking a kubectl cluster context is set..."; \
CLUSTER_CONTEXT=$$(kubectl config current-context); \
if [ -z "$$CLUSTER_CONTEXT" ]; then \
echo "β No kubectl context found. Please configure kubectl first."; \
exit 1; \
fi; \
echo "using cluster context $$CLUSTER_CONTEXT"
@echo ""; \
echo "Invoking go test..."
$(GOTEST) -v -tags=integration -run=_Integration$$ -timeout=120m -parallel=1 ./...
.PHONY: test-all
test-all: test test-integration test-e2e ## Run all tests (unit + integration + e2e)
# Benchmarks
.PHONY: bench
bench: ## Run benchmarks
@echo "β‘ Running benchmarks..."
$(GOTEST) -bench=. -benchmem ./...
# Clean up
.PHONY: clean
clean: ## Clean up build artifacts and caches
@echo "π§Ή Cleaning up..."
@rm -f $(BINARY)
@rm -f coverage.out coverage.html
@$(GOCMD) clean -cache -testcache
@find . -type f -name "*.test" -delete
@echo "β
Clean complete"
# Dependencies
.PHONY: deps
deps: ## Download and tidy dependencies
@echo "π¦ Downloading dependencies..."
$(GOCMD) mod download
$(GOCMD) mod tidy
.PHONY: deps-upgrade
deps-upgrade: ## Upgrade all dependencies
@echo "β¬οΈ Upgrading dependencies..."
$(GOCMD) get -u ./...
$(GOCMD) mod tidy
# Development environment
.PHONY: dev-setup
dev-setup: ## Set up development environment
@echo "π§ Setting up development environment..."
@echo "Installing development tools..."
@$(GOCMD) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@echo "β
Development environment ready"
# Run roxie help
# Validate
.PHONY: validate
validate: ## Validate go.mod and check for issues
@echo "β
Validating go.mod..."
@$(GOCMD) mod verify
@echo "β
go.mod is valid"
# Full development workflow
.PHONY: all
all: clean deps check test build ## Run full development workflow
# Docker/Container targets
IMAGE_DEFAULT_REGISTRY := localhost
IMAGE_REGISTRY := $(shell if [ -z "$(IMAGE_REGISTRY)" ]; then echo $(IMAGE_DEFAULT_REGISTRY); else echo $(IMAGE_REGISTRY); fi)
IMAGE_NAME := roxie
IMAGE_LATEST_TAG := $(IMAGE_REGISTRY)/$(IMAGE_NAME):latest
IMAGE_VERSION_TAG := $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(ROXIE_VERSION)
CONTAINER_RUNTIME ?= $(shell command -v podman 2>/dev/null || command -v docker 2>/dev/null)
# Multi-architecture support
PLATFORMS ?= linux/amd64,linux/arm64
BUILD_PLATFORM := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')
.PHONY: docker-build
docker-build: ## Build roxie Docker image for current platform
@echo "π³ Building roxie container image for current platform..."
@if [ -z "$(CONTAINER_RUNTIME)" ]; then \
echo "β No container runtime found. Please install docker or podman."; \
exit 1; \
fi
$(CONTAINER_RUNTIME) build \
--build-arg ROXIE_VERSION=$(ROXIE_VERSION) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
-t $(IMAGE_LATEST_TAG) \
-t $(IMAGE_VERSION_TAG) \
-f Dockerfile .
@echo "β
Built container images:"
@echo " - $(IMAGE_LATEST_TAG)"
@echo " - $(IMAGE_VERSION_TAG)"
.PHONY: docker-build-arm64
docker-build-arm64: ## Build roxie Docker image for arm64
@echo "π³ Building roxie container image for arm64..."
@if [ -z "$(CONTAINER_RUNTIME)" ]; then \
echo "β No container runtime found. Please install docker or podman."; \
exit 1; \
fi
$(CONTAINER_RUNTIME) build \
--platform linux/arm64 \
--build-arg ROXIE_VERSION=$(ROXIE_VERSION) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
-t $(IMAGE_LATEST_TAG)-arm64 \
-t $(IMAGE_VERSION_TAG)-arm64 \
-f Dockerfile .
@echo "β
Built arm64 images:"
@echo " - $(IMAGE_LATEST_TAG)-arm64"
@echo " - $(IMAGE_VERSION_TAG)-arm64"
.PHONY: docker-build-amd64
docker-build-amd64: ## Build roxie Docker image for amd64
@echo "π³ Building roxie container image for amd64..."
@if [ -z "$(CONTAINER_RUNTIME)" ]; then \
echo "β No container runtime found. Please install docker or podman."; \
exit 1; \
fi
$(CONTAINER_RUNTIME) build \
--platform linux/amd64 \
--build-arg ROXIE_VERSION=$(ROXIE_VERSION) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
-t $(IMAGE_LATEST_TAG)-amd64 \
-t $(IMAGE_VERSION_TAG)-amd64 \
-f Dockerfile .
@echo "β
Built amd64 images:"
@echo " - $(IMAGE_LATEST_TAG)-amd64"
@echo " - $(IMAGE_VERSION_TAG)-amd64"
# Quick targets
.PHONY: quick
quick: fmt vet build ## Quick build (fmt + vet + build)