From a0d60215ca98bf75a268f4a8908c75295886d628 Mon Sep 17 00:00:00 2001 From: Federico Jaramillo Martinez Date: Sat, 20 Jun 2026 23:28:35 +0200 Subject: [PATCH] feat(docker): share dev data with runtime --- .changeset/docker-shared-dev-data.md | 5 +++++ README.md | 2 +- docker/README.md | 32 +++++++++++++++++++++++++++- docker/compose.dev.yml | 5 ++--- 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 .changeset/docker-shared-dev-data.md diff --git a/.changeset/docker-shared-dev-data.md b/.changeset/docker-shared-dev-data.md new file mode 100644 index 0000000..3ab67da --- /dev/null +++ b/.changeset/docker-shared-dev-data.md @@ -0,0 +1,5 @@ +--- +"@jmfederico/pi-web": patch +--- + +Share the Docker development data mount with the runtime Docker data directory by default so Pi sessions can be reused across modes. diff --git a/README.md b/README.md index 3ba2682..61ad3ba 100644 --- a/README.md +++ b/README.md @@ -255,7 +255,7 @@ export DOCKER_GID=$(stat -c '%g' /var/run/docker.sock) docker compose -f docker/compose.dev.yml up --build ``` -Open . The Docker dev setup keeps `sessiond` separate from the autoreloading web/API/client service. See the [Docker guide](https://github.com/jmfederico/pi-web/blob/main/docker/README.md#development-docker-setup). +Open . The Docker dev setup keeps `sessiond` separate from the autoreloading web/API/client service and uses the runtime Docker data directory by default so sessions can be shared across modes. See the [Docker guide](https://github.com/jmfederico/pi-web/blob/main/docker/README.md#development-docker-setup). ## Production-style run from a checkout diff --git a/docker/README.md b/docker/README.md index f3440aa..2eab487 100644 --- a/docker/README.md +++ b/docker/README.md @@ -173,7 +173,7 @@ docker compose exec web hostexec uname -a ## Development Docker setup -Use this mode when developing PI WEB from this checkout. It bind-mounts the source tree, keeps dependencies and PI WEB data in Docker volumes, and preserves the split runtime model: +Use this mode when developing PI WEB from this checkout. It bind-mounts the source tree, keeps dependencies in a Docker volume, stores PI WEB/Pi data in the same host data directory as runtime mode by default, and preserves the split runtime model: - `sessiond` runs `npm run start:sessiond` as the long-lived owner of Pi agent runtimes; - `web` runs `npm run dev:web` and `npm run dev:client` so API, plugin, and Vite changes can autoreload without restarting `sessiond`. @@ -184,10 +184,20 @@ From the repository root: export PI_WEB_UID=$(id -u) export PI_WEB_GID=$(id -g) export DOCKER_GID=$(stat -c '%g' /var/run/docker.sock) +# Optional; this is also the default dev data path. +export PI_WEB_DOCKER_DATA_DIR=${PI_WEB_DOCKER_DATA_DIR:-$HOME/.local/share/pi-web-docker/data} +mkdir -p "$PI_WEB_DOCKER_DATA_DIR" docker compose -f docker/compose.dev.yml up --build ``` +If you already ran the runtime installer, you can reuse its `.env` so dev mode gets the same UID/GID, Docker group, ports, and data directory: + +```bash +docker compose --env-file "$HOME/.local/share/pi-web-docker/.env" \ + -f docker/compose.dev.yml up --build +``` + Open the Vite UI at . The dev API is published on . Useful development commands: @@ -204,6 +214,26 @@ Restart `sessiond` manually after changes that affect `src/server/sessiond.ts`, The dev setup intentionally has the same Docker socket and broad host mounts as the runtime setup. The same trust warnings apply. +### Sharing runtime and development state + +Runtime and dev mode both use `/data` inside the containers. By default they now point at the same host directory: + +```text +$HOME/.local/share/pi-web-docker/data +``` + +Pi session files are therefore shared at: + +```text +$HOME/.local/share/pi-web-docker/data/pi-agent/sessions/ +``` + +Set `PI_WEB_DOCKER_DATA_DIR=/some/path` for both modes if you want that shared data somewhere else. + +Use this shared directory to switch between runtime and dev mode, not to run both at the same time. Stop one Compose stack before starting the other so two session daemons do not share the same socket/state directory concurrently. + +For sessions to appear under the same workspace in both modes, use the same project path in PI WEB. On Flatcar, prefer host-mounted paths such as `/home/core/`, `/srv/`, or `/opt/`. The dev container also exposes this checkout as `/workspace` so the PI WEB dev server can run from it, but sessions started against `/workspace` are organized under that different working-directory path and will not line up with runtime sessions for `/home/core/`. + When `package-lock.json` changes, rebuild the dev image and recreate the `node_modules` volume so the bind-mounted checkout sees the new dependency tree: ```bash diff --git a/docker/compose.dev.yml b/docker/compose.dev.yml index c85fe2a..b5359dc 100644 --- a/docker/compose.dev.yml +++ b/docker/compose.dev.yml @@ -22,8 +22,8 @@ x-pi-web-dev-volumes: &pi-web-dev-volumes - type: volume source: node_modules target: /workspace/node_modules - - type: volume - source: data + - type: bind + source: ${PI_WEB_DOCKER_DATA_DIR:-${HOME}/.local/share/pi-web-docker/data} target: /data - type: bind source: /var/run/docker.sock @@ -91,5 +91,4 @@ services: start_period: 10s volumes: - data: node_modules: