-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
367 lines (309 loc) · 12.3 KB
/
Makefile
File metadata and controls
367 lines (309 loc) · 12.3 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# kdebug Makefile
.PHONY: build clean test lint fmt vet install dev-deps help local-ci local-ci-quick local-ci-build local-ci-no-tests local-ci-verbose
# Binary name and version
BINARY_NAME=kdebug
VERSION=1.0.1
BUILD_DIR=bin
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=gofmt
GOVET=$(GOCMD) vet
# Build flags
LDFLAGS=-ldflags "-X kdebug/cmd.Version=$(VERSION)"
# Default target
all: clean build
## Build the binary
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) .
@echo "Binary built: $(BUILD_DIR)/$(BINARY_NAME)"
## Build for all platforms
build-all: clean
@echo "Building for all platforms..."
@mkdir -p $(BUILD_DIR)
# Linux AMD64
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 .
# Linux ARM64
GOOS=linux GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 .
# macOS AMD64
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 .
# macOS ARM64 (Apple Silicon)
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 .
# Windows AMD64
GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe .
@echo "Cross-platform binaries built in $(BUILD_DIR)/"
## Run tests
test:
@echo "Running tests..."
$(GOTEST) -v ./...
## Run tests with coverage
test-coverage:
@echo "Running tests with coverage..."
$(GOTEST) -v -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
## Run integration tests (requires cluster access)
test-integration:
@echo "Running integration tests..."
$(GOTEST) -v -tags=integration -timeout=10m ./test/integration/...
## Run end-to-end tests
test-e2e:
@echo "Running end-to-end tests..."
$(GOTEST) -v -tags=e2e ./...
## Format code
fmt:
@echo "Formatting code..."
$(GOFMT) -s -w .
## Run go vet
vet:
@echo "Running go vet..."
$(GOVET) ./...
## Run linting (requires golangci-lint)
lint:
@echo "Running linters..."
@which golangci-lint > /dev/null || (echo "golangci-lint not found. Install it with 'make dev-deps'" && exit 1)
golangci-lint run
## Clean build artifacts
clean:
@echo "Cleaning..."
$(GOCLEAN)
rm -rf $(BUILD_DIR)
rm -f coverage.out coverage.html
## Download dependencies
deps:
@echo "Downloading dependencies..."
$(GOMOD) download
$(GOMOD) tidy
## Install development dependencies
dev-deps:
@echo "Installing development dependencies..."
$(GOGET) github.com/golangci/golangci-lint/cmd/golangci-lint@latest
$(GOGET) github.com/securego/gosec/v2/cmd/gosec@latest
$(GOGET) golang.org/x/vuln/cmd/govulncheck@latest
$(GOGET) mvdan.cc/gofumpt@latest
@echo "Installing kind for integration tests..."
$(GOGET) sigs.k8s.io/kind@latest
## Install the binary to $GOPATH/bin or /usr/local/bin
install: build
@echo "Installing $(BINARY_NAME)..."
@if [ -n "$$GOPATH" ]; then \
echo "Installing to $$GOPATH/bin/"; \
mkdir -p "$$GOPATH/bin"; \
cp $(BUILD_DIR)/$(BINARY_NAME) "$$GOPATH/bin/"; \
elif [ -w "/usr/local/bin" ]; then \
echo "Installing to /usr/local/bin/"; \
cp $(BUILD_DIR)/$(BINARY_NAME) /usr/local/bin/; \
else \
echo "Cannot install to system directories. Try:"; \
echo " sudo make install-system"; \
echo " or"; \
echo " make install-user"; \
exit 1; \
fi
@echo "$(BINARY_NAME) installed successfully!"
## Install the binary to /usr/local/bin (requires sudo)
install-system: build
@echo "Installing $(BINARY_NAME) to /usr/local/bin/ (requires sudo)..."
sudo cp $(BUILD_DIR)/$(BINARY_NAME) /usr/local/bin/
@echo "$(BINARY_NAME) installed successfully!"
## Install the binary to ~/.local/bin (user-local)
install-user: build
@echo "Installing $(BINARY_NAME) to ~/.local/bin/..."
@mkdir -p ~/.local/bin
cp $(BUILD_DIR)/$(BINARY_NAME) ~/.local/bin/
@echo "$(BINARY_NAME) installed to ~/.local/bin/"
@echo "Make sure ~/.local/bin is in your PATH. Add this to your shell profile:"
@echo " export PATH=\"\$$HOME/.local/bin:\$$PATH\""
## Run the binary (for quick testing)
run:
@echo "Running $(BINARY_NAME)..."
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) . && $(BUILD_DIR)/$(BINARY_NAME)
## Run cluster command (for testing)
run-cluster:
@echo "Running $(BINARY_NAME) cluster..."
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) . && $(BUILD_DIR)/$(BINARY_NAME) cluster --verbose
## Setup test cluster with kind
test-cluster-setup:
@echo "Setting up test cluster with kind..."
@which kind > /dev/null || (echo "kind not found. Install it with 'make dev-deps'" && exit 1)
kind create cluster --name kdebug-test --wait 60s
@echo "Test cluster ready. Use: export KUBECONFIG=$$(kind get kubeconfig --name kdebug-test)"
## Cleanup test cluster
test-cluster-cleanup:
@echo "Cleaning up test cluster..."
kind delete cluster --name kdebug-test
## Run full test suite (unit + integration)
test-all: test test-integration
## Run security checks
security:
@echo "Running security checks..."
@which gosec > /dev/null || $(GOGET) github.com/securego/gosec/v2/cmd/gosec@latest
$(shell go env GOPATH)/bin/gosec ./...
@echo "Running vulnerability check..."
@which govulncheck > /dev/null || $(GOGET) golang.org/x/vuln/cmd/govulncheck@latest
$(shell go env GOPATH)/bin/govulncheck ./...
## Run all quality checks
quality: fmt vet lint security test-coverage
## Create release build
release: clean quality build-all
@echo "Release build completed"
## Format code with gofumpt
fmt-gofumpt:
@echo "Formatting code with gofumpt..."
@which gofumpt > /dev/null || $(GOGET) mvdan.cc/gofumpt@latest
$(shell go env GOPATH)/bin/gofumpt -w .
## Run pre-push validation
pre-push:
@echo "Running pre-push validation..."
./scripts/pre-push.sh
## Local integration testing
test-integration-local:
@echo "Running local integration tests (full suite)..."
./scripts/test-integration-local.sh
## Local integration testing (skip cluster tests - faster)
test-integration-local-skip:
@echo "Running local integration tests (skipping cluster creation)..."
SKIP_INTEGRATION_TESTS=true ./scripts/test-integration-local.sh
## Quick local testing
test-quick:
@echo "Running quick local tests..."
./scripts/test-quick-local.sh
## Test everything locally (quick + integration)
test-local-all: test-quick test-integration-local
## Check if local environment is ready for integration tests
check-integration-env:
@echo "Checking integration test environment..."
@command -v kind >/dev/null || (echo "❌ kind not found. Install with: go install sigs.k8s.io/kind@latest" && exit 1)
@command -v kubectl >/dev/null || (echo "❌ kubectl not found. Please install kubectl" && exit 1)
@docker info >/dev/null || (echo "❌ Docker not running. Please start Docker" && exit 1)
@echo "✅ Integration test environment is ready"
## Show help
help:
@echo "Available targets:"
@echo " build - Build the binary"
@echo " build-all - Build for all platforms"
@echo " test - Run unit tests"
@echo " test-coverage - Run tests with coverage report"
@echo " test-integration - Run integration tests"
@echo " test-e2e - Run end-to-end tests"
@echo " test-all - Run all tests (unit + integration)"
@echo " test-cluster-setup - Setup test cluster with kind"
@echo " test-cluster-cleanup - Cleanup test cluster"
@echo " fmt - Format code"
@echo " vet - Run go vet"
@echo " lint - Run linters"
@echo " security - Run security checks"
@echo " quality - Run all quality checks"
@echo " clean - Clean build artifacts"
@echo " deps - Download dependencies"
@echo " dev-deps - Install development dependencies"
@echo " install - Install binary (auto-detect location)"
@echo " install-system - Install binary to /usr/local/bin (requires sudo)"
@echo " install-user - Install binary to ~/.local/bin"
@echo " run - Build and run the binary"
@echo " run-cluster - Build and run cluster command"
@echo " fmt-gofumpt - Format code with gofumpt"
@echo " pre-push - Run pre-push validation"
@echo " test-quick - Run quick local tests (build, format, unit, lint)"
@echo " test-integration-local - Run full local integration tests with Kind"
@echo " test-local-all - Run all local tests (quick + integration)"
@echo " check-integration-env - Check if integration test environment is ready"
@echo " local-ci - Run full local CI in Docker (mirrors GitHub Actions)"
@echo " local-ci-quick - Run quick local CI checks (tests + lint only)"
@echo " local-ci-build - Build Docker CI image"
@echo " release - Create release build"
@echo " help - Show this help"
## Local CI Commands
## Run complete local CI in Docker (mirrors GitHub Actions)
local-ci:
@echo "🚀 Running complete local CI in Docker..."
./scripts/local-ci.sh --full
## Run quick local CI checks (tests + lint only)
local-ci-quick:
@echo "⚡ Running quick local CI checks..."
./scripts/local-ci.sh --quick
## Build Docker CI image
local-ci-build:
@echo "🔨 Building Docker CI image..."
docker build -f Dockerfile.ci -t kdebug-ci:latest .
## Run local CI without tests (lint, build, security only)
local-ci-no-tests:
@echo "🔧 Running local CI without tests..."
./scripts/local-ci.sh --no-tests
## Run local CI with verbose output
local-ci-verbose:
@echo "📝 Running local CI with verbose output..."
./scripts/local-ci.sh --verbose --full
## Website Development Targets
## Install Jekyll dependencies for website development
website-deps:
@echo "💎 Installing Jekyll dependencies..."
@if ! command -v ruby >/dev/null 2>&1; then \
echo "❌ Ruby is not installed. Please install Ruby first."; \
echo " macOS: brew install ruby"; \
echo " Linux: sudo apt-get install ruby-full"; \
exit 1; \
fi
@if ! command -v bundle >/dev/null 2>&1; then \
echo "💎 Installing bundler..."; \
gem install bundler; \
fi
@echo "📦 Installing Jekyll and dependencies..."
bundle install
@echo "✅ Jekyll dependencies installed"
## Serve website locally for development
website-serve: website-deps
@echo "🌐 Starting Jekyll development server..."
@echo "📍 Website will be available at: http://localhost:4000"
bundle exec jekyll serve --livereload --drafts
## Build website for production
website-build: website-deps
@echo "🏗️ Building website for production..."
bundle exec jekyll build
@echo "✅ Website built in _site/ directory"
## Clean website build artifacts
website-clean:
@echo "🧹 Cleaning website build artifacts..."
@rm -rf _site .jekyll-cache .sass-cache
@echo "✅ Website artifacts cleaned"
## Check website for broken links and issues
website-check: website-build
@echo "🔍 Checking website for issues..."
@if command -v htmlproofer >/dev/null 2>&1; then \
htmlproofer ./_site --check-html --check-links --assume-extension; \
else \
echo "⚠️ htmlproofer not installed. Install with: gem install html-proofer"; \
echo "💡 Basic build check completed successfully"; \
fi
## Install website checking tools
website-check-deps:
@echo "🔧 Installing website checking tools..."
gem install html-proofer
@echo "✅ Website checking tools installed"
## Development workflow: clean, build, and serve website
website-dev: website-clean website-serve
## Production workflow: clean, build, and check website
website-prod: website-clean website-build website-check
## Show website development help
website-help:
@echo "🌐 Website Development Commands:"
@echo ""
@echo " website-deps Install Jekyll dependencies"
@echo " website-serve Start local development server"
@echo " website-build Build website for production"
@echo " website-clean Clean build artifacts"
@echo " website-check Check for broken links and issues"
@echo " website-dev Clean + serve (development workflow)"
@echo " website-prod Clean + build + check (production workflow)"
@echo ""
@echo "🔧 Setup Commands:"
@echo " website-check-deps Install website checking tools"
@echo ""
@echo "📍 Local development URL: http://localhost:4000"
@echo "🔄 Live reload enabled during development"