# Deploy the interactive broadcast demo to Cloud Run

Serves the **demo** (the recorded race, 3D render + overlays + commentary + neural audio,
language-switchable) as a public web service any phone/PC opens in a browser. Static only — no live
feed, no YouTube. (For the live/OBS path see [`../../../docs/V3-broadcast.md`](../../../docs/V3-broadcast.md) §6.)

This directory now contains three distinct deployment concerns; do not conflate their readiness:

- [`PRODUCER_CLOUDRUN.md`](PRODUCER_CLOUDRUN.md) — the production scene/SSE service, currently warm and
  service-capped at exactly one instance;
- [`GATEWAY_VM.md`](GATEWAY_VM.md) — the degraded headless encoder path; the provisioned emergency VM
  is currently stopped and has no output destination;
- `run_priority_video_cache.{ps1,cmd}` plus `run_priority_video_cache_hidden.vbs` — the local slot-A
  last-good cache installed at Windows user sign-in.

The end-to-end operational procedure is
[`../../../docs/trwc-emergency-broadcast-runbook.md`](../../../docs/trwc-emergency-broadcast-runbook.md).

## Prerequisites
- `gcloud` authenticated to the project (`gcloud auth login`).
- **Neural audio present locally** — clips are gitignored but bundled into the image. Three pinned
  commentary roles per language (Lead, Tactical, and Rules), rendered by Google neural TTS. Generate once:
  ```
  gcloud auth application-default login        # org policy blocks SA keys; ~1 h validity
  ../../../.venv-demo/Scripts/python ../live/tts/synth.py
  ```
- **Cesium ion token** at `../core/web/cesium-config.js` (gitignored; also bundled). Without it the
  scene falls back to stylised water.

## Deploy (from `v3/broadcast/`)
```
gcloud run deploy viewregatta-broadcast \
  --source . \
  --project apps-viewregatta \
  --region europe-north1 \
  --allow-unauthenticated \
  --memory 256Mi
```
`gcloud` builds the image from the `Dockerfile` (Cloud Build — no local Docker needed) and deploys.
It prints a URL like `https://viewregatta-broadcast-XXXX.europe-north1.run.app` — open it on any
device. Language: append `?lang=sv` (also `?speed=1`, `?audio=off`). nginx redirects `/` to the
renderer and listens on Cloud Run's `$PORT`.

## After deploying
- **Lock the Cesium token** to the new domain: in Cesium ion → Access Tokens → restrict the token's
  allowed URLs to `*.run.app` (or your custom domain). The token is shipped in `cesium-config.js`,
  so domain-restriction is what prevents reuse.
- **Custom domain** (optional): map e.g. `broadcast.viewregatta.com` via Cloud Run domain mappings.

## Notes
- The clips are **MP3** from the Google neural path (`../live/tts/synth.py`, needs
  `gcloud auth application-default login`) — generate them before deploying.
- Re-deploy after re-scoring (`real.json`) or re-synthesising audio: just re-run the deploy command.
