Repository navigation
Expand file tree
/
Copy pathdocker-compose.dev.yml
More file actions
399 lines (387 loc) · 18.8 KB
/
Copy pathdocker-compose.dev.yml
File metadata and controls
399 lines (387 loc) · 18.8 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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# Smart Router Dashboard — dev stack with HOT RELOAD, self-contained.
#
# docker compose -f docker-compose.dev.yml --profile router up --build
# (omit --profile router when a router already runs on the host's :7779)
#
# # Add the logs stack (Loki + Promtail + Grafana on :3001):
# docker compose -f docker-compose.dev.yml --profile router --profile logs up --build
#
# Mirrors lava-connect's dev pattern:
# - a shared Dockerfile.dev image carries node_modules (so mounts don't clobber it)
# - only source + dist dirs are mounted (NOT the whole tree)
# - `builder` runs `tsc --watch` on @sr/shared → dist/ (which api+web read)
# - api runs `tsx watch` (restarts on src or shared/dist change)
# - web runs `next dev` (Fast Refresh in the browser)
#
# Prometheus is bundled (deploy/prometheus.yml scrapes the bundled router
# AND host.docker.internal:7779). ONE values file (SR_CONFIG_HOST) drives
# both the router and the api — see docker-compose.yml for details.
name: smart-router-dashboard-dev
services:
prometheus:
image: prom/prometheus:v3.16.0@sha256:e04987641b57704f408e31f6373ba4138ecf27cb4a165d24aabb6c38fddd0f06
command:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
volumes:
- ./deploy/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus-data-dev:/prometheus
ports:
- "9090:9090"
extra_hosts:
- "host.docker.internal:host-gateway"
restart: unless-stopped
router:
profiles: ["router"]
# Published router image from GHCR (override with SR_ROUTER_IMAGE). Pinned
# to :main because the default command uses --cors-expose-headers, which
# ships on :main and rolls into :latest on the next tagged release — switch
# the default back to :latest once it's there. The release image is
# binary-only (no bundled specs/), so specs load straight from the
# lava-specs GitHub repo — no checkout, no volume mount.
image: ${SR_ROUTER_IMAGE:-ghcr.io/magma-devs/smart-router:main}
pull_policy: ${SR_ROUTER_PULL:-always}
command:
- "values.yml"
- "--use-static-spec"
- "${SR_SPEC:-https://github.com/Magma-Devs/lava-specs/tree/main}"
# GitHub PAT for fetching specs from the lava-specs GitHub repo above.
# Unauthenticated GitHub API is rate-limited to 60 req/hour; a token lifts
# that to 5,000/hour (and unlocks private repos). Empty by default — the
# router treats "" as unauthenticated, so leave SR_GITHUB_TOKEN unset for
# the normal public-repo path and set it only if you hit rate limits.
- "--github-token"
- "${SR_GITHUB_TOKEN:-}"
- "--cors-headers"
- "*"
# Expose the router's relay-provenance headers so the dashboard's Live
# test can show which upstream served a request (and "Cached" on a cache
# hit). Read by the browser from the Lava-Provider-Address response header.
- "--cors-expose-headers"
- "Lava-Provider-Address,Lava-Retries,Provider-Latest-Block,lava-cross-validation-agreeing-providers,lava-cross-validation-disagreeing-providers"
- "--log-level"
- "${SR_LOG_LEVEL:-info}"
- "--log-format"
- "${SR_LOG_FORMAT:-json}"
- "--skip-websocket-verification"
# External relay cache address — empty = in-process cache; the `cache`
# profile / `make up-cache` set SR_CACHE_BE=cache:20100. See docker-compose.yml.
- "--cache-be"
- "${SR_CACHE_BE:-}"
volumes:
- ${SR_CONFIG_HOST:-./dev-config/values.yml}:/smart-router/values.yml:ro
ports:
# Multichain dev-config: one listen port per chain×interface (see
# dev-config/values.yml). 3360 ETH1 · 3361 SOLANA · 3362 BTC ·
# 3363 HYPERLIQUID · 3364-3366 COSMOSHUB rest/tendermint/grpc · 3367 APT1.
- "3360-3367:3360-3367"
- "7779:7779"
depends_on:
cache:
condition: service_healthy
required: false # cache is opt-in (--profile cache)
restart: unless-stopped
# ---- Cache sidecar (opt-in via `--profile cache`) ----------------------
# smart-router RAM relay cache on :20100 (metrics :5555). The router uses it
# only when its config declares `cache-be: cache:20100` (commented out in
# dev-config/values.yml). Mirrors smart-router/docker/docker-compose.cache.yml.
cache:
profiles: ["cache"]
image: ${SR_ROUTER_IMAGE:-ghcr.io/magma-devs/smart-router:main}
pull_policy: ${SR_ROUTER_PULL:-always}
command: ["cache", "0.0.0.0:20100", "--metrics_address", "0.0.0.0:5555"]
expose:
- "20100"
ports:
- "5555:5555"
healthcheck:
test: ["CMD", "/busybox/wget", "-qO-", "http://localhost:5555/metrics"]
interval: 5s
timeout: 3s
retries: 5
start_period: 5s
restart: unless-stopped
# Auth backing store — ONLY needed when AUTH_MODE=enabled. Start it with
# the `auth` profile: docker compose -f docker-compose.dev.yml --profile
# router --profile auth up. The api connects lazily (retry loop) so
# AUTH_MODE=disabled keeps the zero-dependency boot. Host port 5434 for
# psql debugging (5433 is lava-connect's dev postgres).
postgres:
profiles: ["auth"]
image: postgres:18.6-alpine@sha256:9ba53c7d41ea093baf5c1ba635ba5434c4f979880527d49bb7d9237d3193085b
environment:
- POSTGRES_USER=sr
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-dev}
- POSTGRES_DB=sr_dashboard
volumes:
# PG18 image convention: mount ONE level up from the data dir
# (/var/lib/postgresql, not .../data) — the old path errors at boot.
- postgres-data-dev:/var/lib/postgresql
ports:
- "5434:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U sr -d sr_dashboard"]
interval: 5s
timeout: 3s
retries: 10
restart: unless-stopped
# ---- Logs stack (opt-in via `--profile logs`) --------------------------
# Loki + Promtail + Grafana. Promtail tails this project's container logs
# (api/web/prometheus/router), parses the router's zerolog JSON, and pushes
# to Loki; Grafana shows them on a pre-provisioned board. No change to any
# other service — discovery is via Docker labels. Grafana is on host :3001
# (web owns :3000). Start with e.g.:
# docker compose -f docker-compose.dev.yml --profile router --profile logs up --build
loki:
profiles: ["logs"]
image: grafana/loki:3.7.9@sha256:0db216b630ae1f348a1584c67f3cead8b4c1fc839169a39501db664744158e28
command: ["-config.file=/etc/loki/loki-config.yml"]
volumes:
- ./deploy/loki-config.yml:/etc/loki/loki-config.yml:ro
- loki-data-dev:/loki
ports:
- "3100:3100"
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "wget -q -O /dev/null http://localhost:3100/ready || exit 1"]
interval: 10s
timeout: 5s
retries: 12
start_period: 20s
promtail:
profiles: ["logs"]
image: grafana/promtail:3.6.8@sha256:6cfa64ec432b24a912d640e2edb940eeae2666f61861a66c121d763dd7241381
command: ["-config.file=/etc/promtail/promtail-config.yml"]
volumes:
- ./deploy/promtail-config.dev.yml:/etc/promtail/promtail-config.yml:ro
# Read-only Docker socket for container discovery + log tailing.
- /var/run/docker.sock:/var/run/docker.sock:ro
- promtail-positions-dev:/tmp
restart: unless-stopped
depends_on:
- loki
grafana:
profiles: ["logs"]
image: grafana/grafana:13.3.1@sha256:0615ec4fbd4072004b7d86b46ded63013a74b7d6eb1119273dd89e8fa25c13cf
environment:
- GF_SECURITY_ADMIN_USER=${GRAFANA_USERNAME:-admin}
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD:-admin}
- GF_USERS_ALLOW_SIGN_UP=false
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Viewer
- GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH=/var/lib/grafana/dashboards/smart-router-dashboard-logs.json
# Grafana listens on :3000 inside the container; only the HOST port is
# remapped to :3001 so it doesn't clash with web (:3000).
- GF_SERVER_ROOT_URL=http://localhost:3001/
volumes:
- ./deploy/grafana/datasources.yml:/etc/grafana/provisioning/datasources/datasources.yml:ro
- ./deploy/grafana/dashboards.yml:/etc/grafana/provisioning/dashboards/dashboards.yml:ro
- ./deploy/grafana/dashboards:/var/lib/grafana/dashboards:ro
- grafana-data-dev:/var/lib/grafana
ports:
- "3001:3000"
restart: unless-stopped
depends_on:
- loki
builder:
build:
context: .
dockerfile: Dockerfile.dev
working_dir: /app
command: pnpm --parallel --filter @sr/shared --filter @sr/db build:watch
volumes:
- ./packages/shared/src:/app/packages/shared/src
- ./packages/shared/dist:/app/packages/shared/dist
- ./packages/db/src:/app/packages/db/src
- ./packages/db/dist:/app/packages/db/dist
api:
build:
context: .
dockerfile: Dockerfile.dev
working_dir: /app
command: pnpm --filter @sr/api dev
environment:
- NODE_ENV=development
- API_PORT=8000
- PROMETHEUS_URL=http://prometheus:9090
# The router's logs, read by the Transactions and Errors tabs - the `logs`
# profile runs this Loki. Without it the tab says it can't read them.
- LOKI_URL=${LOKI_URL:-http://loki:3100}
- LOKI_ROUTER_SELECTOR=${LOKI_ROUTER_SELECTOR:-}
- LOKI_USERNAME=${LOKI_USERNAME:-}
- LOKI_PASSWORD=${LOKI_PASSWORD:-}
# Customer incident reports (docs/INCIDENTS.md). Off unless `true`;
# the webhook is the deployment's inbound URL in our on-call system.
- INCIDENTS_ENABLED=${INCIDENTS_ENABLED:-}
- INCIDENT_WEBHOOK_URL=${INCIDENT_WEBHOOK_URL:-}
- LOKI_ORG_ID=${LOKI_ORG_ID:-}
# Usage data (docs/USAGE-DATA.md): on only with accounts on, the switch
# on and a project token. Empty = unset = the api's defaults.
- USAGE_ANALYTICS=${USAGE_ANALYTICS:-}
- MIXPANEL_TOKEN=${MIXPANEL_TOKEN:-}
- MIXPANEL_API_HOST=${MIXPANEL_API_HOST:-}
- USAGE_TENANT=${USAGE_TENANT:-}
- USAGE_STAFF_DOMAINS=${USAGE_STAFF_DOMAINS:-magmadevs.com}
# Deployment scope (see .env.example). Empty = unset = the whole store.
- METRICS_SCOPE_LABEL=${METRICS_SCOPE_LABEL:-}
- METRICS_SCOPE_VALUE=${METRICS_SCOPE_VALUE:-}
- HELM_VALUES_DIR=/app/helm-values
# Try-me's router leg is sent by the api, which reaches an SR_CONFIG
# mount's routers here: the `router` service. A router running on the
# host instead takes host.docker.internal. ROUTER_RELAY_ENABLED=false
# sends it from the browser.
- ROUTER_RELAY_HOST=${ROUTER_RELAY_HOST:-router}
- ROUTER_RELAY_ENABLED=${ROUTER_RELAY_ENABLED:-true}
- CORS_ORIGINS=http://localhost:3000,http://127.0.0.1:3000
# Auth + database (docs/AUTH.md). EVERY value here is empty by default,
# and that is the whole point: with AUTH_MODE=disabled the api registers
# no database plugin, so it opens NO connection and applies NO migrations
# — `migrate()` is reachable only from `plugins/db.ts`, which is inside
# the `if (authMode === "enabled")` block in `app.ts`. The `postgres`
# service above is behind the `auth` profile, so it is not created either.
#
# The dev admin (admin@example.com / admin1234) and the dev signing secret
# used to live here as defaults. They now live in `make dev-auth`, which
# is the only thing that should be creating an administrator: a stack with
# no login had no business carrying a password for one.
- AUTH_MODE=${AUTH_MODE:-disabled}
- AUTH_SECRET=${AUTH_SECRET:-}
- DATABASE_URL=${DATABASE_URL:-}
# The pool each api process holds and the name the database's TLS
# certificate must carry (see .env.example). Empty = unset = the api's
# defaults: 20 connections, 30 s idle, TLS as DATABASE_URL says.
- DB_POOL_MAX=${DB_POOL_MAX:-}
- DB_IDLE_TIMEOUT_S=${DB_IDLE_TIMEOUT_S:-}
- DB_TLS_SERVERNAME=${DB_TLS_SERVERNAME:-}
- ADMIN_EMAIL=${ADMIN_EMAIL:-}
- ADMIN_PASSWORD=${ADMIN_PASSWORD:-}
# Two-factor secrets are encrypted at rest with this, and the api refuses
# to boot under AUTH_MODE=enabled without it (docs/TWO-FACTOR.md). Empty
# here like every auth value; the make targets that enable auth supply a
# fixed development key, so an accounts-reset cycle does not orphan the
# secrets enrolled before it.
- TOTP_ENCRYPTION_KEY=${TOTP_ENCRYPTION_KEY:-}
# Needed api-side to validate the `aud` claim of Google ID tokens.
- GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID:-}
# First-run setup (docs/AUTH.md → "First run"). Unset ⇒ the api mints a
# token at boot on an install that still needs one and logs it once at
# `warn`; set SETUP_TOKEN_FILE to a mounted path to have it written there
# (mode 0600) so an init container or a volume can surface it instead of
# `docker compose logs`. A configured SETUP_TOKEN must be >= 16 chars.
- SETUP_TOKEN=${SETUP_TOKEN:-}
- SETUP_TOKEN_FILE=${SETUP_TOKEN_FILE:-}
# Proves a request came from our own web tier, so the browser IP and
# User-Agent it forwards are honoured on the routes that open a session
# (sign-in, social sign-in, social invite redemption). Unset ⇒ forwarded
# context is ignored and the session records this container's address
# instead of the person's, which makes the audit log's access events
# useless for telling two sign-ins apart.
- INTERNAL_AUTH_SECRET=${INTERNAL_AUTH_SECRET:-}
# `hibp` (default) checks new passwords against HaveIBeenPwned by
# k-anonymity and fails OPEN if the service is unreachable. `off` is the
# honest setting for an air-gapped install — it says so in the logs
# rather than relying on a silent timeout on every password set.
- PASSWORD_BREACH_CHECK=${PASSWORD_BREACH_CHECK:-hibp}
# Where invitation links point. No default in the api on purpose — a
# guessed host produces a link that looks right and goes nowhere — so
# POST /api/team/invites answers 500 without it and nobody can be
# invited. Defaults to the web's own AUTH_URL, which is the same origin
# by definition; set it explicitly when the browser reaches the web on a
# different host than AUTH_URL names.
- PUBLIC_WEB_ORIGIN=${PUBLIC_WEB_ORIGIN:-${AUTH_URL:-http://localhost:3000}}
# managed (we host, invitations are emailed) vs onprem (customer hosts,
# the admin copies the link). Also sets the invitation TTL: 7 days vs 24
# hours. Declared rather than left to the code's default so the shape of
# the deployment is visible in the file.
- DEPLOYMENT_MODE=${DEPLOYMENT_MODE:-onprem}
# Managed Ask: all secrets/pricing stay on the API. Keep the customer
# ID and retention policy when disabling so cleanup continues.
- ASK_DATA_ENABLED=${ASK_DATA_ENABLED:-false}
- ASK_DATA_CUSTOMER_ID=${ASK_DATA_CUSTOMER_ID:-}
- ASK_DATA_MCP_URL=${ASK_DATA_MCP_URL:-https://mcp-staging.magmadevs.com/mcp}
- ASK_DATA_MCP_TOKEN=${ASK_DATA_MCP_TOKEN:-}
- ASK_DATA_BEDROCK_REGION=${ASK_DATA_BEDROCK_REGION:-us-east-1}
- ASK_DATA_BEDROCK_MODEL=${ASK_DATA_BEDROCK_MODEL:-}
- AWS_BEARER_TOKEN_BEDROCK=${AWS_BEARER_TOKEN_BEDROCK:-}
- ASK_DATA_PRICING_JSON=${ASK_DATA_PRICING_JSON:-}
- ASK_DATA_TOKEN_COUNTER=${ASK_DATA_TOKEN_COUNTER:-}
- ASK_DATA_TOKEN_COUNTER_MODEL=${ASK_DATA_TOKEN_COUNTER_MODEL:-}
- ASK_DATA_MONTHLY_LIMIT_MICRO_USD=${ASK_DATA_MONTHLY_LIMIT_MICRO_USD:-10000000}
- ASK_DATA_RETENTION_DAYS=${ASK_DATA_RETENTION_DAYS:-90}
volumes:
- ./apps/api/src:/app/apps/api/src
- ./apps/api/tsconfig.json:/app/apps/api/tsconfig.json
- ./packages/shared/src:/app/packages/shared/src
- ./packages/shared/dist:/app/packages/shared/dist
- ./packages/db/src:/app/packages/db/src
- ./packages/db/dist:/app/packages/db/dist
- ./packages/db/migrations:/app/packages/db/migrations
- ${SR_CONFIG_HOST:-./dev-config/values.yml}:/app/helm-values/core/values.yml:ro
ports:
- "8000:8000"
# So ROUTER_RELAY_HOST=host.docker.internal resolves on Linux too.
extra_hosts:
- "host.docker.internal:host-gateway"
depends_on:
- builder
- prometheus
web:
build:
context: .
dockerfile: Dockerfile.dev
working_dir: /app
command: pnpm --filter @sr/web dev
environment:
- NODE_ENV=development
- NEXT_PUBLIC_API_URL=http://localhost:8000
- NEXT_PUBLIC_LOCAL_MODE=true
- WATCHPACK_POLLING=true
# Base URL of the Grafana that hosts the logs board — the "View full logs"
# button links here (read at runtime via /api/config). Unset hides the
# button; with the `logs` profile up, set it to http://localhost:3001.
- DASHBOARD_GRAFANA_URL=${DASHBOARD_GRAFANA_URL:-}
# The "Report incident" button — read by the web itself, so it still
# shows when the api is down. Set the same INCIDENTS_ENABLED as the api.
- INCIDENTS_ENABLED=${INCIDENTS_ENABLED:-}
# Auth (see docs/AUTH.md) — same AUTH_MODE + AUTH_SECRET as the api.
# DEPLOYMENT_MODE must match the api's: the web serves it from
# /api/config and forks the invitation copy on it.
- DEPLOYMENT_MODE=${DEPLOYMENT_MODE:-onprem}
- ASK_DATA_ENABLED=${ASK_DATA_ENABLED:-false}
# Empty by default, like the api's: with AUTH_MODE=disabled the web mounts
# no login and never calls the api's /auth/* routes.
- AUTH_MODE=${AUTH_MODE:-disabled}
- AUTH_SECRET=${AUTH_SECRET:-}
- AUTH_URL=${AUTH_URL:-http://localhost:3000}
- INTERNAL_API_BASE_URL=http://api:8000
# Same secret as the api's. This is the half that SENDS the forwarded
# browser context; without it the web doesn't claim one and the api
# wouldn't believe it anyway.
- INTERNAL_AUTH_SECRET=${INTERNAL_AUTH_SECRET:-}
# Published directly, so no proxy writes X-Forwarded-For: 0 forwards no
# address rather than one the browser chose (docs/AUTH.md).
- TRUST_PROXY_HOPS=${TRUST_PROXY_HOPS:-0}
# OAuth providers — the login page shows a provider's button only
# when its id+secret pair is set.
- GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID:-}
- GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET:-}
- GITHUB_CLIENT_ID=${GITHUB_CLIENT_ID:-}
- GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET:-}
volumes:
- ./apps/web/src:/app/apps/web/src
- ./apps/web/public:/app/apps/web/public
- ./apps/web/next.config.mjs:/app/apps/web/next.config.mjs
- ./apps/web/tsconfig.json:/app/apps/web/tsconfig.json
- ./apps/web/next-env.d.ts:/app/apps/web/next-env.d.ts
- ./packages/shared/src:/app/packages/shared/src
- ./packages/shared/dist:/app/packages/shared/dist
ports:
- "3000:3000"
depends_on:
- api
volumes:
prometheus-data-dev:
postgres-data-dev:
loki-data-dev:
promtail-positions-dev:
grafana-data-dev: