From 9e9a99a590df09b8971aceb47451035f06b4a881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vegard=20B=C3=B8nes?= Date: Mon, 29 Jun 2026 15:33:30 +0200 Subject: [PATCH] add very simple docker-compose configuration --- deploy/.env.example | 22 ++++++++ deploy/.gitignore | 1 + deploy/README.md | 83 ++++++++++++++++++++++++++++ deploy/docker-compose.yml | 47 ++++++++++++++++ deploy/rawdataforecaster.config.json | 9 +++ justfile | 3 + 6 files changed, 165 insertions(+) create mode 100644 deploy/.env.example create mode 100644 deploy/.gitignore create mode 100644 deploy/README.md create mode 100644 deploy/docker-compose.yml create mode 100644 deploy/rawdataforecaster.config.json diff --git a/deploy/.env.example b/deploy/.env.example new file mode 100644 index 0000000..283ab8b --- /dev/null +++ b/deploy/.env.example @@ -0,0 +1,22 @@ +# Copy this file to deploy/.env and fill in the values. + +# Path on the host where forecast data files are stored. +# This is mounted read-only into rawdataforecaster at /data/forecast. +# Relative paths are resolved from the deploy/ directory. +FORECAST_DATA_PATH=../data/forecast + +# --- correctedforecaster (optional) --- +# To enable correctedforecaster, set COMPOSE_PROFILES=corrected AND +# point jsonfrontend at it via JSONFRONTEND_UPSTREAM. +# Leave COMPOSE_PROFILES empty (or unset) to run without correction. + +COMPOSE_PROFILES= +JSONFRONTEND_UPSTREAM=rawdataforecaster:5052 + +# When enabling correctedforecaster, change the two lines above to: +# COMPOSE_PROFILES=corrected +# JSONFRONTEND_UPSTREAM=correctedforecaster:5051 + +# Path on the host where topography data files are stored. +# Only used when correctedforecaster is enabled. +TOPOGRAPHY_DATA_PATH=../data/topography diff --git a/deploy/.gitignore b/deploy/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/deploy/.gitignore @@ -0,0 +1 @@ +.env diff --git a/deploy/README.md b/deploy/README.md new file mode 100644 index 0000000..95efd16 --- /dev/null +++ b/deploy/README.md @@ -0,0 +1,83 @@ +# Deploy + +This folder contains configuration for running Forti locally using Docker Compose. It brings up the core services — `rawdataforecaster`, `correctedforecaster`, and `jsonfrontend` — using local forecast data. + +## Prerequisites + +- [Docker](https://docs.docker.com/get-docker/) with Compose support +- Local forecast data (see [Preparing data](#preparing-data) below) + +## Preparing data + +Forecast data can be produced using [forti-prep](https://github.com/metno/forti-prep), a companion tool that downloads and post-processes the input datasets into the format expected by Forti. + +By default, the Compose setup expects forecast data to be available at `../data/forecast` (relative to this folder), which corresponds to `data/forecast/` in the repository root. You can override this with the `FORECAST_DATA_PATH` environment variable. + +## Services + +| Service | Description | Default port | +|---|---|---| +| `rawdataforecaster` | Serves forecast data over gRPC from a local directory | `5052` | +| `correctedforecaster` | Post-processes forecast data and re-exposes it over gRPC | — | +| `jsonfrontend` | REST API that serves point forecast timeseries as JSON | `8080` | + +`correctedforecaster` is optional and must be enabled via a Docker Compose [profile](#profiles). + +## Usage + +Build and start the base services: + +```bash +docker compose up --build +``` + +Test that the API is responding: + +```bash +curl 'http://localhost:8080/?lat=59&lon=11' +``` + +### Enabling correctedforecaster + +`correctedforecaster` is disabled by default. To enable it, set both variables in your `.env` file: + +```bash +COMPOSE_PROFILES=corrected +JSONFRONTEND_UPSTREAM=correctedforecaster:5051 +``` + +Both need to change together: `COMPOSE_PROFILES` starts the container, and `JSONFRONTEND_UPSTREAM` points `jsonfrontend` at it. Leave `COMPOSE_PROFILES` empty (or unset) to run without correction. + +## Environment variables + +| Variable | Default | Description | +|---|---|---| +| `FORECAST_DATA_PATH` | `../data/forecast` | Path to the local forecast data directory | +| `TOPOGRAPHY_DATA_PATH` | `../data/topography` | Path to the local topography data directory (used by `correctedforecaster`) | +| `JSONFRONTEND_UPSTREAM` | `rawdataforecaster:5052` | gRPC upstream address for `jsonfrontend` | + +These can be set in a `.env` file in this directory (`.env` is gitignored). Copy `.env.example` as a starting point: + +```bash +cp .env.example .env +``` + +## Configuration + +`rawdataforecaster.config.json` configures how `rawdataforecaster` reads forecast data: + +```json +{ + "source": { + "bucket": "file:///data/forecast" + }, + "areas": ["meps"], + "loader": { + "type": "blob" + } +} +``` + +- **`source.bucket`** — points to the mounted forecast data directory inside the container. +- **`areas`** — list of forecast areas to load (e.g. `meps`). +- **`loader.type`** — `"blob"` streams data on demand rather than loading everything into memory. Keep this as `"blob"` unless you have a specific reason to change it. diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml new file mode 100644 index 0000000..9a2dac3 --- /dev/null +++ b/deploy/docker-compose.yml @@ -0,0 +1,47 @@ +services: + rawdataforecaster: + build: + context: .. + dockerfile: rawdataforecaster/build/package/Dockerfile + ports: + - "5052:5052" + volumes: + - ./rawdataforecaster.config.json:/config.json:ro + - ${FORECAST_DATA_PATH:-../data/forecast}:/data/forecast:ro + command: ["-config", "/config.json"] + networks: + - internal + + correctedforecaster: + build: + context: .. + dockerfile: correctedforecaster/build/package/Dockerfile + profiles: ["corrected"] + volumes: + - ${TOPOGRAPHY_DATA_PATH:-../data/topography}:/data/topography:ro + command: + - "-upstream" + - "rawdataforecaster:5052" + - "-workdir" + - "/data/topography" + depends_on: + - rawdataforecaster + networks: + - internal + + jsonfrontend: + build: + context: .. + dockerfile: jsonfrontend/build/package/Dockerfile + ports: + - "8080:8080" + command: + - "-upstream" + - "${JSONFRONTEND_UPSTREAM:-rawdataforecaster:5052}" + depends_on: + - rawdataforecaster + networks: + - internal + +networks: + internal: diff --git a/deploy/rawdataforecaster.config.json b/deploy/rawdataforecaster.config.json new file mode 100644 index 0000000..9e34f5e --- /dev/null +++ b/deploy/rawdataforecaster.config.json @@ -0,0 +1,9 @@ +{ + "source": { + "bucket": "file:///data/forecast" + }, + "areas": ["meps"], + "loader": { + "type": "blob" + } +} diff --git a/justfile b/justfile index 86ec6de..a119e9d 100644 --- a/justfile +++ b/justfile @@ -2,3 +2,6 @@ build-docker *modules="correctedforecaster healthz jsonfrontend moxfrontend rawd set -e; for module in {{ modules }}; do \ docker build -t forti_$module -f $module/build/package/Dockerfile .; \ done + +run-docker: + cd deploy && docker compose up --build