Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ __pycache__
*.pyd
env
.dockerignore
# Not needed in the image (and secrets must not be baked in)
scenarios/.streamlit
.streamlit/secrets.toml
OasisPiWind
certs
tests
85 changes: 85 additions & 0 deletions .env.scenarios
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# ============================================================================
# PUBLIC SCENARIOS DEMO CONFIGURATION
# ============================================================================
# Credential-free Scenarios app (scenarios_app.py): visitors run pre-loaded
# scenarios against pre-loaded exposure and view the results. No uploads, no
# public API. Deploy with:
#
# cp .env.scenarios .env # then change every CHANGE_ME value below
# ./install.sh
#
# The demo uses simple auth with a service account that only the UI and its
# setup/prune services use; visitors never log in.
# ============================================================================

# Public demo: Scenarios app only, no public API/database ports (docker-compose.public.yml)
OASIS_PUBLIC_DEMO=true
MODEL_SET=scenarios
# Directory holding the scenario model data (cloned by get-scenarios.sh if missing)
SCENARIOS_PATH=/home/ubuntu/Scenarios
# Bundled analysis settings used when the platform has no settings template
UI_DEFAULTS=./scenarios/defaults
# Days to keep visitors' runs (showcase runs are always kept)
OASIS_PRUNE_DAYS=7
# Per scenario worker: tasks at a time and memory cap (13 workers share the host)
OASIS_WORKER_CONCURRENCY=1
OASIS_WORKER_MEM_LIMIT=6g
# Set to get a Let's Encrypt certificate for OASIS_UI_HOSTNAME (must be public)
OASIS_ACME_EMAIL=

# Project Configuration
COMPOSE_PROJECT_NAME=oasisscenarios
OASIS_DEBUG=0

# Docker socket path (Docker Desktop uses ~/.docker/desktop/docker.sock)
# Standard Docker: /var/run/docker.sock
DOCKER_SOCK=/var/run/docker.sock

# Hostname Configuration
OASIS_UI_HOSTNAME=oasislmf-scenarios.com
OASIS_PROTOCOL=https

# Authentication Type
API_AUTH_TYPE=simple
OASIS_SERVER_ALLOWED_OIDC_AUTH_PROVIDERS=keycloak,authentik

# Simple Auth Credentials
OASIS_ADMIN_USER=admin
OASIS_ADMIN_PASS=CHANGE_ME

# Image Versions
SERVER_IMG=coreoasis/api_server
VERS_API=2.5.9
WORKER_IMG=coreoasis/model_worker
VERS_WORKER=2.5.9
PYTHONUI_IMG=coreoasis/oasispythonui_app
VERS_UI=latest
VERS_PIWIND=2.5.9

# Database Configuration
OASIS_SERVER_DB_HOST=server-db
OASIS_SERVER_DB_PORT=5432
OASIS_SERVER_DB_NAME=oasis
OASIS_SERVER_DB_USER=oasis
OASIS_SERVER_DB_PASS=CHANGE_ME

OASIS_CELERY_DB_HOST=celery-db
OASIS_CELERY_DB_PORT=5432
OASIS_CELERY_DB_NAME=celery
OASIS_CELERY_DB_USER=celery
OASIS_CELERY_DB_PASS=CHANGE_ME

# Broker & Channel Layer
RABBITMQ_DEFAULT_USER=rabbit
RABBITMQ_DEFAULT_PASS=CHANGE_ME
OASIS_CELERY_BROKER_URL=amqp://rabbit:CHANGE_ME@broker:5672
REDIS_HOST=channel-layer
REDIS_PORT=6379
OASIS_SERVER_CHANNEL_LAYER_SSL=false

# Advanced Configuration
OASIS_PORTFOLIO_UPLOAD_VALIDATION=0
OASIS_OASISLMF_VERSION=
OASIS_ODS_VERSION=
OASIS_ODM_VERSION=
OASIS_OED_SCHEMA_INFO=
42 changes: 0 additions & 42 deletions .github/workflows/scenarios-ui-docker.yml

This file was deleted.

82 changes: 75 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ The standard UI (`ui-config.json`) has three pages:
Analysis settings are edited with controls generated from the ODS-tools
analysis and model settings schemas, and validated before they are saved.

The Scenarios UI (`scenarios/ui-config.json`) is configured separately and adds
the `/scenarios`, `/comparison` and `/scenariosGuide` pages.
A separate, credential-free **Scenarios app** (`scenarios_app.py`) is for the
public demo: visitors run pre-loaded disaster scenarios against pre-loaded
exposure and explore the results, but cannot upload anything. See
[Public Scenarios demo](#public-scenarios-demo).

Which pages appear in the sidebar is controlled by the UI config file.

Expand Down Expand Up @@ -167,15 +169,15 @@ or set `MODEL_SET` in `.env` so a bare `./install.sh` deploys it:

```bash
./install.sh -m piwind # default: the PiWind demo model
./install.sh -m scenarios # PiWind plus the public scenario models
./install.sh -m scenarios # the public disaster scenario models
```

Model sets shipped in this repository:

| File | Contents |
|------|----------|
| `docker-compose.models.piwind.yml` | A `model-registration` one-shot and `piwind-worker`, with model data from `./OasisPiWind/`. |
| `docker-compose.models.scenarios.yml` | `piwind-worker` plus the scenario workers (Impact Forecasting, JBA, ARA, IPE), with model data from `${SCENARIOS_PATH}`. |
| `docker-compose.models.scenarios.yml` | `piwind-worker` plus the scenario workers (Impact Forecasting, JBA, ARA, IPE), with model data from `${SCENARIOS_PATH}`, and a `scenarios-setup` one-shot that loads the scenario portfolios, settings templates and showcase runs. |

Because the split is by filename, adding a model set means dropping two new
files into the root directory — no edits to `docker-compose.yml`, `install.sh`
Expand Down Expand Up @@ -314,7 +316,73 @@ docker compose logs -f <container_name> # UI logs
- The `.env` templates and `users.yaml` files ship with **demo credentials**.
Change all passwords before any non-local deployment.

## Public Demo
## Public Scenarios demo

The public site is at https://ui.oasislmf-scenarios.com/
Default scenarios in the tool are processed/hosted at https://github.com/OasisLMF/Scenarios
The public site is at https://oasislmf-scenarios.com/. Its scenarios are
published in https://github.com/OasisLMF/Scenarios.

The demo runs the **Scenarios app** (`scenarios_app.py`, pages in
`scenarios_ui/`), not the standard UI. It is credential free: the app uses a
service account for everyone, and visitors can:

- **Run a scenario** - choose a scenario, check the exposure it runs against,
choose the number of samples and a loss breakdown, run it and explore the
results.
- **Showcase** - explore pre-computed results without waiting.
- **Compare** - put two runs (showcase or their own) side by side.
- **Guide** - how loss models work and how to read the results.

Visitors only see their own runs (identified by the `?v=` id in the URL) and the
showcase runs. They cannot upload exposure, and the standard UI's pages are not
part of the app. Limits are set in the `scenarios` section of
`scenarios/ui-config.json`:

| Setting | Default | Description |
|---------|---------|-------------|
| `max_samples` | 50 | Maximum number of samples per run |
| `default_samples` | 10 | Initial number of samples |
| `max_active_runs_per_visitor` | 2 | Runs one visitor can have in progress |
| `max_active_runs` | 10 | Runs in progress across all visitors before new runs wait |
| `showcase_tag` | `[showcase]` | Name tag marking showcase runs |

`model_map` in the same file lists which pre-loaded portfolios each scenario
model can be run against.

### Deploying

```bash
cp .env.scenarios .env # set every CHANGE_ME value, SCENARIOS_PATH and the hostname
./install.sh # or ./install.sh --yes for an unattended redeploy
```

With `OASIS_PUBLIC_DEMO=true`, `install.sh` adds `docker-compose.public.yml`:

- the UI runs the Scenarios app;
- only Traefik's http/https ports are published - the API, websocket, databases
and broker have no host ports and no public routes;
- a `scenarios-prune` service deletes visitors' runs older than
`OASIS_PRUNE_DAYS` (showcase runs are kept).

The installer refuses to deploy a public demo while `.env` still contains
`CHANGE_ME` placeholders. Set `OASIS_ACME_EMAIL` to get a Let's Encrypt
certificate for `OASIS_UI_HOSTNAME` (`docker-compose.acme.yml`; the hostname
must resolve to the server and port 80 must be reachable).

The `scenarios-setup` service runs on every deploy and is idempotent: it adds
missing portfolios (`scenarios/portfolios.json`), updates the settings templates
(`scenarios/a_settings.json`) and starts a showcase run for any scenario that
doesn't have one (`scripts/add_showcase_analyses.py`).

The **Docker Scenarios UI CD** workflow deploys to the hosted server by running
`scenarios/deploy_scenarios_ui.sh` there, which uses `install.sh`. The server's
`.env` must be a configured copy of `.env.scenarios`.

To run the Scenarios app locally against an existing platform:

```bash
OASIS_UI_CONFIG=scenarios/ui-config.json streamlit run scenarios_app.py
```

The UI and setup scripts take the service account from
`OASIS_SERVICE_USERNAME_OR_ID` / `OASIS_SERVICE_PASSWORD_OR_SECRET` (set by
`install.sh` from `.env`), falling back to `.streamlit/secrets.toml`.
6 changes: 2 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
get_auth_type, exchange_session_token
)
import streamlit as st
from modules.credentials import service_client_kwargs
from modules.client import ClientInterface
from modules.nav import SidebarNav
from oasis_data_manager.errors import OasisException
Expand Down Expand Up @@ -45,10 +46,7 @@

if ui_config.skip_login:
with st.spinner("Loading platform..."):
if auth_type != 'simple':
client_interface = ClientInterface(auth_type="oidc", client_id=st.secrets["client_id"], client_secret=st.secrets["client_secret"])
else:
client_interface = ClientInterface(auth_type="simple", username=st.secrets["user"], password=st.secrets["password"])
client_interface = ClientInterface(**service_client_kwargs())
st.session_state["client"] = client_interface.client

cols = st.columns([0.1, 0.8, 0.1])
Expand Down
13 changes: 0 additions & 13 deletions deploy-scenarios.sh

This file was deleted.

33 changes: 33 additions & 0 deletions docker-compose.acme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ============================================================================
# Let's Encrypt certificates for a public hostname
# ============================================================================
# Added by install.sh when OASIS_ACME_EMAIL is set. Traefik obtains and renews
# a certificate for OASIS_UI_HOSTNAME using the HTTP challenge, so the hostname
# must resolve to this machine and port 80 must be reachable from the internet.
# Without it, certs/ui.crt (scripts/generate-certs.sh) is served instead.
# ============================================================================

volumes:
letsencrypt-data:

services:
traefik:
command:
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--providers.file.directory=/etc/traefik/dynamic"
- "--providers.file.watch=true"
- "--ping=true"
- "--api.insecure=true"
- "--certificatesresolvers.letsencrypt.acme.email=${OASIS_ACME_EMAIL}"
- "--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json"
- "--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web"
volumes:
- letsencrypt-data:/letsencrypt

pythonui:
labels:
- "traefik.http.routers.pythonui-secure.tls.certresolver=letsencrypt"
- "traefik.http.routers.pythonui-secure.tls.domains[0].main=${OASIS_UI_HOSTNAME}"
50 changes: 34 additions & 16 deletions docker-compose.models.scenarios.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# ============================================================================
# PiWind demo model
# Public scenario models
# ============================================================================
# The default model set, loaded by install.sh (MODEL_COMPOSE=piwind, or
# --models piwind). Always used together with docker-compose.yml, which
# provides the server, databases, broker and the filestore volume.
# The scenarios model set (install.sh -m scenarios): one worker per disaster
# scenario, with model data from ${SCENARIOS_PATH}. Always used together with
# docker-compose.yml, which provides the server, databases, broker and the
# filestore volume.
#

x-shared-env: &worker-env
Expand All @@ -18,6 +19,10 @@ x-shared-env: &worker-env
# Where workers report events completed, shown as run progress in the UI
OASIS_ANALYSIS_STATUS_URL: http://server:8000/analysis-status/

# One task at a time per worker (Celery defaults to one process per CPU, and
# with 13 workers that alone uses a lot of memory)
OASIS_CELERY_CONCURRENCY: ${OASIS_WORKER_CONCURRENCY:-1}

# Authentication configuration
OASIS_SERVER_API_AUTH_TYPE: ${API_AUTH_TYPE:-simple}
OASIS_SERVER_ALLOWED_OIDC_AUTH_PROVIDERS: ${OASIS_SERVER_ALLOWED_OIDC_AUTH_PROVIDERS}
Expand Down Expand Up @@ -63,6 +68,9 @@ x-shared-env: &worker-env
x-worker: &worker
restart: always
image: ${WORKER_IMG:-coreoasis/model_worker}:${VERS_WORKER:-latest}
# Cap each worker so a run that outgrows it is killed inside its container
# rather than exhausting the host's memory
mem_limit: ${OASIS_WORKER_MEM_LIMIT:-6g}
depends_on:
server:
condition: service_healthy
Expand All @@ -73,18 +81,6 @@ x-worker: &worker


services:
piwind-worker:
<<: *worker
environment:
<<: *worker-env
OASIS_MODEL_SUPPLIER_ID: OasisLMF
OASIS_MODEL_ID: PiWind
OASIS_MODEL_VERSION_ID: 'v2'
OASIS_RUN_MODE: v2
volumes:
- ./OasisPiWind/:/home/worker/model
- filestore-data:/shared-fs:rw

maeq-worker:
<<: *worker
environment:
Expand Down Expand Up @@ -250,3 +246,25 @@ services:
volumes:
- ${SCENARIOS_PATH}/IPE/FranceHail/:/home/worker/model
- filestore-data:/shared-fs:rw

# Loads the scenario portfolios, settings templates and showcase analyses
# (scripts/scenarios_setup.sh). Idempotent, so it runs on every deploy.
scenarios-setup:
image: ${PYTHONUI_IMG:-coreoasis/oasispythonui_app}:${VERS_UI:-latest}
restart: "no"
entrypoint: ["bash", "scripts/scenarios_setup.sh"]
environment:
- API_URL=http://server:8000
- API_AUTH_TYPE=${API_AUTH_TYPE:-simple}
- OASIS_SERVICE_USERNAME_OR_ID=${OASIS_SERVICE_USERNAME_OR_ID:-}
- OASIS_SERVICE_PASSWORD_OR_SECRET=${OASIS_SERVICE_PASSWORD_OR_SECRET:-}
- SCENARIOS_UI_CONFIG=scenarios/ui-config.json
# Number of model workers in this file: setup waits for all to register
- SCENARIOS_MIN_MODELS=13
volumes:
# Portfolio paths in scenarios/portfolios.json are relative to /usr/src/app
- ${SCENARIOS_PATH}:/usr/src/Scenarios:ro
- ${UI_STREAMLIT:-./.streamlit/}:/usr/src/app/.streamlit:ro
depends_on:
server:
condition: service_healthy
Loading
Loading