Skip to content

armgit / AiSOC

Public Imported from GitHub
0

Open-source AI Security Operations Center: alert fusion, LLM-agent triage, MITRE ATT&CK investigation, and a replayable decision ledger for every agent step. Self-hostable, runs with no API keys, MIT licensed. Ships an MCP server for Claude, Cursor and Continue.

feat(infra,demo): host live demo on Fly.io at tryaisoc.com

Beenu Aroraa60eecf63059
diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile
index cd4b36e40..a04fafaa7 100644
--- a/apps/web/Dockerfile
+++ b/apps/web/Dockerfile
@@ -20,7 +20,7 @@ COPY apps/web ./apps/web
ENV NEXT_TELEMETRY_DISABLED=1
-# ─── Build-time rewrite targets ─────────────────────────────────────────────
+# ─── Build-time rewrite targets (server-side) ───────────────────────────────
# Next.js bakes rewrite destinations into .next/routes-manifest.json at
# build time, so these args MUST be provided to docker build (e.g. via
# `args:` in docker-compose.demo.yml's `web.build:` block) when targeting
@@ -34,6 +34,20 @@ ENV API_URL=${API_URL}
ENV AGENTS_URL=${AGENTS_URL}
ENV REALTIME_URL=${REALTIME_URL}
+# ─── Build-time public URLs (client-side bundle) ────────────────────────────
+# Anything Next.js exposes to the browser via process.env.NEXT_PUBLIC_* is
+# substituted at `next build` time (read from the build environment), then
+# inlined as a string literal into the client JS chunks. Setting them only
+# in the runtime container has no effect on the bundle.
+#
+# Defaults are empty so dev/local builds fall back to same-origin requests
+# (apps/web/src/lib/api.ts checks for empty string and uses window.location).
+# In Fly the values come from infra/fly/web/fly.toml's [build.args].
+ARG NEXT_PUBLIC_API_URL=""
+ARG NEXT_PUBLIC_WS_URL=""
+ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
+ENV NEXT_PUBLIC_WS_URL=${NEXT_PUBLIC_WS_URL}
+
# Use pnpm's default symlinked node_modules — same layout as local dev,
# so tsup/tsc bin shims resolve correctly inside each workspace package.
RUN pnpm install --no-frozen-lockfile
diff --git a/apps/web/src/app/api/health/route.ts b/apps/web/src/app/api/health/route.ts
new file mode 100644
index 000000000..f4c215040
--- /dev/null
+++ b/apps/web/src/app/api/health/route.ts
@@ -0,0 +1,11 @@
+// Liveness probe used by Fly.io's http_service.checks. Kept intentionally
+// dumb: a 200 here means "Next.js is up and serving routes", nothing more.
+// Backend reachability is the API and realtime services' own concern.
+import { NextResponse } from 'next/server';
+
+export const dynamic = 'force-dynamic';
+export const runtime = 'nodejs';
+
+export function GET() {
+ return NextResponse.json({ status: 'ok' });
+}
diff --git a/apps/web/src/app/why-open-source/page.tsx b/apps/web/src/app/why-open-source/page.tsx
index 3a92f2a6b..05f393140 100644
--- a/apps/web/src/app/why-open-source/page.tsx
+++ b/apps/web/src/app/why-open-source/page.tsx
@@ -420,7 +420,7 @@ export default function WhyOpenSourcePage() {
</p>
<div className="mt-6 flex flex-wrap justify-center gap-3">
<a
- href="https://demo.aisoc.dev/cases/INC-001?tab=ledger"
+ href="https://tryaisoc.com/cases/INC-001?tab=ledger"
target="_blank"
rel="noreferrer"
className="inline-flex items-center gap-2 rounded-md bg-brand-500 px-4 py-2 text-sm font-semibold text-white transition hover:bg-brand-400"
diff --git a/apps/web/src/components/demo/DemoBanner.tsx b/apps/web/src/components/demo/DemoBanner.tsx
index 6fb1a794e..196e87423 100644
--- a/apps/web/src/components/demo/DemoBanner.tsx
+++ b/apps/web/src/components/demo/DemoBanner.tsx
@@ -1,7 +1,7 @@
'use client';
/**
- * DemoBanner — top-of-page strip rendered on the hosted demo at demo.aisoc.dev.
+ * DemoBanner — top-of-page strip rendered on the hosted demo at tryaisoc.com.
*
* Sits inside `AppShell` above the TopBar so it covers every authenticated
* page. Renders nothing when `NEXT_PUBLIC_DEMO_MODE !== 'true'`, so self-hosted
diff --git a/apps/web/src/components/landing/Hero.test.tsx b/apps/web/src/components/landing/Hero.test.tsx
index d3aaee78b..ca4d249af 100644
--- a/apps/web/src/components/landing/Hero.test.tsx
+++ b/apps/web/src/components/landing/Hero.test.tsx
@@ -39,7 +39,7 @@ describe('Hero', () => {
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent(/auditable AI SOC/i);
expect(screen.getByRole('link', { name: /open the demo/i })).toHaveAttribute(
'href',
- 'https://demo.aisoc.dev/cases/INC-001?tab=ledger',
+ 'https://tryaisoc.com/cases/INC-001?tab=ledger',
);
expect(screen.getByRole('link', { name: /open console/i })).toHaveAttribute('href', '/dashboard');
});
diff --git a/apps/web/src/components/landing/Hero.tsx b/apps/web/src/components/landing/Hero.tsx
index f23f0b5e8..651dfdc3d 100644
--- a/apps/web/src/components/landing/Hero.tsx
+++ b/apps/web/src/components/landing/Hero.tsx
@@ -40,7 +40,7 @@ export function Hero() {
<div className="mt-8 flex flex-wrap items-center gap-3">
<a
- href="https://demo.aisoc.dev/cases/INC-001?tab=ledger"
+ href="https://tryaisoc.com/cases/INC-001?tab=ledger"
target="_blank"
rel="noreferrer"
className="group inline-flex items-center gap-2 rounded-lg bg-brand-500 px-5 py-3 text-sm font-semibold text-white transition hover:bg-brand-400"
diff --git a/apps/web/src/lib/demoMode.ts b/apps/web/src/lib/demoMode.ts
index cc9af507e..f9fe4fa29 100644
--- a/apps/web/src/lib/demoMode.ts
+++ b/apps/web/src/lib/demoMode.ts
@@ -1,5 +1,5 @@
/**
- * Demo-mode helpers for the hosted demo at demo.aisoc.dev.
+ * Demo-mode helpers for the hosted demo at tryaisoc.com.
*
* Reads `NEXT_PUBLIC_DEMO_MODE` (set by `infra/fly/web/fly.toml`) to flag-gate
* write actions in the UI:
diff --git a/infra/fly/README.md b/infra/fly/README.md
index c25bee07b..de36b0b46 100644
--- a/infra/fly/README.md
+++ b/infra/fly/README.md
@@ -1,7 +1,21 @@
# AiSOC Hosted Demo (Fly.io)
This directory contains the infrastructure-as-code for the public demo at
-**[demo.aisoc.dev](https://demo.aisoc.dev)**, deployed on Fly.io.
+**[tryaisoc.com](https://tryaisoc.com)**, deployed on Fly.io.
+
+Three public hostnames front the stack:
+
+| Hostname | Fly app | Purpose |
+|----------------------|------------------------|----------------------------------|
+| `tryaisoc.com` | `aisoc-demo-web` | Next.js UI (apex/root domain) |
+| `api.tryaisoc.com` | `aisoc-demo-api` | FastAPI: `/health`, `/api/v1/*` |
+| `ws.tryaisoc.com` | `aisoc-demo-realtime` | WebSocket fanout (`wss://`) |
+
+Why three hostnames instead of routing everything through `tryaisoc.com`:
+the realtime service speaks raw WebSocket which Next.js rewrites can't
+proxy in production, and sending all `/api/v1/*` through the web app's
+machine would double latency. Splitting api/ws onto their own Fly certs
+is the standard pattern and keeps the browser's CORS/CSP boundary explicit.
## Goal
@@ -15,22 +29,19 @@ this stack is engineered for.
## Architecture
```
- demo.aisoc.dev (TLS via Fly certs)
+ tryaisoc.com api.tryaisoc.com ws.tryaisoc.com
+ │ │ │
+ ▼ ▼ ▼
+ ┌──────────────┐ ┌──────────────────┐ ┌──────────────────────┐
+ │ aisoc-demo- │ │ aisoc-demo-api │ │ aisoc-demo-realtime │
+ │ web (Next.js)│ │ (FastAPI) │ │ (WebSocket) │
+ │ shared-cpu-1x│ │ shared-cpu-1x │ │ shared-cpu-1x · 0.5GB│
+ │ 1GB · min=1 │ │ 1GB · min=1 │ │ auto_stop=off (WS) │
+ └──────────────┘ └──────────────────┘ └──────────────────────┘
+ │ │ │
+ └───── 6PN internal ────┴─────────────────────┘
│
▼
- ┌──────────────────────────────────┐
- │ aisoc-demo-web (Next.js) │ public
- │ shared-cpu-1x · 1GB · min=1 │
- └──────────────────────────────────┘
- │ │
- https│ wss │
- ▼ ▼
- ┌──────────────────────┐ ┌──────────────────────┐
- │ aisoc-demo-api │ │ aisoc-demo-realtime │
- │ (FastAPI) │ │ (WebSocket) │
- │ shared-cpu-1x · 1GB │ │ shared-cpu-1x · 0.5GB│
- │ min=1, demo middleware│ │ auto_stop=off (WS) │
- └──────────────────────┘ └──────────────────────┘
│ │
└───────┬────────┘
▼
@@ -126,20 +137,28 @@ T+anytime ┌──────────────────────
brew install flyctl
flyctl auth login
-# 2. Create org "aisoc" if it doesn't exist
-flyctl orgs create aisoc
+# 2. Pick the org. The deploy script defaults to `personal` (each Fly user's
+# default org). Override with FLY_ORG=… if you're deploying under a team org.
+export FLY_ORG=personal
-# 3. Reserve app names (one-time)
+# 3. Reserve app names (one-time, idempotent)
for app in aisoc-demo-api aisoc-demo-agents aisoc-demo-web \
aisoc-demo-realtime; do
- flyctl apps create "$app" --org aisoc
+ flyctl apps create "$app" --org "$FLY_ORG" 2>/dev/null || true
done
-# 4. Provision Postgres + Upstash + deploy everything
+# 4. Provision Postgres + Upstash + deploy everything + request TLS certs
./infra/fly/fly-demo-deploy.sh --provision
-# 5. Add DNS:
-# demo.aisoc.dev CNAME aisoc-demo-web.fly.dev
+# 5. Add DNS at your provider (the deploy script prints the exact records):
+# tryaisoc.com. CNAME aisoc-demo-web.fly.dev.
+# api.tryaisoc.com. CNAME aisoc-demo-api.fly.dev.
+# ws.tryaisoc.com. CNAME aisoc-demo-realtime.fly.dev.
+#
+# tryaisoc.com is an apex/root record. If your DNS provider doesn't support
+# CNAME at apex, use ALIAS/ANAME, or run
+# flyctl certs show tryaisoc.com --app aisoc-demo-web
+# to get the A/AAAA records to use instead.
```
## Routine deploy
@@ -183,8 +202,11 @@ curl -sI https://aisoc-demo-api.fly.dev/api/v1/cases | grep -i x-aisoc
curl -si -X POST https://aisoc-demo-api.fly.dev/api/v1/cases | head -3
# expect: HTTP/2 403 …
+# Public domain (after DNS propagates)
+curl -sf https://api.tryaisoc.com/health
+
# Visitor flow
-open https://demo.aisoc.dev/cases/INC-001?tab=ledger
+open https://tryaisoc.com/cases/INC-001?tab=ledger
```
## Troubleshooting
@@ -197,7 +219,7 @@ open https://demo.aisoc.dev/cases/INC-001?tab=ledger
| INC-001 case missing | Re-run seed: `flyctl ssh console -a aisoc-demo-api -C "python -m app.scripts.demo_seed --reset --kickoff-investigation"` |
| Daily seed cron not firing | Verify the scheduled machine: `flyctl machine list -a aisoc-demo-api` (look for `aisoc-demo-seed-cron`) |
| WS disconnects in 30s | Realtime `auto_stop_machines = "off"` — verify fly.toml |
-| Cert pending | `flyctl certs check demo.aisoc.dev --app aisoc-demo-web` |
+| Cert pending | `flyctl certs show tryaisoc.com --app aisoc-demo-web` (and same for `api.` / `ws.` subdomains) |
## Cost envelope
diff --git a/infra/fly/agents/fly.toml b/infra/fly/agents/fly.toml
index 797c26d11..996ddc445 100644
--- a/infra/fly/agents/fly.toml
+++ b/infra/fly/agents/fly.toml
@@ -17,10 +17,10 @@ primary_region = "iad"
kill_signal = "SIGINT"
kill_timeout = "10s" # agent runs may need to flush ledger writes
-# Dockerfile path is relative to the build context (= services/agents/).
-# Deploy script runs `flyctl deploy` from that dir.
-[build]
- dockerfile = "Dockerfile"
+# No [build] override: flyctl resolves `dockerfile` relative to fly.toml's
+# location, not cwd. Omitting it makes flyctl fall back to
+# `<cwd>/Dockerfile`, and the deploy script cd's into services/agents/
+# before invoking `flyctl deploy`, so the right Dockerfile is picked up.
[env]
ENVIRONMENT = "demo"
diff --git a/infra/fly/api/fly.toml b/infra/fly/api/fly.toml
index c0ae9e5e6..63946e6c7 100644
--- a/infra/fly/api/fly.toml
+++ b/infra/fly/api/fly.toml
@@ -2,6 +2,7 @@
# AiSOC Demo - API service (FastAPI)
#
# Deployed at: https://aisoc-demo-api.fly.dev
+# Public domain: https://api.tryaisoc.com (CNAME → aisoc-demo-api.fly.dev)
# Internal name: aisoc-demo-api.internal:8000
#
# Reads: Postgres (Fly managed), Redis (Upstash via Fly), demo tenant
@@ -9,15 +10,17 @@
# ──────────────────────────────────────────────────────────────────────────────
app = "aisoc-demo-api"
-primary_region = "iad" # us-east, lowest latency to demo.aisoc.dev
+primary_region = "iad" # us-east, lowest latency to tryaisoc.com
kill_signal = "SIGINT"
kill_timeout = "5s"
-# Dockerfile path is relative to the build context (= the service source dir).
-# The deploy script runs `flyctl deploy` from `services/api/` so `COPY . .`
-# in the Dockerfile sees the API source. See infra/fly/fly-demo-deploy.sh.
-[build]
- dockerfile = "Dockerfile"
+# No [build] override: flyctl resolves `dockerfile` relative to *fly.toml's*
+# location, not the build context. Since this fly.toml lives at
+# infra/fly/api/fly.toml but the Dockerfile lives at services/api/Dockerfile,
+# any literal "Dockerfile" entry would resolve to infra/fly/api/Dockerfile and
+# fail. Omitting [build] makes flyctl fall back to `<cwd>/Dockerfile`, and the
+# deploy script cd's into services/api/ before invoking `flyctl deploy`, so
+# the right Dockerfile gets picked up automatically.
[env]
ENVIRONMENT = "demo"
@@ -39,6 +42,18 @@ kill_timeout = "5s"
# app over Fly's internal 6PN DNS.
CORE_API_URL = "http://localhost:8000"
AGENTS_API_URL = "http://aisoc-demo-agents.internal:8084"
+ # Cross-origin allowlist for the browser. The Next.js app at tryaisoc.com
+ # calls api.tryaisoc.com directly (see infra/fly/web/fly.toml's build args),
+ # and we keep the .fly.dev hosts whitelisted as a fallback for direct
+ # debugging without DNS. Comma-separated; parsed by Settings.parse_cors.
+ CORS_ORIGINS = "https://tryaisoc.com,https://api.tryaisoc.com,https://aisoc-demo-web.fly.dev,https://aisoc-demo-api.fly.dev"
+ # Realtime base used by the API for /api/v1/push/* fan-out. Internal-only.
+ REALTIME_BASE_URL = "http://aisoc-demo-realtime.internal:4000"
+ # WebAuthn / passkey config. RP_ID is the eTLD+1 of the user-facing UI;
+ # RP_ORIGINS must be the exact scheme+host the browser presents.
+ PASSKEY_RP_ID = "tryaisoc.com"
+ PASSKEY_RP_NAME = "AiSOC"
+ PASSKEY_RP_ORIGINS = "https://tryaisoc.com"
[http_service]
internal_port = 8000
diff --git a/infra/fly/fly-demo-deploy.sh b/infra/fly/fly-demo-deploy.sh
index 10d591e0c..351851943 100755
--- a/infra/fly/fly-demo-deploy.sh
+++ b/infra/fly/fly-demo-deploy.sh
@@ -1,8 +1,8 @@
#!/usr/bin/env bash
-# ──────────────────────────────────────────────────────────────────────────────
+#
# fly-demo-deploy.sh
#
-# Deploys the full AiSOC live demo stack to Fly.io behind demo.aisoc.dev.
+# Deploys the full AiSOC live demo stack to Fly.io behind tryaisoc.com.
# Idempotent: safe to re-run after partial failures.
#
# Usage:
@@ -12,36 +12,35 @@
#
# Prereqs:
# - flyctl installed and authed (https://fly.io/docs/hands-on/install-flyctl/)
-# - fly org "aisoc" exists (fly orgs list)
-# - DNS for demo.aisoc.dev pointed at aisoc-demo-web (CNAME or A record)
+# - FLY_ORG env var set, or override with --org=
+# - DNS for tryaisoc.com (and api., ws.) pointed at the Fly apps via CNAME.
+# The deploy script issues certs but DNS must be live for them to validate.
#
# Architecture:
#
-# ┌────────────────┐ ┌────────────────┐ ┌────────────────┐
-# │ demo.aisoc.dev │──→ │ web (Next.js) │──→ │ api (FastAPI) │
-# └────────────────┘ └────────────────┘ └────────────────┘
-# │ │
-# ▼ ▼
-# ┌────────────────┐ ┌────────────────┐
-# │ realtime (WS) │ │ agents (LangG) │
-# └────────────────┘ └────────────────┘
-# │ │
-# └─────────┬─────────────┘
-# ▼
-# ┌────────────────────────────┐
-# │ Fly Postgres + Upstash Redis│
-# └────────────────────────────┘
+# tryaisoc.com aisoc-demo-web (Next.js UI)
+# api.tryaisoc.com aisoc-demo-api (FastAPI; /health, /docs, /api/v1/*)
+# ws.tryaisoc.com aisoc-demo-realtime (WebSocket fanout)
#
-# Time-to-first-investigation budget: <60s from the demo.aisoc.dev click.
+# web api, agents, realtime (over Fly's *.internal 6PN DNS)
+# api agents, realtime, Postgres, Redis
+#
+# Postgres = Fly managed (aisoc-demo-postgres)
+# Redis = Upstash via Fly (aisoc-demo-redis)
+#
+# Time-to-first-investigation budget: <60s from the tryaisoc.com click.
# The seed job pre-warms a running investigation so the deeplink lands
# inside its TTFI budget regardless of cold-start.
-# ──────────────────────────────────────────────────────────────────────────────
+#
set -euo pipefail
PROVISION=false
SKIP_SEED=false
-ORG="${FLY_ORG:-aisoc}"
+# `personal` is the canonical name Fly uses for a user's default org. We default
+# to it so the script works out of the box for the owner; CI or anyone deploying
+# to a different org can override via FLY_ORG= or by editing this default.
+ORG="${FLY_ORG:-personal}"
REGION="${FLY_REGION:-iad}"
for arg in "$@"; do
@@ -74,10 +73,12 @@ require() {
require flyctl
require git
-# ───────────────────────────────── provision ─────────────────────────────────
+# provision
+
+REDIS_URL_CAPTURED=""
if $PROVISION; then
- log "provisioning aisoc-demo-postgres (Fly managed Postgres, dev plan)…"
+ log "provisioning aisoc-demo-postgres (Fly managed Postgres, dev plan)"
flyctl postgres create \
--name aisoc-demo-postgres \
--org "$ORG" \
@@ -86,23 +87,64 @@ if $PROVISION; then
--volume-size 3 \
--initial-cluster-size 1 || log "(already provisioned)"
- log "provisioning Upstash Redis (free tier)…"
- flyctl redis create \
+ # Upstash Redis on Fly.
+ #
+ # `flyctl redis create` is the *only* place Fly exposes the connection URL.
+ # There's no `redis attach` subcommand and `redis status` doesn't print the
+ # URL either, so we capture stdout and grep out the redis:// string. The
+ # URL is then propagated to each consuming app via `flyctl secrets set`
+ # (see attach_redis below).
+ #
+ # Plan choice: "Pay-as-you-go" is the cheapest tier ($0.2 / 100K cmds);
+ # the older "Free" plan was retired in flyctl 0.4.x. Plan names are
+ # case-sensitive: `flyctl redis plans` prints them with a capital P, and
+ # passing the lowercase "pay-as-you-go" form returns
+ # `Error: plan "pay-as-you-go" not found`.
+ #
+ # --enable-eviction picks the eviction policy non-interactively. Without
+ # this, flyctl prompts ("Would you like to enable eviction?") and dies with
+ # "Error: prompt: non interactive" inside scripted runs. We want eviction ON
+ # for a demo cache: Upstash will drop old keys instead of refusing writes
+ # when the tier fills up.
+ #
+ # ProdPack: flyctl 0.4.x added a new interactive prompt asking whether you
+ # want the ProdPack add-on ($200/mo for enhanced production features).
+ # There is no `--no-prodpack` flag (only `--enable-prodpack` to opt in),
+ # so the prompt fires unconditionally in scripted runs and dies with
+ # "Error: prompt: non interactive". We feed `n\n` on stdin to decline.
+ # This is a "default no" prompt so a single newline would also work, but
+ # being explicit makes the intent obvious to anyone reading the script.
+ log "provisioning Upstash Redis (Pay-as-you-go, eviction enabled)"
+ REDIS_CREATE_OUT="$(printf 'n\n' | flyctl redis create \
--name aisoc-demo-redis \
--org "$ORG" \
--region "$REGION" \
--no-replicas \
- --plan Free || log "(already provisioned)"
+ --enable-eviction \
+ --plan "Pay-as-you-go" 2>&1 || true)"
+ printf '%s\n' "$REDIS_CREATE_OUT"
+ REDIS_URL_CAPTURED="$(printf '%s\n' "$REDIS_CREATE_OUT" \
+ | grep -oE 'redis://[^[:space:]]+' \
+ | head -n1 || true)"
+ if [[ -n "$REDIS_URL_CAPTURED" ]]; then
+ log "captured REDIS_URL from create output (will be staged on each app)"
+ else
+ log "(redis already provisioned or URL not in output; will skip secret"
+ log " propagation this run assume REDIS_URL was set on a prior run)"
+ log "If this is a fresh redis with no secrets set yet, run:"
+ log " flyctl redis status aisoc-demo-redis # then copy the redis:// URL"
+ log " flyctl secrets set REDIS_URL= --app aisoc-demo-{api,agents,realtime}"
+ fi
fi
-# ─────────────────────────────── deploy stack ────────────────────────────────
+# deploy stack
# Order matters:
-# 1. api — others depend on it via .internal DNS
-# 2. agents — api caller
-# 3. realtime — web caller
-# 4. web — last; serves traffic at demo.aisoc.dev
+# 1. api others depend on it via .internal DNS
+# 2. agents api caller
+# 3. realtime web caller
+# 4. web last; serves traffic at tryaisoc.com
#
-# The seeder is *not* a separate app — it ships inside the api image as
+# The seeder is *not* a separate app it ships inside the api image as
# `python -m app.scripts.demo_seed`, and we invoke it via `flyctl ssh
# console` post-deploy + a scheduled machine on the api app for the daily
# cron. This avoids a duplicate Dockerfile + the cost of a fifth Fly app
@@ -116,10 +158,26 @@ fi
# Fly's build context defaults to the *current working directory* of `flyctl
# deploy`, so we cd there before invoking it. The fly.toml is referenced by
# absolute path so flyctl still finds it.
+# ensure_app creates a Fly app if it doesn't already exist. Required because
+# `flyctl postgres attach` and `flyctl secrets set` both need the target app
+# to exist *before* the secret can be written. Our flow stages secrets before
+# the first deploy so the app boots with DATABASE_URL/REDIS_URL already
+# populated, avoiding the cold-start path where the app comes up, fails to
+# connect, and only gets the secret on a redeploy.
+ensure_app() {
+ local name="$1"
+ if flyctl apps list --org "$ORG" 2>/dev/null | awk '{print $1}' | grep -qx "$name"; then
+ log " app $name already exists"
+ else
+ log "creating Fly app $name in org $ORG"
+ flyctl apps create "$name" --org "$ORG"
+ fi
+}
+
deploy_app() {
local name="$1" toml_subdir="$2" build_ctx="$3"
local toml="$INFRA_DIR/$toml_subdir/fly.toml"
- log "deploying $name (context=$build_ctx, config=$toml)…"
+ log "deploying $name (context=$build_ctx, config=$toml)"
if [[ ! -f "$toml" ]]; then
err "fly.toml not found: $toml"
exit 1
@@ -132,40 +190,76 @@ deploy_app() {
flyctl deploy --remote-only --config "$toml" --app "$name" )
}
+# `--yes` skips the interactive "Overwrite existing user/secret?" prompt that
+# would otherwise hang the script on a re-run. Attach is idempotent on success
+# but returns non-zero on the second call (already attached), which we swallow.
attach_pg() {
local name="$1"
- log "attaching aisoc-demo-postgres → $name (sets DATABASE_URL secret)…"
- flyctl postgres attach aisoc-demo-postgres --app "$name" 2>/dev/null || log "($name already attached)"
+ log "attaching aisoc-demo-postgres $name (sets DATABASE_URL secret)"
+ flyctl postgres attach aisoc-demo-postgres --app "$name" --yes 2>/dev/null \
+ || log "($name already attached to postgres)"
}
attach_redis() {
local name="$1"
- log "attaching aisoc-demo-redis → $name (sets REDIS_URL secret)…"
- # Upstash flow exports REDIS_URL on attach
- flyctl redis attach aisoc-demo-redis --app "$name" 2>/dev/null || log "($name already attached)"
+ if [[ -z "$REDIS_URL_CAPTURED" ]]; then
+ log "skipping redis secret on $name (no REDIS_URL captured this run;"
+ log " assuming a prior --provision run already set it)"
+ return 0
+ fi
+ log "staging REDIS_URL secret on $name (applied on next deploy)"
+ # `--stage` writes the secret without triggering a deploy. The deploy_app
+ # call directly after will pick it up, so the machine boots with REDIS_URL
+ # already populated. Without --stage, flyctl would deploy twice.
+ flyctl secrets set "REDIS_URL=$REDIS_URL_CAPTURED" --app "$name" --stage \
+ || log "($name secret set failed will retry on deploy)"
}
-# 1. api — build context = services/api/
+# 1. api build context = services/api/
+ensure_app aisoc-demo-api
attach_pg aisoc-demo-api
attach_redis aisoc-demo-api
deploy_app aisoc-demo-api api services/api
-# 2. agents — build context = services/agents/
+# 2. agents build context = services/agents/
+ensure_app aisoc-demo-agents
attach_pg aisoc-demo-agents
attach_redis aisoc-demo-agents
deploy_app aisoc-demo-agents agents services/agents
-# 3. realtime — build context = services/realtime/
+# 3. realtime build context = services/realtime/
+ensure_app aisoc-demo-realtime
attach_redis aisoc-demo-realtime
deploy_app aisoc-demo-realtime realtime services/realtime
-# 4. web (public) — build context = repo root (Next.js Dockerfile pulls
+# 4. web (public) build context = repo root (Next.js Dockerfile pulls
# pnpm-workspace.yaml + packages/* from there).
+ensure_app aisoc-demo-web
deploy_app aisoc-demo-web web .
-# 4b. attach demo.aisoc.dev cert
-log "ensuring TLS cert for demo.aisoc.dev…"
-flyctl certs add demo.aisoc.dev --app aisoc-demo-web 2>/dev/null || log "(cert already issued)"
+# 4b. attach tryaisoc.com certs across the three public hostnames.
+#
+# Why three certs instead of routing everything through tryaisoc.com:
+# - The realtime service speaks raw WebSocket. Next.js rewrites can't
+# proxy WS in production, so the browser opens wss://ws.tryaisoc.com
+# directly.
+# - Sending /api/v1/* through Next rewrites would force every API call
+# through the web app's machine, doubling latency and limiting horizontal
+# scaling. api.tryaisoc.com goes straight to the FastAPI app.
+#
+# `flyctl certs add` is idempotent: a duplicate add returns non-zero, so we
+# swallow it. Cert *issuance* still requires the matching CNAME to be live
+# Fly retries validation in the background and reports status via
+# `flyctl certs show <hostname> --app <app>`.
+ensure_cert() {
+ local hostname="$1" app="$2"
+ log "ensuring TLS cert for $hostname (app=$app)"
+ flyctl certs add "$hostname" --app "$app" 2>/dev/null \
+ || log " (cert already requested for $hostname)"
+}
+ensure_cert tryaisoc.com aisoc-demo-web
+ensure_cert api.tryaisoc.com aisoc-demo-api
+ensure_cert ws.tryaisoc.com aisoc-demo-realtime
# 5. seed (in-process on the api app)
#
@@ -178,7 +272,7 @@ flyctl certs add demo.aisoc.dev --app aisoc-demo-web 2>/dev/null || log "(cert a
# Both paths execute `python -m app.scripts.demo_seed`; the canonical
# implementation lives in services/api/app/scripts/demo_seed.py.
if ! $SKIP_SEED; then
- log "running seed bootstrap inside aisoc-demo-api (one-shot via ssh)…"
+ log "running seed bootstrap inside aisoc-demo-api (one-shot via ssh)"
# `ssh console -C` runs a single command on a live machine and exits. We
# accept the slight CPU cost on the traffic-serving machine because (a)
# the seed is mostly I/O-bound, (b) it's a 30s burst, and (c) it lets us
@@ -188,7 +282,7 @@ if ! $SKIP_SEED; then
--command "python -m app.scripts.demo_seed --reset --kickoff-investigation" \
|| err "(seed bootstrap failed; demo will be cold until daily cron runs)"
- log "ensuring daily seed cron at 00:00 UTC on aisoc-demo-api…"
+ log "ensuring daily seed cron at 00:00 UTC on aisoc-demo-api"
# Fly scheduled machines fire on the chosen interval and exit cleanly.
# `--schedule daily` runs once per UTC day. Without an explicit image arg
# flyctl resolves to the app's currently-deployed image (i.e. the api
@@ -209,11 +303,31 @@ fi
log "deploy complete."
log ""
-log " Public: https://demo.aisoc.dev"
-log " Web: https://aisoc-demo-web.fly.dev"
-log " API: https://aisoc-demo-api.fly.dev/docs"
-log " Realtime: wss://aisoc-demo-realtime.fly.dev"
+log " Public UI: https://tryaisoc.com (CNAME aisoc-demo-web.fly.dev)"
+log " Public API: https://api.tryaisoc.com (CNAME aisoc-demo-api.fly.dev)"
+log " Public WS: wss://ws.tryaisoc.com (CNAME aisoc-demo-realtime.fly.dev)"
+log ""
+log " Direct (Fly):"
+log " Web: https://aisoc-demo-web.fly.dev"
+log " API: https://aisoc-demo-api.fly.dev/docs"
+log " Realtime: wss://aisoc-demo-realtime.fly.dev"
+log ""
+log "DNS setup (add these CNAMEs at your DNS provider before certs validate):"
+log " tryaisoc.com. CNAME aisoc-demo-web.fly.dev."
+log " api.tryaisoc.com. CNAME aisoc-demo-api.fly.dev."
+log " ws.tryaisoc.com. CNAME aisoc-demo-realtime.fly.dev."
+log ""
+log " Note: tryaisoc.com is an apex/root record. If your provider doesn't"
+log " support CNAME at apex, use ALIAS/ANAME, or follow Fly's instructions"
+log " from \`flyctl certs show tryaisoc.com --app aisoc-demo-web\` (returns"
+log " the A/AAAA records to use instead)."
log ""
log "Smoke test:"
log " curl -sf https://aisoc-demo-api.fly.dev/health"
-log " open https://demo.aisoc.dev/cases/INC-001?tab=ledger"
+log " curl -sf https://api.tryaisoc.com/health # after DNS propagates"
+log " open https://tryaisoc.com/cases/INC-001?tab=ledger"
+log ""
+log "Cert status (run after DNS is live):"
+log " flyctl certs show tryaisoc.com --app aisoc-demo-web"
+log " flyctl certs show api.tryaisoc.com --app aisoc-demo-api"
+log " flyctl certs show ws.tryaisoc.com --app aisoc-demo-realtime"
diff --git a/infra/fly/realtime/fly.toml b/infra/fly/realtime/fly.toml
index 1b6d44a37..739ab004a 100644
--- a/infra/fly/realtime/fly.toml
+++ b/infra/fly/realtime/fly.toml
@@ -3,11 +3,12 @@
#
# Deployed at: https://aisoc-demo-realtime.fly.dev
# Internal name: aisoc-demo-realtime.internal:4000
-# Public WS: wss://aisoc-demo-realtime.fly.dev
+# Public WS: wss://ws.tryaisoc.com (CNAME → aisoc-demo-realtime.fly.dev)
#
-# The web frontend connects directly over wss://. In demo mode the realtime
-# service multiplexes Redis pub/sub for "alert created" / "investigation event"
-# fanout. Kafka is intentionally disabled to keep the demo lean.
+# The web frontend connects directly over wss:// using NEXT_PUBLIC_WS_URL.
+# In demo mode the realtime service multiplexes Redis pub/sub for "alert
+# created" / "investigation event" fanout. Kafka is intentionally disabled
+# to keep the demo lean.
# ──────────────────────────────────────────────────────────────────────────────
app = "aisoc-demo-realtime"
@@ -15,18 +16,22 @@ primary_region = "iad"
kill_signal = "SIGINT"
kill_timeout = "5s"
-# Dockerfile path is relative to the build context (= services/realtime/).
-# Deploy script runs `flyctl deploy` from that dir.
-[build]
- dockerfile = "Dockerfile"
+# No [build] override: flyctl resolves `dockerfile` relative to fly.toml's
+# location, not cwd. Omitting it makes flyctl fall back to
+# `<cwd>/Dockerfile`, and the deploy script cd's into services/realtime/
+# before invoking `flyctl deploy`, so the right Dockerfile is picked up.
[env]
NODE_ENV = "production"
PORT = "4000"
AISOC_DEMO_MODE = "true"
AISOC_DISABLE_KAFKA = "true"
- # WebSocket origin allowlist: only the demo web app
- ALLOWED_ORIGINS = "https://demo.aisoc.dev,https://aisoc-demo-web.fly.dev"
+ # WebSocket origin allowlist: anything the browser can plausibly load the
+ # UI from. tryaisoc.com is the canonical public origin; the .fly.dev host
+ # stays on the list as a fallback (direct app access for debugging) and
+ # ws.tryaisoc.com is harmless because origin checks compare the loading
+ # page's origin, not the WS hostname.
+ ALLOWED_ORIGINS = "https://tryaisoc.com,https://aisoc-demo-web.fly.dev"
[http_service]
internal_port = 4000
diff --git a/infra/fly/web/fly.toml b/infra/fly/web/fly.toml
index 2faced4c6..3b703476e 100644
--- a/infra/fly/web/fly.toml
+++ b/infra/fly/web/fly.toml
@@ -2,13 +2,18 @@
# AiSOC Demo - Web (Next.js)
#
# Deployed at: https://aisoc-demo-web.fly.dev
-# Public domain: https://demo.aisoc.dev (configured via Fly certs)
+# Public domain: https://tryaisoc.com (CNAME → aisoc-demo-web.fly.dev)
#
-# This is the only public-facing service. The api/agents/realtime fly apps
-# only expose internal addressing through the .internal DNS to keep the
-# demo's blast radius small.
+# Three public hostnames front this stack:
+# tryaisoc.com → aisoc-demo-web (this app, Next.js UI)
+# api.tryaisoc.com → aisoc-demo-api (FastAPI, /health, /docs, /api/v1/*)
+# ws.tryaisoc.com → aisoc-demo-realtime (WebSocket fanout, wss://)
#
-# Reads: api (HTTP), realtime (WSS)
+# Why three subdomains instead of routing everything through the web app's
+# Next.js rewrites: the realtime service speaks raw WebSocket, which Next's
+# rewrites can't proxy in production. Splitting api/ws onto their own Fly
+# certs is the standard pattern and keeps the browser's CORS/CSP boundary
+# explicit.
# ──────────────────────────────────────────────────────────────────────────────
app = "aisoc-demo-web"
@@ -18,23 +23,56 @@ kill_timeout = "5s"
# Web Dockerfile expects the *monorepo root* as build context (it COPYs
# pnpm-workspace.yaml + packages/* to resolve workspace deps). The deploy
-# script runs `flyctl deploy` from the repo root, and we point at the
-# Dockerfile via its repo-relative path.
+# script runs `flyctl deploy` from the repo root, so the build context is
+# correct, but flyctl resolves the `dockerfile` field relative to *this
+# fly.toml's directory* (infra/fly/web/), not relative to CWD. So we have
+# to walk back up to the repo root with `../../../` and then down to the
+# real Dockerfile path. Without the `../../../` prefix, flyctl looks for
+# `infra/fly/web/apps/web/Dockerfile` and dies with "dockerfile not found".
+#
+# build.args: Next.js inlines NEXT_PUBLIC_* values into the *client* bundle
+# at build time (next build reads process.env then). Setting them only in
+# [env] would make them runtime-only — fine for SSR, but the browser-side
+# fetch()/WebSocket calls in apps/web/src/lib/api.ts would silently fall
+# back to same-origin and break. So we pass them through `docker build
+# --build-arg` here, the Dockerfile re-exports them as ENV before the
+# build step, and Next bakes the literal URL into the JS chunks.
[build]
- dockerfile = "apps/web/Dockerfile"
+ dockerfile = "../../../apps/web/Dockerfile"
+
+ [build.args]
+ NEXT_PUBLIC_API_URL = "https://api.tryaisoc.com"
+ NEXT_PUBLIC_WS_URL = "wss://ws.tryaisoc.com"
[env]
NODE_ENV = "production"
PORT = "3000"
NEXT_PUBLIC_DEMO_MODE = "true"
- # Public URLs: web is public, api/realtime are accessed through public Fly hostnames
- # so the browser can reach them. In a self-hosted setup these would be private.
- NEXT_PUBLIC_API_URL = "https://aisoc-demo-api.fly.dev"
- NEXT_PUBLIC_WS_URL = "wss://aisoc-demo-realtime.fly.dev"
+ # Public URLs the browser uses to reach api / realtime. Kept in sync with
+ # [build.args] above so SSR and client agree on the same backend hostnames.
+ NEXT_PUBLIC_API_URL = "https://api.tryaisoc.com"
+ NEXT_PUBLIC_WS_URL = "wss://ws.tryaisoc.com"
NEXT_PUBLIC_DEMO_RESET = "daily-utc-0000"
NEXT_PUBLIC_DEMO_BANNER = "Demo data resets daily at 00:00 UTC. All write actions are disabled."
# Default landing in demo mode: pre-seeded incident with running investigation
NEXT_PUBLIC_DEMO_DEEPLINK = "/cases/INC-001?tab=ledger"
+ # Server-side rewrite targets for next.config.js. Only some paths flow
+ # through the Next proxy:
+ # /api/v1/contextual/* → agents (apps/web/src/lib/api.ts uses an empty
+ # AGENTS_BASE, so contextual calls land same-origin
+ # on tryaisoc.com and Next rewrites them to agents
+ # internal — public api.tryaisoc.com would 404)
+ # /ws/*, /sse → realtime (rarely hit; the browser opens
+ # wss://ws.tryaisoc.com directly when NEXT_PUBLIC_WS_URL
+ # is set, but the rewrite is a safety net)
+ # /api/v1/* catch-all → api (mostly unused; browser goes to api.tryaisoc.com
+ # via NEXT_PUBLIC_API_URL)
+ # Without these set, the Dockerfile defaults (`http://agents:8084` etc.) leak
+ # through and the Next process tries to resolve them in Fly's DNS, which
+ # has no `agents` record. Use the full *.internal:port form for 6PN.
+ AGENTS_URL = "http://aisoc-demo-agents.internal:8084"
+ API_URL = "http://aisoc-demo-api.internal:8000"
+ REALTIME_URL = "http://aisoc-demo-realtime.internal:4000"
[http_service]
internal_port = 3000
diff --git a/services/api/app/core/config.py b/services/api/app/core/config.py
index 22e90fb6e..3258d451a 100644
--- a/services/api/app/core/config.py
+++ b/services/api/app/core/config.py
@@ -157,7 +157,7 @@ class Settings(BaseSettings):
return [origin.strip() for origin in v.split(",") if origin.strip()]
return v
- # Demo mode (hosted at demo.aisoc.dev)
+ # Demo mode (hosted at tryaisoc.com)
# When AISOC_DEMO_MODE=true the API rejects mutating requests outside the
# demo tenant with 403, surfaces a banner, and pre-seeds canonical data.
AISOC_DEMO_MODE: bool = False
diff --git a/services/api/app/db/database.py b/services/api/app/db/database.py
index 161102cf1..b73842e72 100644
--- a/services/api/app/db/database.py
+++ b/services/api/app/db/database.py
@@ -7,8 +7,36 @@ from sqlalchemy.orm import DeclarativeBase
from app.core.config import settings
+
+def _normalize_async_pg_url(url: str) -> str:
+ """Coerce common Postgres URL forms into the SQLAlchemy 2.x async dialect.
+
+ Fly.io's ``flyctl postgres attach`` (and Heroku, and most managed
+ hosts) writes ``DATABASE_URL=postgres://...``. SQLAlchemy 2.x dropped
+ the bare ``postgres`` scheme alias, so passing it straight to
+ ``create_async_engine`` raises ``NoSuchModuleError: postgres``.
+
+ Likewise, ``postgresql://...`` without an explicit driver suffix
+ selects the synchronous ``psycopg2`` dialect, which the async engine
+ rejects ("the asyncio extension requires an async driver").
+
+ This shim rewrites both forms to ``postgresql+asyncpg://``, which is
+ what we actually run. It is a no-op for URLs that already specify a
+ driver (``postgresql+asyncpg``, ``postgresql+psycopg``, etc.), so
+ operators who want to override the driver via secret can still do so.
+ """
+ if url.startswith("postgres://"):
+ return "postgresql+asyncpg://" + url[len("postgres://") :]
+ if url.startswith("postgresql://"):
+ # No driver specified -> default to asyncpg (the only async driver
+ # we ship with). Anything matching "postgresql+<driver>://" already
+ # has an explicit choice and we leave it alone.
+ return "postgresql+asyncpg://" + url[len("postgresql://") :]
+ return url
+
+
engine = create_async_engine(
- str(settings.DATABASE_URL),
+ _normalize_async_pg_url(str(settings.DATABASE_URL)),
pool_size=settings.DATABASE_POOL_SIZE,
max_overflow=settings.DATABASE_MAX_OVERFLOW,
echo=settings.DEBUG,
diff --git a/services/api/app/middleware/demo_mode.py b/services/api/app/middleware/demo_mode.py
index 7c88e10d1..24509dbb7 100644
--- a/services/api/app/middleware/demo_mode.py
+++ b/services/api/app/middleware/demo_mode.py
@@ -1,4 +1,4 @@
-"""Demo-mode guard for the hosted demo at demo.aisoc.dev.
+"""Demo-mode guard for the hosted demo at tryaisoc.com.
When `AISOC_DEMO_MODE=true`, this middleware:
@@ -97,7 +97,7 @@ class DemoModeMiddleware(BaseHTTPMiddleware):
content={
"error": "demo_mode_read_only",
"message": (
- "This is the public AiSOC demo at demo.aisoc.dev. "
+ "This is the public AiSOC demo at tryaisoc.com. "
"Write actions are disabled here so every visitor sees "
"the same dataset. To run AiSOC for real, self-host it "
"in 5 minutes — see https://github.com/beenuar/AiSOC."
diff --git a/services/api/app/scripts/demo_seed.py b/services/api/app/scripts/demo_seed.py
index 638a15b00..d9164af57 100644
--- a/services/api/app/scripts/demo_seed.py
+++ b/services/api/app/scripts/demo_seed.py
@@ -1,4 +1,4 @@
-"""demo_seed — Reset and warm up the hosted demo at demo.aisoc.dev.
+"""demo_seed — Reset and warm up the hosted demo at tryaisoc.com.
This is the canonical entrypoint for the hosted-demo refresh job. It runs
inside the api image (so it gets DATABASE_URL via Fly Postgres attach,
@@ -8,7 +8,7 @@ and is invoked one of three ways:
* **Post-deploy** — `infra/fly/fly-demo-deploy.sh` runs it via
`flyctl ssh console -a aisoc-demo-api -C "python -m app.scripts.demo_seed
--reset --kickoff-investigation"` once the deploy completes, so visitors
- hitting `demo.aisoc.dev` immediately see a hot investigation.
+ hitting `tryaisoc.com` immediately see a hot investigation.
* **Daily cron** — A Fly scheduled machine on the api app re-runs this
every 24h at 00:00 UTC to scrub demo state and re-seed.
* **Local recovery** — Self-hosters can run
diff --git a/services/api/tests/test_demo_mode.py b/services/api/tests/test_demo_mode.py
index 02db2c87c..7542f306f 100644
--- a/services/api/tests/test_demo_mode.py
+++ b/services/api/tests/test_demo_mode.py
@@ -146,7 +146,7 @@ def test_options_preflight_is_allowed(app: FastAPI) -> None:
client = TestClient(app)
r = client.options(
"/api/v1/cases",
- headers={"Origin": "https://demo.aisoc.dev", "Access-Control-Request-Method": "GET"},
+ headers={"Origin": "https://tryaisoc.com", "Access-Control-Request-Method": "GET"},
)
# FastAPI's TestClient + CORSMiddleware would normally answer this; without
# CORSMiddleware it 405s, but the demo-mode middleware itself never blocks