Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
178 lines (157 loc) Β· 7.83 KB
/
Copy pathMakefile
File metadata and controls
178 lines (157 loc) Β· 7.83 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
# Development environment with hot reloading (frontend + backend)
dev:
@./scripts/dev.sh
# Build everything
build-app: build-front build-binary
build-image:
docker build -t dbbat .
demo: build-app
@echo "Starting demo environment..."
docker compose up -d postgres
DBB_RUN_MODE="demo" DBB_DSN="postgres://postgres:postgres@localhost:5001/dbbat?sslmode=disable" ./dbbat
# Start only frontend dev server
dev-front:
@echo "Starting frontend dev server..."
@cd front && bun run dev
# Start only backend with Air (requires frontend to be running separately for HMR)
dev-back:
@echo "Starting backend with Air hot reloading..."
@docker compose up -d postgres
@sleep 2
@air
# Stop development environment
dev-stop:
@echo "Stopping development environment..."
@-pkill -f "bun run dev" 2>/dev/null || true
@-pkill -f "air" 2>/dev/null || true
@docker compose down
# Build variables for ldflags
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null | sed 's/^v//' || echo "dev")
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
GIT_TIME ?= $(shell TZ=UTC git log -1 --format=%cd --date=format-local:%Y-%m-%dT%H:%M:%SZ 2>/dev/null || echo "unknown")
LDFLAGS := -X 'github.com/fclairamb/dbbat/internal/version.Version=$(VERSION)' \
-X 'github.com/fclairamb/dbbat/internal/version.Commit=$(COMMIT)' \
-X 'github.com/fclairamb/dbbat/internal/version.GitTime=$(GIT_TIME)'
# Build the binary
build-binary:
go build -ldflags "$(LDFLAGS)" -o ./dbbat .
# Build frontend
build-front:
@./scripts/build-frontend.sh
# Run Go unit tests
#
# `-race` matches what CI runs (.github/workflows/ci.yml). The proxies are
# concurrency-heavy β accept loop, per-connection goroutines, shutdown
# WaitGroup β and races there are probabilistic, so a local gate without the
# detector lets them through to CI (or to production).
test:
go test -race ./...
# Run E2E tests (builds production server, starts it in test mode, runs Playwright tests)
test-e2e:
@echo "Running E2E tests..."
@cd front && bun run test:e2e
# Regenerate the website's showcase media (screenshots + approval video).
#
# On demand only β never wired into a release. Brings up its own throwaway
# PostgreSQL container and its own demo-mode dbbat on non-default ports, so it
# cannot disturb a running `make dev` stack. See scripts/showcase.sh.
showcase:
@./scripts/showcase.sh
# Run Oracle integration tests (requires Docker).
#
# Twelve tests, each starting its own Oracle container: 15m was never enough and
# turned a slow machine into a red suite. CI budgets 60m for this job; 40m
# matches the other integration targets below and still fails fast on a real
# regression.
#
# The default image is gvenzl/oracle-free:23-slim (Oracle 23ai Free) on every
# host and in every environment: it has an arm64 build, and 23ai is the version
# the proxy work is validated against. The former default,
# gvenzl/oracle-xe:18.4.0-slim, is published for linux/amd64 only and does not
# boot under emulation on Apple Silicon β it dies in instance startup
# (ORA-27300 / ORA-00442), so the suite gave an arm64 developer no signal.
#
# Override the image with ORACLE_TEST_IMAGE, e.g. to reproduce the pinned 18c
# run on an amd64 machine:
#
# ORACLE_TEST_IMAGE=gvenzl/oracle-xe:18.4.0-slim make test-e2e-oracle
#
# CI (.github/workflows/integration.yml) runs the suite twice: once on this
# default, and once pinned to the 18c XE image so that coverage is kept.
#
# `-race`, and it costs nothing measurable. The integration suites are the only
# place two proxy goroutines meet on one session β client reader, upstream
# reader, limit watchdog, approval gate β and this is the suite with the most
# of that state and the most client shapes; the unit tests carry the detector
# but drive a single goroutine. Running without it hid two live races on the
# in-flight query (see `trackerMu` in internal/proxy/oracle/session.go).
#
# Measured on this target, same machine, back to back:
#
# without -race 6m38s wall (392s test time, 8.7s user CPU)
# with -race 6m16s wall (371s test time, 14.6s user CPU)
#
# The detector really is a ~2x CPU tax β but on ~6 seconds of CPU against a
# suite that spends six minutes booting Oracle containers, so the wall-clock
# difference is inside the run-to-run noise. -timeout 40m is unchanged.
test-e2e-oracle:
go test -race -tags integration -v -timeout 40m -count=1 ./internal/proxy/oracle/...
# Protocol integration suites (require Docker).
#
# Every test starts its own upstream container *and* its own PostgreSQL storage
# container, so a suite is dominated by container startup rather than by the
# assertions. On an idle laptop the MongoDB suite runs in ~4min; with other
# containers competing for the Docker daemon it has been measured at 7min and
# once past 12min. `go test`'s default timeout is 10 minutes, so the plain
# `go test -tags integration ./internal/proxy/mongodb/...` panics on a busy
# machine even when nothing is wrong. These targets carry the same -timeout 40m
# the CI workflow uses. A run that exceeds *that* is a real regression.
#
# `-race` on the three below, for the reason spelled out on test-e2e-oracle:
# these are the only suites that put two proxy goroutines on one session, and
# the detector is what turns that into signal. Measured on the Oracle target at
# 6m38s without / 6m16s with β the CPU tax is real but invisible next to
# container startup, and the same holds here (PostgreSQL 2m37s with it on).
# Each of the three has been run green under the detector; PostgreSQL needed a
# fix first (see `bookMu` in internal/proxy/postgresql/session.go).
test-integration-mongodb:
go test -race -tags integration -v -timeout 40m -count=1 ./internal/proxy/mongodb/...
test-integration-mysql:
go test -race -tags integration -v -timeout 40m -count=1 ./internal/proxy/mysql/...
test-integration-postgresql:
go test -race -tags integration -v -timeout 40m -count=1 ./internal/proxy/postgresql/...
# mcr.microsoft.com/mssql/server is published for linux/amd64 only, so on an
# arm64 laptop this suite runs under emulation. CI (ubuntu-24.04) is where it is
# expected to pass, but emulation is not a reason to skip it locally: measured
# under Rosetta on an M-series host, the whole suite (175 cases) took 3m39s wall
# with `-race` on, SQL Server itself reaching "ready for client connections" in
# ~6s per container.
#
# `-race`, same reason as the targets above. The TDS proxy runs the two relay
# pumps over one session like the others do, and the detector reported nothing β
# it guards the in-flight statement behind `pendingMu`, `statsMu`, `heldMu` and
# `preparedMu` already, which is what the other proxies had to be taught.
test-integration-mssql:
go test -race -tags integration -v -timeout 40m -count=1 ./internal/proxy/mssql/...
# The Kubernetes tunnel end to end: one k3s cluster (privileged container), a
# PostgreSQL pod inside it, and dbbat dialing through `pods/portforward`. Unlike
# the protocol suites this one boots a whole control plane, so the first run on
# a cold image cache is dominated by pulling k3s. Override the cluster with
# K3S_TEST_IMAGE=rancher/k3s:vX.Y.Z-k3s1 β it must be 1.31 or newer for the
# websocket transport assertion to hold.
#
# `-race`, like every other integration target. Booting a control plane sounds
# like the one suite where the detector would not be worth its cost, and it is
# also the one least likely to hide a race β it exercises the tunnel, not a
# session's two relay goroutines. Both guesses were checkable and were checked:
# with a warm k3s image the whole suite (7 cases, cluster boot included) ran in
# 1m09s wall under the detector, on arm64, with nothing reported. The cost was
# never the reason to skip it.
test-integration-kubernetes:
go test -race -tags integration -v -timeout 40m -count=1 ./internal/proxy/kubernetes/...
# Run linter
lint:
golangci-lint run
# Clean build artifacts
clean:
rm -rf ./bin ./tmp