-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
170 lines (133 loc) · 6.12 KB
/
Copy pathMakefile
File metadata and controls
170 lines (133 loc) · 6.12 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
.PHONY: run run-debug install-gotestsum test test-report testdox clean install-lint lint lint-fix install-swag swagger build build-debug dockerfile-lint sonar-local e2e-local migrate format-data-json bump-version ha-up ha-down infra-up infra-down
GOTESTSUM := $(shell go env GOPATH)/bin/gotestsum
GOLANGCI_LINT := $(shell go env GOPATH)/bin/golangci-lint
SWAG := $(shell go env GOPATH)/bin/swag
# Keep in sync with github.com/swaggo/swag/v2 in go.mod (CLI + runtime types).
SWAG_VERSION ?= v2.0.0
# Parse API packages explicitly. With multiple -d entries, -g is relative to the first dir (cmd/fuse).
SWAG_DIRS := ./cmd/fuse,./internal/handlers,./internal/dtos,./internal/workflow,./pkg/workflow
run:
go build -o bin/fuse cmd/fuse/main.go
./bin/fuse server -o -p 9090 -l debug
# Install gotestsum into GOPATH/bin (same path as GOTESTSUM)
install-gotestsum:
go install gotest.tools/gotestsum@latest
test: install-gotestsum
$(GOTESTSUM) --junitfile test-report.xml --format testdox -- ./pkg/... ./internal/... ./tests/...
# Functional tests against a real PostgreSQL instance (requires DB_POSTGRES_DSN).
# Pipeline order: CI (lint+build+test) → Functional → E2E → Load Testing → Release
test-functional: install-gotestsum
$(GOTESTSUM) --junitfile functional-report.xml --format testdox -- -tags=functional -count=1 ./tests/functional/...
test-benchmark:
go test -bench=. -benchmem ./...
# Run E2E locally: build image, start stack, run tests, tear down.
e2e-local:
docker build -t fuse-app:test .
docker compose --profile e2e up -d --wait --wait-timeout 120
E2E_API_URL=http://localhost:9091 go test -tags=e2e ./tests/e2e -v -count=1 -timeout 15m; \
rc=$$?; docker compose --profile e2e down -v; exit $$rc
# E2E against a Kubernetes cluster with PG (requires: Kind/k3d cluster, kubectl, helm).
# Pipeline order: CI → Functional → E2E → Load Testing → Release
e2e-k8s:
E2E_API_URL=http://localhost:9091 go test -tags=e2e ./tests/e2e -v -count=1 -timeout 5m
build:
go build -o bin/fuse cmd/fuse/main.go
build-debug:
go build -tags pprof -o bin/fuse cmd/fuse/main.go
run-debug: build-debug
./bin/fuse server -o -p 9090 -l debug
clean:
rm -rf bin/
# golangci-lint must be built with Go >= the "go" line in go.mod (golangci-lint refuses older toolchains).
# GOTOOLCHAIN makes `go install` use that SDK even when the host `go` is older (e.g. gvm go1.24 + go.mod 1.26).
GOMOD_GOVER := $(shell sed -n 's/^go //p' go.mod | head -1 | tr -d ' \t\r')
# Install golangci-lint into GOPATH/bin (same path as GOLANGCI_LINT)
install-lint:
GOTOOLCHAIN=go$(GOMOD_GOVER).0 go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.5.0
# Run linter
lint: install-lint
$(GOLANGCI_LINT) run ./... --timeout=5m
# Run linter with auto-fix
lint-fix: install-lint
$(GOLANGCI_LINT) run ./... --fix --timeout=5m
format:
go fmt ./...
# Pretty-print JSON under data/ (filesystem object store). No-op if data/ is missing. Requires jq.
format-data-json:
@test -d data || exit 0
@find data -type f -name '*.json' -exec sh -c 'jq . "$$1" > "$$1.tmp" && mv "$$1.tmp" "$$1"' _ {} \;
# Install swag CLI v2 into GOPATH/bin (same path as SWAG)
install-swag:
GOTOOLCHAIN=go$(GOMOD_GOVER).0 go install github.com/swaggo/swag/v2/cmd/swag@latest
# Generate Swagger 2.0 docs under docs/ (default swag v2; avoid --v3.1 — OpenAPI 3.1 breaks many UIs/validators)
swagger: install-swag
$(SWAG) init -g main.go -o docs/ -d $(SWAG_DIRS)
# Lint Dockerfiles (consecutive RUN merge, etc.). Mirrors Sonar Docker rules; requires Docker.
HADOLINT_IMAGE := hadolint/hadolint:2.12.0-alpine
dockerfile-lint:
docker run --rm -v "$$(pwd):/work" -w /work --entrypoint /bin/hadolint $(HADOLINT_IMAGE) \
--config /work/.hadolint.yaml Dockerfile
# SonarCloud local analysis (reads ./sonar-project.properties). Requires Docker.
# SONAR_TOKEN: https://sonarcloud.io/account/security — use a SonarCloud user or org
# scoped token with analysis permission (not a GitHub OAuth token).
# If you see "Error 404 on .../analysis/analyses", try SONAR_REGION=us for US-hosted orgs.
# Optional: SONAR_SCANNER_IMAGE=sonarsource/sonar-scanner-cli:latest
SONAR_SCANNER_IMAGE ?= sonarsource/sonar-scanner-cli:latest
sonar-local:
@test -n "$$SONAR_TOKEN" || (echo "Set SONAR_TOKEN (SonarCloud > My Account > Security)." >&2; exit 1)
@set -e; \
opts=""; \
b=$$(git rev-parse --abbrev-ref HEAD 2>/dev/null || true); \
if [ -n "$$b" ] && [ "$$b" != "HEAD" ]; then \
opts="$$opts -Dsonar.branch.name=$$b"; \
fi; \
if [ -n "$$SONAR_REGION" ]; then \
opts="$$opts -Dsonar.region=$$SONAR_REGION"; \
fi; \
rev=$$(git rev-parse HEAD 2>/dev/null || true); \
if [ -n "$$rev" ]; then \
opts="$$opts -Dsonar.scm.revision=$$rev"; \
fi; \
docker run --rm \
-e SONAR_TOKEN \
-v "$$(pwd):/usr/src" \
-w /usr/src \
$(SONAR_SCANNER_IMAGE) \
$$opts
dkb:
docker build -t fuse-app:dev .
dkx:
docker stop fuse-local 2>/dev/null || true
docker rm fuse-local 2>/dev/null || true
docker run --name fuse-local --env-file .env -p 9090:9090 fuse-app:dev
# Start full HA stack: 3 Fuse nodes + PostgreSQL + S3 + etcd (built from source).
ha-up:
docker compose --profile ha up --build -d
ha-down:
docker compose --profile ha down -v
# Start infrastructure only (PG + S3 + etcd) for local dev with fuse on host.
infra-up:
docker compose --profile infra up -d
infra-down:
docker compose --profile infra down -v
# Apply PostgreSQL migrations only (requires DB_POSTGRES_DSN, same as server).
migrate: build
./bin/fuse migrate
seed: build
./bin/fuse seed examples -l debug
# Bump release version across deploy manifests. Usage: make bump-version VERSION=0.3.0
bump-version:
@test -n "$(VERSION)" || (echo "Usage: make bump-version VERSION=x.y.z" >&2; exit 1)
@chmod +x scripts/bump-version.sh
./scripts/bump-version.sh $(VERSION)
deploy:
./scripts/k3s-setup.sh
# Local Kubernetes (Docker Desktop): kind + Helm (same values as k3d script).
.PHONY: kind-deploy kind-redeploy
kind-deploy:
@chmod +x scripts/kind-setup.sh scripts/kind-redeploy.sh
./scripts/kind-setup.sh
# Rebuild image, load into kind, helm upgrade, rollout restart (refreshes /docs from Dockerfile swag).
kind-redeploy:
@chmod +x scripts/kind-redeploy.sh
./scripts/kind-redeploy.sh