Files
fxhnt/scripts/dev_cockpit_local.py
jgrusewski 359f2f5c50 feat(dev): local cockpit against real prod DB (read-only) for fast UI testing
scripts/dev-cockpit-local.sh port-forwards prod postgres to 15432 (5432 is usually owned by a local pg, so
the forward would fail 'address in use'), wires the DSN from the db-credentials secret, and serves the REAL
cockpit on :8801 via scripts/dev_cockpit_local.py — which builds the repos WITHOUT .migrate() so it never
writes DDL to prod. Iterate on cockpit UI in a real browser on real data in seconds, not 9-min Argo deploys.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-27 12:21:35 +02:00

30 lines
1.2 KiB
Python

"""Serve the REAL cockpit locally against whatever FXHNT_OPERATIONAL_DSN points to, READ-ONLY.
For fast local UI testing against REAL prod data without a 9-minute Argo deploy. Deliberately constructs the
repos WITHOUT calling .migrate(), so it never writes DDL to the (possibly production) DB — the cockpit pages
it serves are read-only. Driven by scripts/dev-cockpit-local.sh, which sets up the port-forward + DSN.
Env:
FXHNT_OPERATIONAL_DSN required — e.g. postgresql+psycopg://foxhunt:<pw>@127.0.0.1:15432/fxhnt
FXHNT_DEV_PORT local port to serve on (default 8801)
"""
import os
import uvicorn
from fxhnt.adapters.persistence.forward_nav import ForwardNavRepo
from fxhnt.adapters.persistence.paper_repo import PaperRepo
from fxhnt.adapters.web.app import create_app
dsn = os.environ["FXHNT_OPERATIONAL_DSN"]
port = int(os.environ.get("FXHNT_DEV_PORT", "8801"))
# READ-ONLY: no .migrate() — never write DDL to a prod DB we're only browsing.
app = create_app(
ForwardNavRepo(dsn),
paper_repo=PaperRepo(dsn),
bybit_paper_repo=PaperRepo(dsn, venue="bybit"),
)
print(f"cockpit (read-only) on http://127.0.0.1:{port}/paper/sim?book=bybit_4edge")
uvicorn.run(app, host="127.0.0.1", port=port, log_level="warning")