-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
302 lines (247 loc) · 11.7 KB
/
Copy pathMakefile
File metadata and controls
302 lines (247 loc) · 11.7 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
# ── JBrowser Local Development Makefile ──────────────────────────────────────
#
# Usage:
# make dev — start MySQL + control-plane + frontend dev server
# make dev-agent — start MySQL + control-plane + agent + frontend
# make up — docker-compose up (control + MySQL)
# make up-agent — docker-compose up with agent profile
# make down — tear down all containers
# make build — cargo build + frontend build
# make test — run all tests (Rust + TypeScript)
# make lint — run all linters
# make clean — cargo clean + remove frontend dist
#
# ────────────────────────────────────────────────────────────────────────────
COMPOSE := docker compose -f docker/docker-compose.yml
CARGO := cargo
PNPM := pnpm
# Default env for local native runs
export JWT_SECRET ?= dev-secret-change-me
export DATABASE_URL ?= mysql://root:jbrowser@127.0.0.1:3306/jbrowser
export PUBLIC_BASE_URL ?= http://localhost:8080
export DEMO_EMAIL ?= admin@example.com
export DEMO_PASSWORD ?= jbrowser
export SEED_AGENT_TOKEN ?= jbr_reg_dev_seed_token_for_local_docker
export RUST_LOG ?= info,jbrowser_control_plane=debug,jbrowser_agent=debug
# Agent env (native)
export CONTROL_PLANE_HTTP_URL ?= http://127.0.0.1:8080
export CONTROL_PLANE_WS_URL ?= ws://127.0.0.1:8080
export REGISTRATION_TOKEN ?= jbr_reg_dev_seed_token_for_local_docker
export AGENT_NAME ?= local-agent
# ── Combo targets ────────────────────────────────────────────────────────────
.PHONY: dev dev-agent
## Start MySQL (docker) + control-plane (native) + frontend dev server
dev: db
@echo "==> Starting control-plane + frontend (Ctrl-C to stop)"
@trap 'kill 0' EXIT; \
$(CARGO) run -p jbrowser-control-plane & \
sleep 2 && cd frontend && $(PNPM) dev & \
wait
## Start MySQL (docker) + control-plane + agent + frontend dev server
dev-agent: db
@echo "==> Starting control-plane + agent + frontend (Ctrl-C to stop)"
@trap 'kill 0' EXIT; \
$(CARGO) run -p jbrowser-control-plane & \
sleep 3 && $(CARGO) run -p jbrowser-agent & \
sleep 2 && cd frontend && $(PNPM) dev & \
wait
# ── Docker Compose ───────────────────────────────────────────────────────────
.PHONY: up up-agent down logs ps
## Docker-compose up: MySQL + control-plane
up:
$(COMPOSE) up --build -d
## Docker-compose up with agent
up-agent:
$(COMPOSE) --profile agent up --build -d
## Stop and remove all containers
down:
$(COMPOSE) --profile agent down
## Follow container logs
logs:
$(COMPOSE) --profile agent logs -f
## Show running containers
ps:
$(COMPOSE) --profile agent ps
# ── Database ─────────────────────────────────────────────────────────────────
.PHONY: db db-stop db-reset
## Start only MySQL container (for native dev)
db:
$(COMPOSE) up -d mysql
@echo "==> Waiting for MySQL to be healthy..."
@until docker inspect --format='{{.State.Health.Status}}' $$($(COMPOSE) ps -q mysql) 2>/dev/null | grep -q healthy; do \
sleep 1; \
done
@echo "==> MySQL is ready"
## Stop MySQL container
db-stop:
$(COMPOSE) stop mysql
## Reset database (destroy volume + restart)
db-reset:
$(COMPOSE) rm -sf mysql
docker volume rm -f docker_mysql_data 2>/dev/null || true
$(MAKE) db
# ── Build ────────────────────────────────────────────────────────────────────
.PHONY: build build-rust build-frontend
## Build everything
build: build-rust build-frontend
## Build all Rust crates
build-rust:
$(CARGO) build --all
## Build frontend for production
build-frontend:
cd frontend && $(PNPM) install && $(PNPM) build
# ── Build Docker images ─────────────────────────────────────────────────────
.PHONY: docker-build docker-build-control docker-build-agent
## Build all Docker images
docker-build: docker-build-control docker-build-agent
## Build control-plane image
docker-build-control:
docker build -t jbrowser-control:dev -f docker/Dockerfile.control .
## Build agent image
docker-build-agent:
docker build -t jbrowser-agent:dev -f docker/Dockerfile.agent-chromium .
# ── Test ─────────────────────────────────────────────────────────────────────
.PHONY: test test-rust test-frontend
## Run all tests
test: test-rust test-frontend
## Run Rust tests
test-rust:
$(CARGO) test --all
## Run frontend tests
test-frontend:
cd frontend && $(PNPM) test
# ── API Helpers ──────────────────────────────────────────────────────────────
API_URL ?= http://localhost:8080
.PHONY: login create-agent-token list-agent-tokens create-cdp-token list-cdp-tokens
## Login and print JWT token
login:
@curl -sf $(API_URL)/api/v1/auth/login \
-H 'Content-Type: application/json' \
-d '{"email":"$(DEMO_EMAIL)","password":"$(DEMO_PASSWORD)"}' \
| python3 -m json.tool
## Create an agent registration token (requires TENANT_ID and TOKEN env)
## Usage: make create-agent-token TENANT_ID=xxx TOKEN=jwt_here NAME="my-token"
create-agent-token:
@test -n "$(TENANT_ID)" || { echo "ERROR: set TENANT_ID"; exit 1; }
@test -n "$(TOKEN)" || { echo "ERROR: set TOKEN (JWT from 'make login')"; exit 1; }
@curl -sf $(API_URL)/api/v1/tenants/$(TENANT_ID)/agent-registration-tokens \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer $(TOKEN)' \
-d '{"name":"$(or $(NAME),cli-token)"}' \
| python3 -m json.tool
## List agent registration tokens
list-agent-tokens:
@test -n "$(TENANT_ID)" || { echo "ERROR: set TENANT_ID"; exit 1; }
@test -n "$(TOKEN)" || { echo "ERROR: set TOKEN (JWT from 'make login')"; exit 1; }
@curl -sf $(API_URL)/api/v1/tenants/$(TENANT_ID)/agent-registration-tokens \
-H 'Authorization: Bearer $(TOKEN)' \
| python3 -m json.tool
## Create a CDP access token
create-cdp-token:
@test -n "$(TENANT_ID)" || { echo "ERROR: set TENANT_ID"; exit 1; }
@test -n "$(TOKEN)" || { echo "ERROR: set TOKEN (JWT from 'make login')"; exit 1; }
@curl -sf $(API_URL)/api/v1/tenants/$(TENANT_ID)/tokens/cdp \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer $(TOKEN)' \
-d '{"name":"$(or $(NAME),cli-cdp-token)"}' \
| python3 -m json.tool
## List CDP access tokens
list-cdp-tokens:
@test -n "$(TENANT_ID)" || { echo "ERROR: set TENANT_ID"; exit 1; }
@test -n "$(TOKEN)" || { echo "ERROR: set TOKEN (JWT from 'make login')"; exit 1; }
@curl -sf $(API_URL)/api/v1/tenants/$(TENANT_ID)/tokens/cdp \
-H 'Authorization: Bearer $(TOKEN)' \
| python3 -m json.tool
## Quick setup: login → create agent token → print docker run command
## Usage: make setup
setup:
@echo "==> Logging in as $(DEMO_EMAIL)..."
@JWT=$$(curl -sf $(API_URL)/api/v1/auth/login \
-H 'Content-Type: application/json' \
-d '{"email":"$(DEMO_EMAIL)","password":"$(DEMO_PASSWORD)"}' \
| python3 -c "import sys,json; print(json.load(sys.stdin)['access_token'])") && \
TID=$$(curl -sf $(API_URL)/api/v1/auth/me \
-H "Authorization: Bearer $$JWT" \
| python3 -c "import sys,json; print(json.load(sys.stdin)['user']['tenants'][0]['id'])") && \
echo "==> Tenant: $$TID" && \
RESULT=$$(curl -sf $(API_URL)/api/v1/tenants/$$TID/agent-registration-tokens \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $$JWT" \
-d '{"name":"make-setup"}') && \
REG_TOKEN=$$(echo "$$RESULT" | python3 -c "import sys,json; print(json.load(sys.stdin)['token'])") && \
echo "==> Agent registration token: $$REG_TOKEN" && \
echo "" && \
echo "Run agent with:" && \
echo " docker run --shm-size=1g \\" && \
echo " -e CONTROL_PLANE_HTTP_URL=$(API_URL) \\" && \
echo " -e CONTROL_PLANE_WS_URL=$$(echo $(API_URL) | sed 's/http/ws/') \\" && \
echo " -e REGISTRATION_TOKEN=$$REG_TOKEN \\" && \
echo " -e AGENT_NAME=my-agent \\" && \
echo " ghcr.io/cnjack/jbrowser-agent-chromium:latest"
# ── Lint / Format ────────────────────────────────────────────────────────────
.PHONY: lint lint-rust lint-frontend fmt fmt-check
## Run all linters
lint: lint-rust lint-frontend
## Rust clippy
lint-rust:
$(CARGO) clippy --all-targets --all-features -- -D warnings
## Frontend type-check + eslint
lint-frontend:
cd frontend && $(PNPM) type-check
## Format Rust code
fmt:
$(CARGO) fmt --all
## Check Rust formatting (CI)
fmt-check:
$(CARGO) fmt --all --check
# ── Clean ────────────────────────────────────────────────────────────────────
.PHONY: clean
## Remove build artifacts
clean:
$(CARGO) clean
rm -rf frontend/dist frontend/node_modules/.vite
# ── Help ─────────────────────────────────────────────────────────────────────
.PHONY: help
help:
@echo ""
@echo "JBrowser Development Targets"
@echo "════════════════════════════════════════════════════════"
@echo ""
@echo " Development:"
@echo " make dev MySQL + control-plane + frontend (native)"
@echo " make dev-agent MySQL + control-plane + agent + frontend (native)"
@echo ""
@echo " Docker:"
@echo " make up docker-compose up (control + MySQL)"
@echo " make up-agent docker-compose up with agent"
@echo " make down stop all containers"
@echo " make logs follow container logs"
@echo " make ps show running containers"
@echo ""
@echo " Database:"
@echo " make db start MySQL container only"
@echo " make db-stop stop MySQL container"
@echo " make db-reset destroy + recreate MySQL"
@echo ""
@echo " Build:"
@echo " make build build Rust + frontend"
@echo " make docker-build build all Docker images"
@echo ""
@echo " API / Tokens:"
@echo " make setup auto-login + create agent token + print docker cmd"
@echo " make login login and print JWT"
@echo " make create-agent-token TENANT_ID=x TOKEN=jwt NAME=n"
@echo " make list-agent-tokens TENANT_ID=x TOKEN=jwt"
@echo " make create-cdp-token TENANT_ID=x TOKEN=jwt NAME=n"
@echo " make list-cdp-tokens TENANT_ID=x TOKEN=jwt"
@echo ""
@echo " Quality:"
@echo " make test run all tests"
@echo " make lint clippy + type-check"
@echo " make fmt format Rust code"
@echo " make fmt-check check Rust formatting"
@echo ""
@echo " Misc:"
@echo " make clean remove build artifacts"
@echo " make help show this help"
@echo ""