Change ResInsight to use ri-cloud-api as submodule (#14468)

This commit is contained in:
Jørgen Herje
2026-08-06 08:28:00 +02:00
committed by GitHub
parent 0012a65922
commit 086ab43e0a
17 changed files with 383 additions and 174 deletions
-74
View File
@@ -1,74 +0,0 @@
# ResInsight Cloud API service
A localhost FastAPI/uvicorn service whose lifecycle is managed by ResInsight
(`RiaCloudApiService`): it is started when Sumo authentication succeeds, bound to an
auto-selected free port, health-checked on `/alive`, restarted if unresponsive, and
killed when ResInsight closes.
## Location
The package lives at `scripts/ri_cloud_api` in the repository root.
On install, the contents of this folder are copied to `<install folder>/CloudServiceApi`
(see the *Installation packaging Cloud Service API* section in the top-level
`CMakeLists.txt`).
`RiaCloudApiService::serviceWorkingDirectory` locates the package by probing, in order:
1. the configured **Shared Script Folder(s)**
(**Preferences → Scripting → Shared Script Folder(s)**), and
2. `<application dir>/CloudServiceApi/`
and returning the first folder that contains a `ri_cloud_api` directory. For a
development build, point one of the shared script folders at the repository `scripts`
folder (e.g. `C:/Git/ResInsight/scripts`), since the executable lives in the build tree
and not next to the package.
## Deployment status
> **Target state:** this service is intended to be distributed and installed as a
> regular **pip package** into the active Python environment. Once packaged, importing
> `ri_cloud_api` (and any `ri_cloud_*` workspace libraries) will work directly from the
> environment's site-packages, with no path manipulation.
>
> **Current state (interim):** the service is **not yet a pip package**. It runs from the
> source tree inside a virtual environment, with the folder containing `ri_cloud_api` used
> as the process working directory. If workspace libraries are laid out as
> `ri_cloud_api/libs/<lib>/src`, ResInsight adds each such `src` folder to `PYTHONPATH` at
> launch time (see `RiaCloudApiService::buildProcessEnvironment`). This is a temporary
> measure that should be removed once the package is published/installed.
## Requirements (interim setup)
- A Python virtual environment configured in ResInsight under
**Preferences → Scripting → Python Executable**
(e.g. `C:/Git/.venvResInsight/Scripts/python.exe`).
- `uvicorn` and `fastapi` installed in that environment, plus any third-party
dependencies pulled in by the routers.
## Contents
ri_cloud_api/
main.py shim exposing `app` for `uvicorn ri_cloud_api.main:app`
primary/
main.py FastAPI application, router registration
routers/health/router.py `/alive` health endpoint
## Running manually (for debugging)
From the `scripts` folder (the parent of this package):
cd scripts
<venv>/Scripts/python.exe -m uvicorn ri_cloud_api.main:app --host 127.0.0.1 --port 8000
If workspace libraries are present, put them on `PYTHONPATH` first:
set PYTHONPATH=ri_cloud_api/libs/<lib>/src
Then check the health endpoint:
http://127.0.0.1:8000/alive -> {"status": "alive"}
Interactive API docs are available at:
http://127.0.0.1:8000/docs
View File
-11
View File
@@ -1,11 +0,0 @@
"""ResInsight Cloud API entrypoint.
Thin shim so ``uvicorn ri_cloud_api.main:app`` keeps working alongside the
real application module at :mod:`ri_cloud_api.primary.main`.
"""
from __future__ import annotations
from .primary.main import app
__all__ = ["app"]
-43
View File
@@ -1,43 +0,0 @@
"""ResInsight Cloud API — FastAPI application.
Lifecycle is managed by ResInsight (RiaCloudApiService): the service is started when Sumo
authentication succeeds, bound to an auto-selected free port, health-checked on /alive,
restarted if unresponsive, and killed when ResInsight closes.
Deployment status:
Target state — distributed and installed as a regular pip package, importable directly
from the environment's site-packages.
Current state (interim) — runs from the source tree in a virtual environment; ResInsight
injects each ri_cloud_api/libs/<lib>/src folder onto PYTHONPATH at launch time. This is
temporary and should be removed once the package is published/installed.
See README.md (next to this package) for details.
Setup:
pip install poetry
python -m venv .venv
source .venv/bin/activate
poetry install
Run (from the repository root):
uvicorn ri_cloud_api.primary.main:app --host 0.0.0.0 --port 8000 --reload
Docs:
http://localhost:8000/docs
"""
from __future__ import annotations
import logging
from fastapi import FastAPI
from .routers.health.router import router as health_router
logger = logging.getLogger("ri_cloud_api")
logging.basicConfig(level=logging.INFO)
app = FastAPI(title="ResInsight Cloud API")
app.include_router(health_router)
@@ -1,12 +0,0 @@
from fastapi import APIRouter
router = APIRouter(tags=["health"])
@router.get("/alive")
def alive() -> dict[str, str]:
"""Health-check endpoint polled by ResInsight for service life cycle management."""
return {"status": "alive"}