Repository navigation
Expand file tree
/
Copy pathmakefile
More file actions
653 lines (577 loc) · 28.6 KB
/
Copy pathmakefile
File metadata and controls
653 lines (577 loc) · 28.6 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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
PKG := github.com/thushan/olla/internal/version
RUNTIME := Go v$(shell go version | awk '{print $$3}' | sed 's/go//')
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "v0.0.0-dev")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "none")
DATE := $(shell date +%Y-%m-%dT%H:%M:%S%z)
USER := $(shell git config user.name 2>/dev/null || whoami)
TOOL := "make"
# Tool versions (pinned)
GOLANGCI_LINT_VERSION := v2.15.0
BETTERALIGN_VERSION := v0.16.1
BUN_VERSION := 1.3.5
# Lint tools live in a repo-local, gitignored .bin so each checkout runs its
# own pinned versions and never reads or writes the shared GOPATH/bin.
TOOLS_BIN := $(CURDIR)/.bin
GOEXE := $(shell go env GOEXE)
GOLANGCI_LINT := $(TOOLS_BIN)/golangci-lint$(GOEXE)
BETTERALIGN := $(TOOLS_BIN)/betteralign$(GOEXE)
# tool-version <binary>: module version recorded in the binary's build info.
tool-version = $$(go version -m "$(1)" 2>/dev/null | awk '$$1=="mod"{print $$3}')
# tool-gover <binary>: Go toolchain the binary was built with (the first line
# of `go version -m` is "<path>: goX.Y.Z").
tool-gover = $$(go version -m "$(1)" 2>/dev/null | awk 'NR==1{print $$2}')
# ensure-tool <name> <binary> <version> <module>: reinstall on a module or
# build-Go mismatch. The Go check matters after a go.mod bump, because
# golangci-lint refuses to lint a module needing a newer Go than it was built with.
define ensure-tool
have="$(call tool-version,$(2))"; \
gohave="$(call tool-gover,$(2))"; \
if [ "$$have" != "$(3)" ] || [ "$$gohave" != "$$(go env GOVERSION)" ]; then \
echo " Installing $(1) $(3) into $(TOOLS_BIN) (found: $${have:-none} $${gohave})..."; \
GOBIN="$(TOOLS_BIN)" go install $(4)@$(3) || exit 1; \
fi
endef
# Frontend locations. WEB_DIR is the Svelte source tree; EMBED_DIST is the
# go:embed source the binary ships. It is gitignored and regenerated at build
# time by build-web; only a .gitkeep sentinel stays committed so a fresh
# checkout compiles without Bun.
WEB_DIR := web/dashboard
EMBED_DIST := internal/app/handlers/dashboard/dist
# Sentinel proving build-web actually populated the embed (see build-web).
EMBED_INDEX := index.html
LDFLAGS := -ldflags "\
-X '$(PKG).Version=$(VERSION)' \
-X '$(PKG).Runtime=$(RUNTIME)' \
-X '$(PKG).Commit=$(COMMIT)' \
-X '$(PKG).Date=$(DATE)' \
-X '$(PKG).Tool=$(TOOL)' \
-X '$(PKG).User=$(USER)'"
.PHONY: ensure-golangci-lint ensure-betteralign smoke-build-local run clean build test test-verbose test-short test-race test-cover bench version install-deps check-deps vet test-script-integration test-script-sticky test-auth-bearer test-auth-env-fatal test-auth-manual build-web install-web clean-web lint-web test-web ci-web check-fonts-web
# Build the application with version info. Depends on build-web so the binary
# always embeds the current frontend; this is where the "build fresh every
# time" guarantee is enforced for plain go builds.
build: build-web
@echo "Building olla $(VERSION)..."
@go build $(LDFLAGS) -o bin/olla .
# Build release version (optimised). build-web first for the same reason.
build-release: build-web
@echo "Building olla $(VERSION) for release..."
@mkdir -p bin
@CGO_ENABLED=0 go build $(LDFLAGS) -a -installsuffix cgo -o bin/olla$(shell go env GOEXE) .
# Platform-specific validation (used by CI - builds both archs for current OS but runs only AMD64)
validate-linux:
@echo "Building and testing Linux binaries..."
@mkdir -p bin
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o bin/olla-linux-amd64 .
@CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o bin/olla-linux-arm64 .
@echo "Testing Linux AMD64 binary..."
@bin/olla-linux-amd64 --version > /dev/null && echo "Linux AMD64: OK"
@echo "Testing Linux ARM64 binary..."
@if bin/olla-linux-arm64 --version > /dev/null 2>&1; then \
echo "Linux ARM64: OK (tested via QEMU)"; \
else \
echo "Linux ARM64: Build OK (runtime test failed/skipped)"; \
fi
@rm -f bin/olla-linux-*
validate-darwin:
@echo "Building and testing macOS binaries..."
@mkdir -p bin
@CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o bin/olla-darwin-amd64 .
@CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o bin/olla-darwin-arm64 .
@echo "Testing macOS binary..."
@if [ "$$(uname -m)" = "arm64" ]; then \
bin/olla-darwin-arm64 --version > /dev/null && echo "Darwin ARM64: OK"; \
echo "AMD64 build: OK (compile-only)"; \
else \
bin/olla-darwin-amd64 --version > /dev/null && echo "Darwin AMD64: OK"; \
echo "ARM64 build: OK (compile-only)"; \
fi
@rm -f bin/olla-darwin-*
validate-windows:
@echo "Building and testing Windows binaries..."
@mkdir -p bin
@CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o bin/olla-windows-amd64.exe .
@CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build $(LDFLAGS) -o bin/olla-windows-arm64.exe .
@echo "Testing Windows AMD64 binary..."
@bin/olla-windows-amd64.exe --version > /dev/null && echo "Windows AMD64: OK"
@echo "ARM64 build: OK (compile-only)"
@rm -f bin/olla-windows-*
# Validate all platforms (for local testing or releases - builds all 6 targets)
#
# Platform Support Matrix:
# OS | AMD64 | ARM64 |
# ---------|-------|-------|
# Linux | ✓ | ✓ |
# macOS | ✓ | ✓ | (ARM64 = Apple Silicon M1/M2/M3)
# Windows | ✓ | ✓ | (ARM64 = Windows on ARM devices)
#
# This target builds all combinations but does NOT test execution
# Use the OS-specific targets (validate-linux, etc) to test execution
validate-all-platforms:
@echo "Building all platforms (6 targets)..."
@mkdir -p bin
@echo "Linux AMD64..."
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o bin/olla-linux-amd64 .
@echo "Linux ARM64..."
@CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o bin/olla-linux-arm64 .
@echo "macOS AMD64 (Intel)..."
@CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o bin/olla-darwin-amd64 .
@echo "macOS ARM64 (Apple Silicon)..."
@CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o bin/olla-darwin-arm64 .
@echo "Windows AMD64..."
@CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o bin/olla-windows-amd64.exe .
@echo "Windows ARM64..."
@CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build $(LDFLAGS) -o bin/olla-windows-arm64.exe .
@echo "All platforms built successfully (6 targets)"
@rm -f bin/olla-*
# Run the application. Depends on build-web so the embedded dashboard is
# regenerated; without it the embed carries only the .gitkeep sentinel and
# serves a 503 not-built response.
run: build-web
@go run $(LDFLAGS) .
# Run with debug logging
run-debug: build-web
@OLLA_LOG_LEVEL=debug go run $(LDFLAGS) .
# Run tests
test:
@echo "Running tests..."
@go test ./...
# Run tests with verbose output
test-verbose:
@echo "Running tests with verbose output..."
@go test -v ./...
# Run tests with short flag
test-short:
@echo "Running short tests..."
@go test -short ./...
# Run tests with race detection
test-race:
@echo "Running tests with race detection..."
@go test -race -short ./...
# Run tests with race detection and a coverage profile. Same test selection as
# test-race - this only adds -coverprofile so CI can feed coverage.out to
# Codecov without running the suite twice.
test-race-cover:
@echo "Running tests with race detection and coverage..."
@go test -race -short -coverprofile=coverage.out ./...
# Run tests with coverage
test-cover:
@echo "Running tests with coverage..."
@go test -cover ./...
# Run stress tests (comprehensive testing)
test-stress:
@echo "Running comprehensive stress tests..."
@go test -v ./... -run "Stress"
# Run tests with coverage profile and generate HTML report
test-cover-html:
@echo "Running tests with coverage and generating HTML report..."
@go test -coverprofile=coverage.out ./...
@go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Run benchmark tests
bench:
@echo "Running benchmarks..."
@go test -bench=. -benchmem ./...
# Run repository benchmarks
bench-repo:
@echo "Running repository benchmarks..."
@go test -bench=BenchmarkRepository -benchmem ./internal/adapter/discovery/
# Run balancer benchmarks
bench-balancer:
@echo "Running balancer benchmarks..."
@go test -bench=BenchmarkFactory -benchmem ./internal/adapter/balancer/
@go test -bench=BenchmarkPriority -benchmem ./internal/adapter/balancer/
@go test -bench=BenchmarkRoundRobin -benchmem ./internal/adapter/balancer/
@go test -bench=BenchmarkLeastConnections -benchmem ./internal/adapter/balancer/
# Show version information that would be embedded
version:
@echo "Version: $(VERSION)"
@echo "Commit: $(COMMIT)"
@echo "Date: $(DATE)"
@echo "User: $(USER)"
# Show embedded version from built binary
version-built: build
@./bin/olla --version 2>/dev/null || echo "Add --version flag to main.go to see embedded version"
# Clean build artifacts and logs
clean: clean-web
@rm -rf bin/ build/ dist/ logs/ coverage.out coverage.html
# Download dependencies
deps:
@go mod download && go mod tidy
ready-tools: fmt vet lint align
@echo -e "\033[32mCode is clean for tests!\033[0m"
# Make code ready for commit (test, test-race, fmt, vet, lint, align)
ready: test-short test-race fmt vet lint align
@echo -e "\033[32mCode is ready for commit!\033[0m"
# Build binaries only (no archives) to ./build directory. --output names the binary file:
# the goreleaser before-hooks make build/ a directory, so a bare ./build/ collides with it.
build-local:
@echo "Building local binaries to ./build/..."
@goreleaser build --snapshot --clean --single-target --output ./build/olla$(shell go env GOEXE)
@echo "Binary created: ./build/olla$(shell go env GOEXE)"
# Prove build-local works from a clean and a pre-populated build/ (needs goreleaser and bun).
# Deletes ./build, so it needs OLLA_SMOKE_OK=1 and belongs in a scratch worktree.
smoke-build-local:
@./scripts/smoke-build-local.sh
# Build full snapshot release (with archives) to ./dist directory
build-snapshot:
@echo "Building full snapshot release to ./dist/..."
@goreleaser release --snapshot --clean
@echo "Release artifacts in ./dist/"
# Deprecated: use build-local or build-snapshot instead
ready-local: build-snapshot
DOCKER_ARCH ?= amd64
# Build Docker image without goreleaser (for local development)
docker-build-local: build-web
@echo "Building Docker image locally (without goreleaser) for $(DOCKER_ARCH)..."
@echo "Building olla binary to root..."
@CGO_ENABLED=0 GOOS=linux GOARCH=$(DOCKER_ARCH) go build $(LDFLAGS) -o olla .
@echo "Staging docker-flavoured config (mirrors the goreleaser before-hook)..."
@bash ./scripts/generate-container-config.sh
@mkdir -p build
@cp config/docker.yaml build/docker-config.yaml
@echo "Building Docker image..."
@docker build -t ghcr.io/thushan/olla:local-$(DOCKER_ARCH) .
@echo "Cleaning up binary..."
@rm -f olla
@echo "Docker image built: ghcr.io/thushan/olla:local-$(DOCKER_ARCH)"
@docker images --filter reference='*olla*local*'
# Build Docker image for ARM64 (convenience target)
docker-build-local-arm64:
@$(MAKE) docker-build-local DOCKER_ARCH=arm64
# Build and test Docker image locally
docker-build:
@if ! command -v goreleaser > /dev/null 2>&1; then \
echo "❌ goreleaser not found. Use 'make docker-build-local' instead (no goreleaser required)"; \
exit 1; \
fi
@echo "Building Docker image locally..."
@goreleaser release --snapshot --clean --skip=publish,announce,sign,sbom
@echo "Docker images:"
@docker images | grep olla | head -5
# Run Docker image with local config (defaults to amd64)
docker-run:
@echo "Running Docker image with local config (amd64)..."
@docker run --rm -it \
-p 40114:40114 \
-v "$(shell pwd)/config/config.local.yaml:/config/config.yaml:ro" \
-e OLLA_CONFIG_FILE=/config/config.yaml \
ghcr.io/thushan/olla:local-amd64
# Test full release locally (binaries + docker + archives)
release-test:
@echo "Testing full release locally..."
@goreleaser release --snapshot --clean
@echo "Release artifacts in ./dist/"
@echo "Docker images:"
@docker images | grep olla | head -5
# Test goreleaser configuration
goreleaser-check:
@echo "Checking goreleaser configuration..."
@goreleaser check
# ── Frontend (dashboard SPA) ──────────────────────────────────────────────────
# The dashboard dist is gitignored and built fresh whenever a binary is
# produced: build, build-release, docker-build-local, run, run-debug and dev
# depend on build-web, and goreleaser runs build-web via its before.hooks
# (covering build-local, build-snapshot and release). test, vet, lint, align
# and ready stay Bun-free: a committed .gitkeep sentinel keeps //go:embed
# non-empty so a fresh checkout compiles, and the embed handler serves a loud
# 503 if a binary was built without the SPA.
# Install frontend deps (bun install). Requires Bun 1.3.5+ (pinned above as BUN_VERSION).
install-web:
@echo "Installing frontend dependencies (bun install --frozen-lockfile)..."
@cd $(WEB_DIR) && bun install --frozen-lockfile
@echo "Frontend dependencies installed."
# Build the SPA. Vite's outDir points straight at the gitignored go:embed
# source (see vite.config.js), so there is no separate rm/cp/touch copy step
# any more. A writeBundle plugin hook in vite.config.js restores the
# .gitkeep sentinel emptyOutDir wipes on every build.
build-web: install-web
@echo "Building frontend into embed source..."
@cd $(WEB_DIR) && bun run build
@# A vite outDir that stops pointing at EMBED_DIST still exits 0, and the
@# binary would then embed only .gitkeep and serve a 503 dashboard - which
@# no Go test catches, since they run against the unbuilt sentinel. Fail
@# the build here rather than ship it.
@if [ ! -f "$(EMBED_DIST)/$(EMBED_INDEX)" ]; then \
echo "build-web: $(EMBED_DIST)/$(EMBED_INDEX) missing after 'bun run build' - check vite.config.js outDir; refusing to embed an empty dashboard"; \
exit 1; \
fi
@echo "Embed source regenerated (gitignored). Rebuild the binary to embed it."
# Run svelte-check (type/syntax checks) on the SPA.
lint-web: install-web
@echo "Running svelte-check..."
@cd $(WEB_DIR) && bun run check
# Run vitest unit tests on the SPA.
test-web: install-web
@echo "Running frontend tests..."
@cd $(WEB_DIR) && bun run test
# Remove Vite's cache and the generated embed source (leaving only the
# committed .gitkeep sentinel behind). Vite now writes straight into
# $(EMBED_DIST) (see build-web), so there is no separate $(WEB_DIR)/dist to
# clean any more.
clean-web:
@echo "Cleaning frontend ephemeral build output..."
@rm -rf $(WEB_DIR)/node_modules/.cache $(WEB_DIR)/coverage
@rm -rf $(EMBED_DIST)/*
@touch $(EMBED_DIST)/.gitkeep
@echo "Frontend ephemeral output and embed source cleaned."
# Guard against a repeat of the corrupt-font incident: a saved HTML error
# page committed in place of a real .woff2 (wrong bytes, but a plausible
# file size, so it passes casual review). Every .woff2 under the frontend
# source and the built embed dist must start with the WOFF2 magic
# (hex 774f4632 / ASCII "wOF2"), or CI fails loudly instead of shipping a
# font that silently falls back to a system sans in every browser.
check-fonts-web: build-web
@echo "Checking .woff2 files start with the WOFF2 magic bytes..."
@fail=0; \
for f in $$(find $(WEB_DIR)/src $(EMBED_DIST) -name '*.woff2' 2>/dev/null); do \
magic=$$(od -An -tx1 -N4 "$$f" | tr -d ' \n'); \
if [ "$$magic" != "774f4632" ]; then \
printf "\033[31m%s is not a WOFF2 file (magic: %s)\033[0m\n" "$$f" "$$magic"; \
fail=1; \
fi; \
done; \
if [ $$fail -eq 1 ]; then \
echo "One or more .woff2 files are corrupt or not actually fonts."; \
exit 1; \
else \
printf "\033[32mAll .woff2 files are genuine WOFF2.\033[0m\n"; \
fi
# CI web gate: the SPA builds cleanly, its unit tests and type checks pass,
# and every shipped font is a genuine WOFF2. The dist is gitignored, so there
# is no committed-output staleness to check; a successful build-web is the
# freshness signal. test-web, lint-web and build-web all depend on install-web,
# so a clean checkout gets node_modules installed once (Make runs a shared
# prerequisite only once per invocation) before any of the three run, and a
# broken component still fails fast without waiting on the Vite build.
# Deliberately NOT a dependency of `ready`: a fresh clone with no Bun
# toolchain must still pass the Go gate, so these only run from `ci`/`ci-web`
# and the GitHub Actions workflow.
ci-web: test-web lint-web build-web check-fonts-web
@printf "\033[32mDashboard builds, tests, type-checks and fonts are valid.\033[0m\n"
# Format code
fmt:
@echo "Running go fmt..."
@go fmt ./...
@echo "Running go fmt...Done!"
# Run go vet
vet:
@echo "Running go vet..."
@go vet ./...
@echo "Running go vet...Done!"
# Run linter
lint: ensure-golangci-lint
@echo "Running golangci-lint..."
@printf " Version: %s \033[32m(verified)\033[0m\n" "$(call tool-version,$(GOLANGCI_LINT))"
@"$(GOLANGCI_LINT)" run --fix
@echo "Running golangci-lint...Done!"
# Run betteralign
align: ensure-betteralign
@echo "Running better-align..."
@printf " Version: %s \033[32m(verified)\033[0m\n" "$(call tool-version,$(BETTERALIGN))"
@"$(BETTERALIGN)" -apply ./...
@echo "Running better-align...Done!"
# Run betteralign in check-only mode (no -apply). CI uses this instead of
# align - a passing build must mean the committed code is already aligned,
# not that this run silently patched it in a workspace nothing commits from.
align-check: ensure-betteralign
@echo "Running better-align (check only)..."
@printf " Version: %s \033[32m(verified)\033[0m\n" "$(call tool-version,$(BETTERALIGN))"
@output=$$("$(BETTERALIGN)" ./... 2>&1); status=$$?; \
if [ $$status -ne 0 ] || [ -n "$$output" ]; then \
echo "Struct alignment check failed (exit $$status):"; \
echo "$$output"; \
exit 1; \
fi
@echo "Running better-align (check only)...Done!"
# Install a repo-local tool unless the binary already reports the pinned
# version. Reading the version off the exact binary we then run means the
# printed version and the executed version cannot diverge.
ensure-golangci-lint:
@$(call ensure-tool,golangci-lint,$(GOLANGCI_LINT),$(GOLANGCI_LINT_VERSION),github.com/golangci/golangci-lint/v2/cmd/golangci-lint)
ensure-betteralign:
@$(call ensure-tool,betteralign,$(BETTERALIGN),$(BETTERALIGN_VERSION),github.com/dkorunic/betteralign/cmd/betteralign)
# Install dependencies at pinned versions
install-deps: ensure-golangci-lint ensure-betteralign
@echo "Installing dependencies..."
@echo "Checking Bun toolchain (needed for build-web / install-web)..."
@if command -v bun > /dev/null 2>&1; then \
INSTALLED=$$(bun --version 2>/dev/null); \
MAJOR=$$(echo $$INSTALLED | cut -d. -f1); \
MINOR=$$(echo $$INSTALLED | cut -d. -f2); \
REQ_MAJOR=$$(echo "$(BUN_VERSION)" | cut -d. -f1); \
REQ_MINOR=$$(echo "$(BUN_VERSION)" | cut -d. -f2); \
if [ "$$MAJOR" -gt "$$REQ_MAJOR" ] || ([ "$$MAJOR" -eq "$$REQ_MAJOR" ] && [ "$$MINOR" -ge "$$REQ_MINOR" ]); then \
printf " bun: %s \033[32m(verified)\033[0m\n" "$$INSTALLED"; \
else \
printf " bun: %s [require: %s+ \033[31m(pinned)\033[0m]\n" "$$INSTALLED" "$(BUN_VERSION)"; \
echo " Install Bun $(BUN_VERSION)+ via https://bun.sh"; \
fi; \
else \
printf " bun: not installed [require: %s+ \033[31m(pinned)\033[0m]\n" "$(BUN_VERSION)"; \
echo " Install Bun $(BUN_VERSION)+ via https://bun.sh"; \
fi
@echo "Dependencies installed successfully!"
# Check installed tool versions against requirements
check-deps:
@echo "Checking dependencies..."
@rc=0; for t in "golangci-lint:$(GOLANGCI_LINT):$(GOLANGCI_LINT_VERSION)" "betteralign:$(BETTERALIGN):$(BETTERALIGN_VERSION)"; do \
name=$${t%%:*}; rest=$${t#*:}; bin=$${rest%:*}; want=$${rest##*:}; \
have=$$(go version -m "$$bin" 2>/dev/null | awk '$$1=="mod"{print $$3}'); \
if [ "$$have" = "$$want" ]; then \
printf " %s: %s \033[32m(verified)\033[0m\n" "$$name" "$$have"; \
elif [ -z "$$have" ]; then \
printf " %s: not installed [require: %s \033[31m(pinned)\033[0m] - run 'make install-deps'\n" "$$name" "$$want"; rc=1; \
else \
printf " %s: %s [require: %s \033[31m(pinned)\033[0m] - run 'make install-deps'\n" "$$name" "$$have" "$$want"; rc=1; \
fi; \
done; \
if command -v bun > /dev/null 2>&1; then \
INSTALLED=$$(bun --version 2>/dev/null); \
MAJOR=$$(echo $$INSTALLED | cut -d. -f1); \
MINOR=$$(echo $$INSTALLED | cut -d. -f2); \
REQ_MAJOR=$$(echo "$(BUN_VERSION)" | cut -d. -f1); \
REQ_MINOR=$$(echo "$(BUN_VERSION)" | cut -d. -f2); \
if [ "$$MAJOR" -gt "$$REQ_MAJOR" ] || ([ "$$MAJOR" -eq "$$REQ_MAJOR" ] && [ "$$MINOR" -ge "$$REQ_MINOR" ]); then \
printf " bun: %s \033[32m(verified)\033[0m\n" "$$INSTALLED"; \
else \
printf " bun: %s [require: %s+ \033[31m(pinned)\033[0m]\n" "$$INSTALLED" "$(BUN_VERSION)"; \
fi \
else \
printf " bun: not installed [require: %s+ \033[31m(pinned)\033[0m]\n" "$(BUN_VERSION)"; \
fi; \
exit $$rc
# Development build (no optimisations). build-web first so the dashboard
# embed is fresh; see run/run-debug for the same reason.
dev: build-web
@echo "Building development version..."
@go build $(LDFLAGS) -gcflags="all=-N -l" -o bin/olla-dev .
# Run full CI pipeline locally. ci-web is included here (not in `ready`) so
# `make ci` matches what the GitHub Actions workflow gates on; ready stays
# Bun-free for a fresh clone with no Bun toolchain. test-race-cover replaces
# the old test-race + test-cover pair (same test-race selection, one run
# instead of two, and it produces the coverage.out CI uploads to Codecov).
# `test` runs alongside it (no -short) so testing.Short()-gated tests -
# stress and slow-shutdown cases skipped under -short - execute in at least
# one gate; race-detection on the -short-eligible suite still comes from
# test-race-cover.
ci: deps fmt vet lint align-check test test-race-cover build ci-web
@echo "CI pipeline completed successfully!"
# Docker compose up with local config
docker-compose:
@echo "Starting with docker-compose..."
@docker-compose up
# Run integration test scripts (requires running Olla instance)
test-script-integration:
@echo "Running integration test scripts..."
@cd test/scripts && python integration/test-integration.py $(ARGS)
## test-script-sticky: Run sticky session test scripts (requires running Olla instance)
test-script-sticky:
@echo "Running sticky session test scripts..."
@cd test/scripts && python sticky/test-sticky-sessions.py $(ARGS)
# ── AIMock helpers ────────────────────────────────────────────────────────────
# These targets manage the three AIMock containers used by the sticky session
# manual test harness. AIMock (ghcr.io/copilotkit/aimock) serves OpenAI and
# Anthropic endpoints with embedded BACKEND:<id> markers so affinity tests can
# confirm which instance handled each response.
#
# Ports: mock-instance-a=9300, mock-instance-b=9301, mock-instance-c=9302
.PHONY: mock-up mock-down mock-status mock-logs
## mock-up: Start AIMock instances and wait until all are healthy
mock-up:
@echo "Starting AIMock instances..."
@docker compose -f test/mock/compose.yaml up -d --wait --wait-timeout 40
@echo "All 3 AIMock instances are healthy"
## mock-down: Stop and remove AIMock containers and volumes
mock-down:
@echo "Stopping AIMock instances..."
@docker compose -f test/mock/compose.yaml down -v
## mock-status: Show running state of AIMock instances
mock-status:
@docker compose -f test/mock/compose.yaml ps
## mock-logs: Tail logs from all three AIMock instances
mock-logs:
@docker compose -f test/mock/compose.yaml logs -f
# ── Auth test helpers ─────────────────────────────────────────────────────────
# These targets run the auth integration scripts that prove outbound credential
# injection works end-to-end against the Go mock backend (test/cmd/mockbackend).
# No Docker or AIMock required; the scripts spin up the mock backend in-process.
## test-auth-bearer: Bearer token injection end-to-end (happy + failure paths)
test-auth-bearer:
@echo "Running bearer auth integration test..."
@bash test/scripts/auth/auth-bearer.sh
## test-auth-env-fatal: Missing env var must abort Olla startup with a clear error
test-auth-env-fatal:
@echo "Running env-var-missing fatal startup test..."
@bash test/scripts/auth/auth-env-fatal.sh
## test-auth-manual: Run all auth scripts that do not require Docker
test-auth-manual:
@echo "Running all auth integration tests..."
@bash test/scripts/auth/auth-bearer.sh
@bash test/scripts/auth/auth-api-key.sh
@bash test/scripts/auth/auth-basic.sh
@bash test/scripts/auth/auth-headers-only.sh
@bash test/scripts/auth/auth-env-fatal.sh
# Show help
help:
@echo "Available targets:"
@echo " build - Build optimised binary with version info"
@echo " build-release - Build release binary (static, optimised)"
@echo " run - Run with version info"
@echo " run-debug - Run with debug logging"
@echo " test - Run all tests"
@echo " test-verbose - Run tests with verbose output"
@echo " test-short - Run short tests only"
@echo " test-race - Run tests with race detection"
@echo " test-cover - Run tests with coverage"
@echo " test-stress - Run comprehensive stress tests (may take 30+ seconds)"
@echo " test-cover-html - Run tests with coverage and generate HTML report"
@echo " bench - Run all benchmarks"
@echo " bench-repo - Run repository benchmarks"
@echo " bench-balancer - Run balancer benchmarks"
@echo " version - Show version info that will be embedded"
@echo " version-built - Show version from built binary"
@echo " dev - Build development binary (with debug symbols)"
@echo " clean - Clean build artifacts and logs"
@echo " deps - Download and tidy dependencies"
@echo " ready - Make code ready for commit (test, fmt, vet, lint, align)"
@echo " ready-tools - Check code is ready with tools (fmt, vet, lint, align)"
@echo " validate-linux - Build and test Linux binaries (AMD64 + ARM64)"
@echo " validate-darwin - Build and test macOS binaries (Intel + Apple Silicon)"
@echo " validate-windows- Build and test Windows binaries (AMD64 + ARM64)"
@echo " validate-all-platforms - Build all 6 platform combinations (local testing)"
@echo " build-local - Build binary only to ./build/olla (fast, for testing)"
@echo " smoke-build-local - Check build-local from clean and dirty build/ (OLLA_SMOKE_OK=1)"
@echo " build-snapshot - Build full release to ./dist/ (archives, checksums, etc)"
@echo " docker-build - Build Docker images locally"
@echo " docker-run - Run Docker image with local config"
@echo " docker-compose - Run with docker-compose"
@echo " release-test - Test full release (binaries + docker + archives)"
@echo " goreleaser-check- Check goreleaser configuration"
@echo " fmt - Format code"
@echo " vet - Run go vet static analysis"
@echo " lint - Run linter (requires golangci-lint)"
@echo " align - Run alignment checker (requires betteralign)"
@echo " install-deps - Install dependencies at pinned versions"
@echo " check-deps - Check installed tool versions against requirements"
@echo " ci - Run full CI pipeline locally"
@echo " test-script-integration - Run integration test scripts (requires running Olla)"
@echo " test-script-sticky - Run sticky session test scripts (requires running Olla)"
@echo " mock-up - Start AIMock instances and wait for health"
@echo " mock-down - Stop AIMock instances and remove volumes"
@echo " mock-status - Show AIMock container state"
@echo " mock-logs - Tail logs from all AIMock instances"
@echo " test-auth-bearer - Bearer token injection end-to-end (no Docker needed)"
@echo " test-auth-env-fatal - Missing env var aborts startup with a clear error"
@echo " test-auth-manual - All auth integration scripts (no Docker needed)"
@echo ""
@echo "Frontend:"
@echo " build-web - Build SPA into the gitignored embed source (run by build/release)"
@echo " install-web - Install frontend deps (bun install)"
@echo " clean-web - Remove Vite output, cache, and generated embed source"
@echo " lint-web - Run svelte-check on the SPA"
@echo " test-web - Run vitest unit tests on the SPA"
@echo " check-fonts-web - Fail if any .woff2 is missing the WOFF2 magic bytes"
@echo " ci-web - CI gate: vitest + svelte-check + build + font-integrity (requires Bun; run by 'make ci', not 'make ready')"
@echo ""
@echo " help - Show this help"