-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
72 lines (55 loc) · 3.04 KB
/
Copy pathMakefile
File metadata and controls
72 lines (55 loc) · 3.04 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
.PHONY: help build test vet fmt lint tidy check run run-bwrap linux smoke image image-lean image-multiarch clean
BIN := bin/hostel
ADDR := :8872
WS_ROOT := ./.workspace
IMAGE := hostel:dev
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
PLATFORMS := linux/amd64,linux/arm64
help: ## List available targets
@grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-12s\033[0m %s\n", $$1, $$2}'
build: ## Build the hostel binary for the current platform
go build -o $(BIN) ./cmd/hostel
# -race is non-negotiable here: shells, bed lifecycle and cas uploads are all
# concurrent; -count=1 keeps the detector from being skipped by the test cache.
test: ## Run all tests with the race detector
go test -race -count=1 ./...
vet: ## Run go vet
go vet ./...
fmt: ## Format all Go sources
gofmt -w .
lint: vet ## gofmt check + go vet (CI gate)
@out=$$(gofmt -l .); if [ -n "$$out" ]; then echo "gofmt needed on:"; echo "$$out"; exit 1; fi
tidy: ## Sync go.mod/go.sum
go mod tidy
check: tidy lint build test ## Pre-commit gate: tidy + lint + build + race tests
@echo "check passed"
run: build ## Run locally with no isolation (dev, any platform)
$(BIN) --isolation dorm --workspace-root $(WS_ROOT) --addr $(ADDR)
run-bwrap: build ## Run at suite level = bwrap (Linux with bubblewrap installed)
$(BIN) --isolation suite --workspace-root $(WS_ROOT) --addr $(ADDR)
linux: ## Cross-compile static Linux binaries (amd64 + arm64) into bin/
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/hostel-linux-amd64 ./cmd/hostel
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o bin/hostel-linux-arm64 ./cmd/hostel
smoke: build ## Boot on a scratch port and curl the core endpoints end to end
@set -e; \
tmp=$$(mktemp -d); \
$(BIN) --isolation dorm --workspace-root $$tmp/ws --addr :44799 & pid=$$!; \
trap "kill $$pid 2>/dev/null; rm -rf $$tmp" EXIT; \
sleep 1; \
curl -sf localhost:44799/ping >/dev/null; \
curl -sf localhost:44799/healthz >/dev/null; \
curl -sfN -XPOST localhost:44799/command -H 'Content-Type: application/json' \
-d '{"command":"echo smoke > s.txt && cat s.txt"}' | grep -q smoke; \
curl -sf 'localhost:44799/files/download?path=/workspace/s.txt' | grep -q smoke; \
curl -sf -o /dev/null -w '%{http_code}' 'localhost:44799/files/download?path=/workspace/s.txt' \
-H 'X-Hostel-Bed: other' | grep -q 404; \
echo "smoke OK"
image: ## Build the container image (bwrap + chromium)
docker build -f deploy/docker/Dockerfile -t $(IMAGE) --build-arg VERSION=$(VERSION) .
image-lean: ## Build the lean image (bwrap only, no browser amenity)
docker build -f deploy/docker/Dockerfile -t $(IMAGE)-lean --build-arg VERSION=$(VERSION) --build-arg WITH_CHROMIUM=false .
image-multiarch: ## Build + push a multi-arch image (needs buildx + a registry; set IMAGE=repo/name:tag)
docker buildx build -f deploy/docker/Dockerfile --platform $(PLATFORMS) \
-t $(IMAGE) --build-arg VERSION=$(VERSION) --push .
clean: ## Remove build artifacts and the dev workspace
rm -rf bin .workspace