Skip to content

perf(dashboard): standalone Next.js build + slim runtime image - #910

Merged
unjica merged 4 commits into
mainfrom
perf/dashboard-standalone-runtime
Oct 31, 2026
Merged

unjica merged 4 commits into
mainfrom
perf/dashboard-standalone-runtime

Conversation

@unjica

@unjica unjica commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator

What

  • Dockerfile (used by the Railway dasboard service): build with NEXT_OUTPUT=standalone (the same switch selfhost/dashboard.Dockerfile already uses; next.config.ts unchanged).
  • New slim runner stage on node:20-slim: copies only .next/standalone, .next/static, public and CHANGELOG.md (read at runtime by lib/changelog.ts). Runs as node, CMD ["node", "apps/dashboard/server.js"], HOSTNAME=0.0.0.0, PORT honoured (Railway injects it). No reinstall in the runner, so the v1.17.7 failure mode does not apply.

Why

Railway metrics (7 days): dashboard memory avg 0.43 GB, max 0.86 GB, near-zero CPU. It's the second-largest Railway cost line (~$4.3/month est.). The old runner copies the whole workspace and runs pnpm start → next start (two Node processes).

Measured locally (box, Node 24, same build)

Old (pnpm start) Standalone
RSS after warm-up (/, /pricing ×5) next-server 373 MB + pnpm 108 MB ≈ 481 MB 219 MB
Runtime payload full workspace (2.7 GB incl. build cache/deps on box) 166 MB

No Docker on the box, so image sizes weren't measured. The standalone layout was assembled exactly as the Dockerfile copies it.

Smoke (standalone): / 200, /login 200, /pricing 200, /docs/releases 200 (changelog renders 1.22.25), /_next/image (sharp) 200.

Checks

  • pnpm --filter dashboard lint: pass
  • vitest run (dashboard): 76 files / 467 tests pass
  • next build (includes typecheck): pass
  • tsc --noEmit reports 2 existing TS1501 errors in lib/marketing-seo-head.test.ts (regex flag/target). They're also on main and unrelated to this change.

⚠️ Deploy

The dasboard service watches /apps/dashboard/** and /Dockerfile on main, so merging auto-deploys to telemetry-tracker.com. Don't merge until Sanja approves a deploy window. After deploy, check /, /login, /docs/releases and Railway memory.

Rollback

Revert this PR (auto-redeploys), or redeploy the previous deployment in Railway.

@unjica

unjica commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator Author

QA request (QA / Product Reliability): please verify this standalone build before deploy. Suggested checks on a local docker build -f Dockerfile . + run with PORT set: /, /login (sign-in flow), /pricing, /docs/releases (changelog renders), /dashboard after login, /_next/image (sharp), Sentry release tag, and container RSS. Reply PASS/FAIL here. Merge auto-deploys telemetry-tracker.com, so it won't be merged until QA passes.

@unjica

unjica commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator Author

QA: PASS (Refs #910)

Tested SHA: e10555ac92601407834268ac2dff0cd5ae34b72d (Dockerfile-only change). Tested on 2026-10-31 around 23:40 CET.

What was run: a clean clone of the PR head, built on Node 20.20.2 with pnpm 9.15.9 (the same versions the Dockerfile pins).

  • pnpm install --frozen-lockfile: OK
  • pnpm --filter dashboard lint: OK
  • dashboard vitest: 76 files, 467/467 tests passed
  • I built it the same way the Dockerfile does: NEXT_OUTPUT=standalone, then core, next and dashboard builds, then rm -rf .next/cache. Next 15.5.27 built OK.
  • I put the runner stage together by hand with the same COPY layout: .next/standalone → /, .next/static → apps/dashboard/.next/static, public → apps/dashboard/public, and CHANGELOG.md → root. Then I started it with node apps/dashboard/server.js and HOSTNAME=0.0.0.0 PORT=3910, with API_URL pointed at the production API. Runtime size is 167 MB.
  • Caveat: I didn't run docker build, because there's no Docker on the QA box. I reproduced the Dockerfile stages by hand.

Checklist results (two runs on the local build; production checked once on the same pages as a baseline):

Item Result
/, /login, /pricing, /docs, /docs/nextjs, /robots.txt, /sitemap.xml, /favicon.ico 200. Status code and <title> match prod
404 (/this-does-not-exist-qa, /signup, /changelog) 404, same as prod
Auth guards /dashboard and /dashboard/projects give 307 to /login?next=…, and /dashboard/settings gives 307 to /settings/profile. Same as prod
/docs/releases Renders, and the CHANGELOG is read at runtime (latest entry 1.22.25 is present)
Static assets All 21 /_next/static JS/CSS/font files on the landing page return 200, and the CSS is applied
/_next/image (sharp) 200 image/png
Login with the QA account (server action) Works, redirects to /dashboard/overview?range=24h (2/2)
Dashboard pages overview, errors, events, logs, alerts, releases, sessions and performance all 200 (2/2)
Settings pages profile, keys (view only), billing, changelog and team all 200 (2/2)
Error checks on dashboard and settings pages No "Not Found" or error boundary, no console errors, no 4xx/5xx responses (2/2). Body text length matches prod
/pricing 200 (no Checkout opened)
Server log No ⨯ errors after the run

Memory (RSS of node server.js): about 179 MB idle and about 241 MB after two full smoke runs, consistent with the ~219 MB claimed.

Notes / risks (not blockers):

  1. API_URL is read at runtime and defaults to http://localhost:3001. Without it, the login server action returns 500 (ECONNREFUSED). This is the same as before the change, but the Railway dashboard service has to keep API_URL set as a runtime variable.
  2. On the Railway dashboard service, check that there's no Custom Start Command such as pnpm start overriding the new CMD. The slim runner has no pnpm and no full workspace, so an override like that would fail to boot.
  3. The runner runs as USER node. .next/cache for image optimization gets created under /app/apps/dashboard/.next, which is chowned to node, so this should be fine. Worth a quick /_next/image check after the prod deploy.
  4. Small text-length differences on /pricing and /dashboard/settings/changelog compared with prod come from the build env: I didn't set the prod NEXT_PUBLIC_* build args locally. This isn't a regression signal.
  5. Already present on prod, not caused by this PR: /docs/releases throws React Dashboard: client-side list table sort (SWR/React Query) #418, a hydration text mismatch. It doesn't happen on the local build. Probably locale or timezone related.

After the merge, please verify on prod: login, /docs/releases, /_next/image, container RSS, and the Sentry release tag.

@unjica
unjica merged commit bfc2dea into main Oct 31, 2026
6 checks passed
@unjica

unjica commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator Author

QA prod: PASS (Refs #910)

I checked production on 2026-11-01 between about 00:25 and 00:30 CET, after Railway deploy d3a5f400 went live at 23:45 CET. Everything was run twice and the results are the same both times.

  • Public pages and guards: these match the pre-deploy baseline (2/2):
    • 200: /, /login, /pricing, /docs, /docs/nextjs, /docs/releases, /robots.txt, /sitemap.xml, /favicon.ico.
    • 404: /signup, /changelog, an unknown path.
    • 307: /dashboard and /dashboard/projects go to /login?next=…, and /dashboard/settings goes to /settings/profile.
  • Static assets: all 21 /_next/static JS, CSS and font files on the landing page return 200.
  • Images: /_next/image returns 200 image/png (2/2), so the image cache works with the container running as the node user.
  • Login and dashboard: the QA account logs in and lands on /dashboard/overview?range=24h (2/2).
    • All 8 dashboard pages load 200: overview, errors, events, logs, alerts, releases, sessions, performance.
    • All 5 settings pages load 200: profile, keys (view only), billing, changelog, team.
    • No console errors, no failed requests, no error screens.
    • I didn't open Stripe Checkout.
  • Changelog: /docs/releases shows 1.22.25.
  • React Dashboard: client-side list table sort (SWR/React Query) #418 on /docs/releases: no longer shows on prod. Before the deploy it showed once.
  • API: /health returns 200 with ok:true, version 1.22.25, database ok and the alert evaluator ok.
  • Build marker: the HTML doesn't expose a build ID. Response headers show x-powered-by: Next.js served through Railway. The new build's features (the image cache under the node user, and the CHANGELOG read at runtime) work.

No rollback needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant