Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
251 lines (224 loc) Β· 12.6 KB
/
Copy pathMakefile
File metadata and controls
251 lines (224 loc) Β· 12.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
#!/usr/bin/make -f
#
# Smart Router Dashboard β local stack.
#
# `make up` is the one command you need: the compose file is self-contained
# (router profile + Prometheus + api + web). `make down` tears it down.
#
# The router profile pulls the published image (ghcr.io/magma-devs/smart-router
# :latest) and loads specs straight from the lava-specs GitHub repo β no
# smart-router checkout, no volume mount.
#
# Why the isolated builder (build-api/build-web): when another project is
# built on the same Docker daemon, the shared BuildKit cache/context can serve
# the wrong project's files (you'll see `@info/shared` in an
# ERR_PNPM_OUTDATED_LOCKFILE). A dedicated builder has its own clean cache.
SHELL := /bin/bash
# Optional overrides, forwarded to compose (each has a default IN the compose
# file, so leave unset for the normal path):
# SR_SPEC spec source for --use-static-spec (default: the lava-specs
# GitHub repo). Point at a local dir or another repo URL.
# SR_CONFIG_HOST the values file mounted into BOTH router and api
# (default: ./dev-config/values.yml β multichain + CV).
export SR_SPEC ?=
export SR_CONFIG_HOST ?=
# Build provenance surfaced by GET /version + the Account page. Read from the
# VERSION file and git so `make up` stamps the real version instead of the
# compose default (0.0.0 / dev). Overridable from the environment.
export APP_VERSION ?= $(shell tr -d ' \n\r' < VERSION 2>/dev/null || echo 0.0.0)
export GIT_COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo dev)
# Image names for local GHCR-parity builds (match the CI-published names:
# api β backend, web β frontend β the names the smart-router helm chart uses).
BUILDER ?= srdash-builder
API_IMAGE ?= ghcr.io/magma-devs/smart-router-dashboard/backend:local
WEB_IMAGE ?= ghcr.io/magma-devs/smart-router-dashboard/frontend:local
API_PORT ?= 8000
WEB_PORT ?= 3000
SES_UI_PORT ?= 8005
API_URL ?= http://localhost:$(API_PORT)
.PHONY: up down dev dev-down up-auth dev-auth accounts accounts-managed accounts-reset e2e e2e-down router ps clean builder build build-api build-web typecheck test
## up: SELF-CONTAINED stack β router + Prometheus + api + web + logs (Loki/Grafana)
up:
docker compose --profile router --profile logs up -d --build
@echo ""f
@echo " β
Dashboard up:"
@echo " UI β http://localhost:$(WEB_PORT)"
@echo " API β http://localhost:$(API_PORT)"
@echo " Prom β http://localhost:9090"
@echo " Grafana β http://localhost:3001 (admin / admin) β \"Smart Router Dashboard Logs\""
@echo " Router β http://localhost:3360-3367 (ETH1/SOLANA/BTC/HYPERLIQUID/COSMOSHUBΓ3/APT1)"
@echo ""
@echo " logs β docker compose logs -f (make dev runs in the foreground and streams them)"
## up-cache: like `up`, plus the smart-router cache sidecar (:20100, metrics :5555)
## Wires the router to the cache via --cache-be β no values.yml edit needed.
up-cache:
SR_CACHE_BE=cache:20100 docker compose --profile router --profile cache --profile logs up -d --build
@echo ""
@echo " β
Dashboard + cache up. Cache metrics β http://localhost:5555/metrics"
@echo " Router is wired to the cache via --cache-be cache:20100."
## down: stop the whole stack (auth + logs + cache profiles included so everything stops)
down:
docker compose --profile router --profile auth --profile logs --profile cache down
## dev: HOT-RELOAD stack (api = tsx watch Β· web = next dev Β· shared = tsc --watch) + logs (Loki/Grafana β :3001)
## Runs in the FOREGROUND and streams every container's logs β Ctrl-C to stop.
dev:
@echo "βΆ dev stack with hot reload + logs (Grafana β http://localhost:3001, admin/admin; first boot runs pnpm install β ~1 min)"
docker compose -f docker-compose.dev.yml --profile router --profile logs up --build
## dev-down: stop the hot-reload dev stack
dev-down:
docker compose -f docker-compose.dev.yml --profile router --profile auth --profile logs down
## up-auth: prod-style stack WITH authentication (postgres + login) β see docs/AUTH.md.
## Requires AUTH_SECRET, TOTP_ENCRYPTION_KEY and INTERNAL_AUTH_SECRET (each
## `openssl rand -base64 32`) in the environment β the api refuses to boot
## without the last two. The first admin is created at
## /setup with the setup token: this is a production build, and it ignores
## ADMIN_EMAIL / ADMIN_PASSWORD.
## (logs profile is on by default here too β Grafana β :3001.)
##
## DATABASE_URL is supplied HERE rather than as a compose default: the compose
## files leave every auth value empty so a stack with auth off has nothing
## pointing at a database. Override it to use a postgres other than the one the
## `auth` profile starts.
up-auth:
AUTH_MODE=enabled \
DATABASE_URL=$${DATABASE_URL:-postgres://sr:$${POSTGRES_PASSWORD:-dev}@postgres:5432/sr_dashboard} \
docker compose --profile router --profile auth --profile logs up -d --build
@echo ""
@echo " π Auth enabled β open http://localhost:$(WEB_PORT); a fresh install goes to /setup"
@echo " Setup token: the SETUP_TOKEN you set, or: docker compose logs api | grep -iE 'setup_?token'"
@echo " Grafana β http://localhost:3001 (admin / admin)"
## dev-auth: hot-reload stack WITH authentication (dev-default admin@example.com / admin1234)
##
## The dev secret, the dev 2FA key and the dev admin live here, not in
## docker-compose.dev.yml (the key is a fixed development value, never real):
## a stack running with auth OFF should not carry a password for an
## administrator it is never going to create. Every value is overridable.
dev-auth:
@echo "βΆ dev stack with hot reload + auth (sign in: admin@example.com / admin1234; Grafana β :3001)"
AUTH_MODE=enabled \
AUTH_SECRET=$${AUTH_SECRET:-dev-secret-change-me-please-32chars!} \
DATABASE_URL=$${DATABASE_URL:-postgres://sr:$${POSTGRES_PASSWORD:-dev}@postgres:5432/sr_dashboard} \
TOTP_ENCRYPTION_KEY=$${TOTP_ENCRYPTION_KEY:-ZGV2LW9ubHkta2V5LW5vdC1mb3ItcHJvZHVjdGlvbiE=} \
ADMIN_EMAIL=$${ADMIN_EMAIL:-admin@example.com} \
ADMIN_PASSWORD=$${ADMIN_PASSWORD:-admin1234} \
INTERNAL_AUTH_SECRET=$${INTERNAL_AUTH_SECRET:-dev-internal-secret} \
docker compose -f docker-compose.dev.yml --profile router --profile auth --profile logs up --build
## accounts: stack for exercising the MAG-2729 account system by hand (no seeded admin)
accounts:
AUTH_MODE=enabled \
AUTH_SECRET=$${AUTH_SECRET:-dev-secret-change-me-please-32chars!} \
DATABASE_URL=$${DATABASE_URL:-postgres://sr:$${POSTGRES_PASSWORD:-dev}@postgres:5432/sr_dashboard} \
TOTP_ENCRYPTION_KEY=$${TOTP_ENCRYPTION_KEY:-ZGV2LW9ubHkta2V5LW5vdC1mb3ItcHJvZHVjdGlvbiE=} \
docker compose -f docker-compose.dev.yml -f docker-compose.accounts.yml \
--profile auth up -d --build postgres builder api web
@echo ""
@echo " π Fresh install β no accounts yet."
@echo " Open http://localhost:$(WEB_PORT) β it redirects to /setup"
@echo " Setup token: installer-printed-this-token"
@echo ""
@echo " Walkthrough: docs/AUTH.md β \"Trying the account system by hand\""
@echo " Reset to a fresh install: make accounts-reset"
## accounts-managed: the same stack in MANAGED mode β invitations and resets are emailed
accounts-managed:
AUTH_MODE=enabled \
AUTH_SECRET=$${AUTH_SECRET:-dev-secret-change-me-please-32chars!} \
DATABASE_URL=$${DATABASE_URL:-postgres://sr:$${POSTGRES_PASSWORD:-dev}@postgres:5432/sr_dashboard} \
TOTP_ENCRYPTION_KEY=$${TOTP_ENCRYPTION_KEY:-ZGV2LW9ubHkta2V5LW5vdC1mb3ItcHJvZHVjdGlvbiE=} \
docker compose -f docker-compose.dev.yml -f docker-compose.accounts.yml \
-f docker-compose.managed.yml --profile auth up -d --build postgres builder ses api web
@echo ""
@echo " βοΈ Managed mode β invitations and resets are emailed."
@echo " Mail goes to a local SES mock, so nothing leaves this machine."
@echo ""
@echo " Inbox: http://localhost:$(SES_UI_PORT)"
@echo " App: http://localhost:$(WEB_PORT) β /setup"
@echo ""
@echo " Reset to a fresh install: make accounts-reset"
## recover: run a host recovery command against the running accounts database
## make recover CMD="reset-2fa --email dana@example.com"
##
## The three commands are reset-2fa, reset-password and promote-admin. Each
## writes a host.recovery row naming the command and the operator, so a recovery
## shows up in the dashboard afterwards and cannot be done quietly. Shell access
## on the host is the authorisation β see docs/TWO-FACTOR.md.
## The host.recovery row names the operator. Inside the container the shell
## user is the container's, so the host user is passed as --by unless CMD
## already names one. The dev stack only: a deployed api runs the same file as
## `node apps/api/dist/recover.js` (docs/TWO-FACTOR.md β Recovery).
recover:
@test -n "$(CMD)" || (echo 'set CMD, e.g. make recover CMD="reset-2fa --email dana@example.com"'; exit 2)
docker compose -f docker-compose.dev.yml -f docker-compose.accounts.yml \
--profile auth exec api pnpm --filter @sr/api exec tsx src/recover.ts $(CMD) \
$(if $(findstring --by,$(CMD)),,--by "$${SUDO_USER:-$$USER}")
## accounts-reset: wipe the accounts database and start over from first-run
accounts-reset:
docker compose -f docker-compose.dev.yml -f docker-compose.accounts.yml \
-f docker-compose.managed.yml --profile auth down -v
@echo 'βΆ wiped β run make accounts for a fresh first-run'
## e2e: EVERYTHING, from scratch β wipes the accounts database, then brings up
## router + Prometheus + logs + postgres + api + web in hot reload, with no
## seeded admin (first run at /setup) and managed-mode email to the local SES
## mock. The one stack for walking the whole product end to end.
## make e2e managed: invites + resets emailed (inbox :8005)
## make e2e MODE=onprem on-prem: links handed over by an admin, no email
## Prometheus is on :9091 here (the accounts overlay remaps it).
MODE ?= managed
E2E_FILES = -f docker-compose.dev.yml -f docker-compose.accounts.yml \
$(if $(filter managed,$(MODE)),-f docker-compose.managed.yml,)
E2E_PROFILES = --profile router --profile auth --profile logs
e2e:
@test "$(MODE)" = managed -o "$(MODE)" = onprem || (echo 'MODE must be managed or onprem'; exit 2)
docker compose -f docker-compose.dev.yml -f docker-compose.accounts.yml \
-f docker-compose.managed.yml $(E2E_PROFILES) down -v
AUTH_MODE=enabled \
AUTH_SECRET=$${AUTH_SECRET:-dev-secret-change-me-please-32chars!} \
DATABASE_URL=$${DATABASE_URL:-postgres://sr:$${POSTGRES_PASSWORD:-dev}@postgres:5432/sr_dashboard} \
TOTP_ENCRYPTION_KEY=$${TOTP_ENCRYPTION_KEY:-ZGV2LW9ubHkta2V5LW5vdC1mb3ItcHJvZHVjdGlvbiE=} \
docker compose $(E2E_FILES) $(E2E_PROFILES) up -d --build
@echo ""
@echo " π§ͺ End-to-end stack, fresh install ($(MODE) mode)"
@echo " App β http://localhost:$(WEB_PORT) β /setup, token: installer-printed-this-token"
@echo " API β http://localhost:$(API_PORT) (OpenAPI at /docs)"
@$(if $(filter managed,$(MODE)),echo " Inbox β http://localhost:$(SES_UI_PORT)",echo " Email β none (on-prem: an admin hands links over)")
@echo " Prom β http://localhost:9091"
@echo " Grafana β http://localhost:3001 (admin / admin)"
@echo " Router β http://localhost:3360-3367"
@echo ""
@echo " Logs: docker compose $(E2E_FILES) logs -f api web"
@echo " Again from scratch: make e2e Β· Stop: make e2e-down"
## e2e-down: stop the e2e stack (volumes kept; `make e2e` wipes them on the next run)
e2e-down:
docker compose -f docker-compose.dev.yml -f docker-compose.accounts.yml \
-f docker-compose.managed.yml $(E2E_PROFILES) down
## router: bring up ONLY the router + Prometheus from this compose
router:
docker compose --profile router up -d --build router prometheus
## builder: ensure the isolated BuildKit builder exists
builder:
@docker buildx inspect $(BUILDER) >/dev/null 2>&1 || \
docker buildx create --name $(BUILDER) --driver docker-container --bootstrap
## build: build the api + web images under their GHCR names (publish parity)
build: builder build-api build-web
build-api: builder
@echo "βΆ build $(API_IMAGE)"
docker buildx build --builder $(BUILDER) -f apps/api/Dockerfile \
-t $(API_IMAGE) --build-arg GIT_COMMIT=$$(git rev-parse --short HEAD 2>/dev/null || echo dev) \
--load .
build-web: builder
@echo "βΆ build $(WEB_IMAGE)"
docker buildx build --builder $(BUILDER) -f apps/web/Dockerfile \
-t $(WEB_IMAGE) \
--build-arg NEXT_PUBLIC_API_URL=$(API_URL) \
--build-arg NEXT_PUBLIC_LOCAL_MODE=true \
--load .
## ps: show the stack
ps:
@docker compose --profile router ps
## typecheck / test: workspace gates
typecheck:
pnpm -r typecheck
test:
pnpm -r test
## clean: down + remove the isolated builder
clean: down
-docker buildx rm $(BUILDER) 2>/dev/null