From 21b32b6c591c9922e9bba8ae64ccae3039930cb6 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 5 Nov 2026 09:53:33 +0900 Subject: [PATCH] refac --- Dockerfile | 2 ++ README.md | 17 +++++++++++++++-- terminals/backends/docker.py | 3 +++ terminals/config.py | 8 ++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index ed49d11..48d614a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,8 @@ FROM python:3.12-slim ENV PYTHONUNBUFFERED=1 ENV PYTHONDONTWRITEBYTECODE=1 +ENV TERMINALS_DATABASE_URL=sqlite+aiosqlite:////app/data/terminals.db +ENV TERMINALS_DOCKER_DATA_DIR=/app/data/terminals WORKDIR /app diff --git a/README.md b/README.md index 12594c4..093e1cb 100644 --- a/README.md +++ b/README.md @@ -21,13 +21,25 @@ The fastest way to get running is with Docker. Terminals will manage sibling con ```bash docker run -p 3000:3000 \ -e TERMINALS_DOCKER_HOST=host.docker.internal \ + -e TERMINALS_DOCKER_HOST_DATA_DIR="$(pwd)/data/terminals" \ -v /var/run/docker.sock:/var/run/docker.sock \ - -v $(pwd)/data:/app/data \ + -v "$(pwd)/data:/app/data" \ ghcr.io/open-webui/terminals:latest ``` **Prerequisites:** Docker running on the host. +The image stores SQLite at `/app/data/terminals.db` and accesses workspaces at +`/app/data/terminals`. Set the optional `TERMINALS_DOCKER_HOST_DATA_DIR` only when +the Docker daemon sees those workspaces at a different absolute path, as above. +Both paths must refer to the same bind-mounted directory so provisioning and +file resets access the same files. Leave it unset when running directly on the +Docker host or when host and container paths match. + +When upgrading an existing deployment, back up and move its database and +workspaces from their previous effective paths before switching to this layout. +Changing these settings does not migrate existing files or container mounts. + ### Kubernetes Operator (recommended for clusters) For Kubernetes deployments, the operator manages `Terminal` custom resources automatically, handling pod creation, storage, and cleanup through CRDs. @@ -243,7 +255,8 @@ All settings are configured through environment variables prefixed with `TERMINA | `TERMINALS_DOCKER_HOST` | `127.0.0.1` | Host/IP that the orchestrator uses to reach published terminal container ports | | `TERMINALS_DOCKER_NETWORK` | | Docker network for terminal containers. Use a comma-separated list to shard terminals across multiple Docker bridge networks. | | `TERMINALS_DOCKER_MOUNTS` | | JSON array of extra bind mounts with `source`, `target`, and optional `readOnly` | -| `TERMINALS_DOCKER_DATA_DIR` | `data/terminals` | Host directory for per-user `/home/user` bind mounts | +| `TERMINALS_DOCKER_DATA_DIR` | `data/terminals` (`/app/data/terminals` in the image) | Workspace directory accessible to the orchestrator, including file resets | +| `TERMINALS_DOCKER_HOST_DATA_DIR` | | Optional absolute Docker-host path to the same workspace directory. Unset uses `TERMINALS_DOCKER_DATA_DIR`. | ### Kubernetes-only settings diff --git a/terminals/backends/docker.py b/terminals/backends/docker.py index 4dbf24b..4923f14 100644 --- a/terminals/backends/docker.py +++ b/terminals/backends/docker.py @@ -86,6 +86,9 @@ class DockerBackend(Backend): context_id = normalize_context_id(context_id) instance_name = self._container_name(policy_id, user_id, context_id) host_data_dir = str(self._home_dir(user_id, context_id).resolve()) + if settings.docker_host_data_dir: + relative_home = self._home_dir(user_id, context_id).relative_to(settings.docker_data_dir) + host_data_dir = str(Path(settings.docker_host_data_dir) / relative_home) s = spec or {} image = s.get("image", settings.image) diff --git a/terminals/config.py b/terminals/config.py index d8b3dba..c3646ff 100644 --- a/terminals/config.py +++ b/terminals/config.py @@ -36,6 +36,14 @@ class Settings(BaseSettings): default=f"{_DEFAULT_DATA_DIR}/terminals", validation_alias=AliasChoices("TERMINALS_DOCKER_DATA_DIR", "TERMINALS_DATA_DIR"), ) + docker_host_data_dir: str = "" # optional Docker-host path for docker_data_dir + + @field_validator("docker_host_data_dir") + @classmethod + def _validate_docker_host_data_dir(cls, value: str) -> str: + if value and not Path(value).is_absolute(): + raise ValueError("TERMINALS_DOCKER_HOST_DATA_DIR must be absolute") + return value port: int = 3000 host: str = "0.0.0.0"