A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Fix Docker startup permissions and add inline Compose setup
klarkxyced7204a76e9
diff --git a/.dockerignore b/.dockerignoreindex d0f907e8..a1d674ad 100644--- a/.dockerignore+++ b/.dockerignore@@ -9,3 +9,5 @@ docs/imagesdocker/datadocker/workspacedocker/.env+.env+docker-compose.override.ymldiff --git a/.github/workflows/test.yml b/.github/workflows/test.ymlindex 8bcc79de..d2a544d0 100644--- a/.github/workflows/test.yml+++ b/.github/workflows/test.yml@@ -54,13 +54,27 @@ jobs:env:SCAN_EXTRA_PATTERNS: ${{ secrets.SCAN_EXTRA_PATTERNS }}+ docker:+ name: Docker startup and data migration+ runs-on: ubuntu-latest+ timeout-minutes: 20+ steps:+ - uses: actions/checkout@v4+ - uses: actions/setup-node@v4+ with:+ node-version: 24+ - run: docker compose -f docker-compose.yml config --quiet+ - run: docker compose -f docker/compose.yml config --quiet+ - run: docker build -f docker/Dockerfile -t ds-bot:test .+ - run: node docker/test.mjs ds-bot:test+# The one check that branch rules require. A job whose needs failed is skipped,# and GitHub counts a skipped required check as passed, so this job always runs- # and fails unless every matrix entry and the leak scan passed.+ # and fails unless the matrix, leak scan and Docker checks passed.result:name: Test result- needs: [test, scan]+ needs: [test, scan, docker]if: always()runs-on: ubuntu-lateststeps:- - run: test "${{ needs.test.result }}" = success && test "${{ needs.scan.result }}" = success+ - run: test "${{ needs.test.result }}" = success && test "${{ needs.scan.result }}" = success && test "${{ needs.docker.result }}" = successdiff --git a/.gitignore b/.gitignoreindex d07c5286..e495159a 100644--- a/.gitignore+++ b/.gitignore@@ -17,3 +17,5 @@ node_modules//docker/data//docker/workspace//docker/.env+/.env+/docker-compose.override.ymldiff --git a/docker-compose.yml b/docker-compose.ymlnew file mode 100644index 00000000..17db2dd6--- /dev/null+++ b/docker-compose.yml@@ -0,0 +1,35 @@+# From the repository root:+# docker compose up -d --build+# Configure this file directly; no .env file is needed.+# Do not commit this file after filling in real API keys.+services:+ ds-bot:+ image: ds-bot:local+ pull_policy: never+ build:+ context: .+ dockerfile: docker/Dockerfile+ args:+ NPM_REGISTRY: https://registry.npmjs.org/+ ports:+ - "0.0.0.0:13080:3080"+ environment:+ DEEPSEEK_API_KEY: ""+ # Uncomment for another Anthropic-Messages-compatible endpoint.+ # DEEPSEEK_BASE_URL: "https://your-endpoint.example"+ # Add custom provider keys here when referenced by your DSH config.+ # RELAY_API_KEY: ""+ PUID: "1000"+ PGID: "1000"+ # Add your NAS/LAN IP and host names, without ports.+ DSH_TRUSTED_HOST: "localhost,127.0.0.1"+ DSH_HOST: "0.0.0.0"+ DSH_LISTEN_PORT: "3080"+ # DSH_TELEMETRY_DISABLED: "1"+ volumes:+ - ./docker/data:/data+ - ./docker/workspace:/workspace+ extra_hosts:+ - "host.docker.internal:host-gateway"+ restart: unless-stopped+ stop_grace_period: 15sdiff --git a/docker/Dockerfile b/docker/Dockerfileindex 3810fbf3..e969817d 100644--- a/docker/Dockerfile+++ b/docker/Dockerfile@@ -40,7 +40,7 @@ COPY --from=build /usr/local/ /usr/local/COPY --from=build /opt/dsh-template /opt/dsh-templateCOPY --from=build /tmp/ds-bot.tgz /opt/ds-bot/ds-bot.tgzCOPY --from=build /pnpm-version /opt/ds-bot/pnpm-version-COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh+COPY --chmod=0755 docker/entrypoint.sh /usr/local/bin/entrypoint.shCOPY docker/docker.patch.yml /opt/ds-bot/docker.patch.yml# pnpm as a plain global install (same version the build used) so plugindiff --git a/docker/README.md b/docker/README.mdindex ac00b0b2..55a37824 100644--- a/docker/README.md+++ b/docker/README.md@@ -15,21 +15,40 @@ box. The container is the sandbox boundary — see [Permissions](#permissions).## Quick start+From the repository root, edit `docker-compose.yml`: fill in+`DEEPSEEK_API_KEY`, add the NAS IP to `DSH_TRUSTED_HOST`, and set `PUID`/`PGID`+to the share owner's IDs. Environment variables, ports and paths are all+configured directly in this file; no `.env` is needed. Do not commit real keys.+```sh-cd docker-cp .env.example .env-# edit .env: DEEPSEEK_API_KEY, DSH_TRUSTED_HOST (the NAS IP), PUID/PGID-docker compose up -d-docker compose logs ds-bot | grep "dsh web:"+docker compose up -d --build+docker compose logs ds-bot```+This builds the local image without pulling a published DS Bot image. The root+Compose file publishes host port **13080**, and stores data and workspace files+in `docker/data` and `docker/workspace`.+The log prints a line like `dsh web: http://127.0.0.1:3080/?token=… (LAN:http://172.x.x.x:3080/?token=…)`. Take the token from it and open-`http://<NAS IP>:3080/?token=…` once in your browser: the token sets a signed+`http://<NAS IP>:13080/?token=…` once in your browser: the token sets a signedcookie (valid 30 days, bound to that authority), after which-`http://<NAS IP>:3080/` opens the UI directly. The first time the team opens,+`http://<NAS IP>:13080/` opens the UI directly. The printed port is the container's;+use the host port from `ports:` when opening it. The first time the team opens,DS Bot creates a Main Bot called Chief.+An alternative for users who prefer `.env` is still available in `docker/`:++```sh+cd docker+cp .env.example .env+# Edit .env: DEEPSEEK_API_KEY, DSH_TRUSTED_HOST, PUID/PGID.+docker compose up -d --build+```++That file publishes host port **3080** by default. Choose one deployment+method; do not run both against the same data directory.+## PermissionsThe container is the only sandbox. DSH's own kernel sandbox (bubblewrap /@@ -68,14 +87,17 @@ reverse proxy in front for regular use.## Environment variables-See `.env.example` for the full list. The main ones:+In the root `docker-compose.yml`, edit container variables under `environment`,+the published port under `ports`, and host directories under `volumes`.+The alternative `docker/compose.yml` reads these settings from `.env`;+see `docker/.env.example` for its full list. The main variables are:| Variable | Purpose ||---|---|| `DEEPSEEK_API_KEY` | API key for the model endpoint || `DEEPSEEK_BASE_URL` | Override the endpoint (Anthropic-Messages-compatible) || `DSH_TRUSTED_HOST` | Comma-separated host names / IPs the UI answers to |-| `DSH_PORT` | Published port on the Docker host (default 3080; the container always listens on 3080) |+| `DSH_PORT` | Alternative `.env` deployment's host port (default 3080); edit `ports` directly in the root Compose file || `DSH_HOST` | Bind address: `0.0.0.0` (default) or `127.0.0.1`; only relevant with `network_mode: host` || `DSH_LISTEN_PORT` | Listen port inside the container (default 3080); only relevant with `network_mode: host` || `PUID` / `PGID` | User/group the server runs as and new files belong to |@@ -110,8 +132,9 @@ layer, applied after the profile's own — with an `llm-pi-ai` provider and anmodel: my-model```-`RELAY_API_KEY` rides in from `.env` through `env_file`. The alternative is-Settings → Models in the UI, which writes the same config.+Add `RELAY_API_KEY` under `environment` in the root Compose file, or to `.env`+for the alternative deployment. The alternative is Settings → Models in the+UI, which writes the same config.## Data@@ -122,6 +145,13 @@ Settings → Models in the UI, which writes the same config.**Backup**: stop the container, then copy `DATA_DIR`. Restore by putting thefolder back and starting again.+On every start, entries in `/data` with a different owner or group are assigned+to `PUID`/`PGID`, including existing profiles and restored files. This scans the+data directory, so large histories can take longer to start. It does not follow+symbolic links or descend into other filesystems. A populated `/workspace` keeps+its ownership; if you change `PUID`/`PGID`, grant the new user access to that+share on the host.+## Updating```sh@@ -155,3 +185,13 @@ container's workspace is always `/workspace`).clear text — use HTTPS off-box (see [Network](#network)).- Full access is the only permission mode: a Bot can change everything thecontainer can see.++## Testing++After building the image, run `node docker/test.mjs ds-bot:local` from the+repository root. The test uses isolated, network-disabled containers and+temporary Docker volumes, with no host directory mounts or model calls. It+checks entrypoint permissions, first start, UID/GID changes, restored files,+workspace ownership, offline plugin reinstall and web startup. All test+containers and volumes are removed when it finishes. CI builds the image from+the Linux checkout and runs this test as part of the required Test result check.diff --git a/docker/entrypoint.sh b/docker/entrypoint.shindex ddb198a6..acc08f17 100644--- a/docker/entrypoint.sh+++ b/docker/entrypoint.sh@@ -13,11 +13,11 @@ usermod -o -u "$PUID" nodeif [ ! -d /data/profiles/web ]; thenmkdir -p /datacp -a /opt/dsh-template/. /data/- chown -R node:node /datafi-# Every start: /data itself must be writable by node; the files below keep the-# ownership they got on first start or from the host.-chown node:node /data+# Existing profiles and restored backups can belong to a previous PUID/PGID.+# Do not follow links into workspace shares or descend into other filesystems.+find -P /data -xdev \( ! -uid "$PUID" -o ! -gid "$PGID" \) \+ -exec chown -h node:node -- {} +mkdir -p /workspace# Only claim an empty /workspace; a populated share keeps its owners.diff --git a/docker/test.mjs b/docker/test.mjsnew file mode 100644index 00000000..09748069--- /dev/null+++ b/docker/test.mjs@@ -0,0 +1,144 @@+import assert from 'node:assert/strict'+import { randomUUID } from 'node:crypto'+import { spawnSync } from 'node:child_process'+import { setTimeout } from 'node:timers/promises'++const image = process.argv[2] ?? 'ds-bot:local'+const name = `ds-bot-test-${randomUUID()}`+const data = `${name}-data`+const workspace = `${name}-workspace`+const containers = new Set()+const volumes = []++function docker(args, { allowFailure = false } = {}) {+ const result = spawnSync('docker', args, {+ encoding: 'utf8',+ timeout: 120_000,+ maxBuffer: 1024 * 1024,+ })+ if (!allowFailure && (result.error || result.status !== 0)) {+ throw new Error(`docker ${args[0]} failed: ${result.error?.message ?? result.stderr}`)+ }+ return result+}++function mounts() {+ return [+ '--mount', `type=volume,src=${data},dst=/data`,+ '--mount', `type=volume,src=${workspace},dst=/workspace`,+ ]+}++function run(args) {+ const container = `${name}-${containers.size}`+ containers.add(container)+ return docker(['run', '--rm', '--name', container, '--network', 'none', ...mounts(), ...args])+}++function shell(script) {+ return run(['--entrypoint', '/bin/sh', image, '-eu', '-c', script])+}++function startHelp(uid, gid) {+ run(['-e', `PUID=${uid}`, '-e', `PGID=${gid}`, image, '--help'])+}++function checkDataOwner(uid, gid) {+ shell(`+ test -z "$(find -P /data -xdev \\( ! -uid ${uid} -o ! -gid ${gid} \\) -print -quit)"+ test "$(stat -c %a /data/profiles/web/package.json)" = 600+ test "$(cat /data/review-state.txt)" = preserved+ test "$(stat -c %u:%g /workspace)" = 2345:2346+ test "$(stat -c %u:%g /workspace/keep.txt)" = 2345:2346+ test "$(cat /workspace/keep.txt)" = untouched+ `)+}++try {+ for (const volume of [data, workspace]) {+ docker(['volume', 'create', volume])+ volumes.push(volume)+ }++ shell(`+ test "$(stat -c %a /usr/local/bin/entrypoint.sh)" = 755+ /bin/sh -n /usr/local/bin/entrypoint.sh+ `)+ startHelp(1000, 1000)+ shell(`+ test "$(stat -c %u:%g /data/profiles/web/package.json)" = 1000:1000+ printf preserved > /data/review-state.txt+ chmod 600 /data/review-state.txt+ chown 1000:1000 /data/review-state.txt+ printf untouched > /workspace/keep.txt+ chown 2345:2346 /workspace /workspace/keep.txt+ ln -s /workspace /data/workspace-link+ ln -s /workspace/keep.txt /data/file-link+ ln -s /missing-target /data/dangling-link+ `)+ console.log('PASS: executable entrypoint and first start')++ startHelp(1234, 1234)+ checkDataOwner(1234, 1234)+ console.log('PASS: UID/GID migration preserves data and workspace link targets')++ startHelp(1234, 1235)+ checkDataOwner(1234, 1235)+ shell(`+ mkdir -p /data/restored+ printf restored > /data/restored/private.txt+ chmod 700 /data/restored+ chmod 600 /data/restored/private.txt+ chown -R 3456:3457 /data/restored+ `)+ startHelp(1234, 1235)+ checkDataOwner(1234, 1235)+ console.log('PASS: group-only migration and restored files with mixed ownership')++ shell(`+ node -e 'const fs = require("node:fs"); const path = "/data/profiles/web/node_modules/ds-bot/package.json"; const pkg = JSON.parse(fs.readFileSync(path)); pkg.version = "0.0.1"; fs.writeFileSync(path, JSON.stringify(pkg))'+ `)+ startHelp(1234, 1235)+ shell(`+ test "$(jq -r .version /data/profiles/web/node_modules/ds-bot/package.json)" = "$(jq -r .version /opt/dsh-template/profiles/web/node_modules/ds-bot/package.json)"+ `)+ console.log('PASS: offline plugin reinstall after migration')++ const server = `${name}-web`+ containers.add(server)+ docker([+ 'run', '--detach', '--rm', '--name', server, '--network', 'none', ...mounts(),+ '-e', 'PUID=1234', '-e', 'PGID=1235', '-e', 'DSH_TELEMETRY_DISABLED=1', image,+ ])+ const probe = `+ const response = await fetch('http://127.0.0.1:3080/');+ if (![200, 401].includes(response.status)) throw new Error('Unexpected HTTP status: ' + response.status);+ `+ const deadline = Date.now() + 45_000+ let ready = false+ while (Date.now() < deadline) {+ if (docker(['exec', server, 'node', '--input-type=module', '-e', probe], { allowFailure: true }).status === 0) {+ ready = true+ break+ }+ await setTimeout(300)+ }+ assert.ok(ready, 'web server must answer HTTP after ownership migration')+ const processOwner = docker(['exec', server, 'stat', '-c', '%u:%g', '/proc/1']).stdout.trim()+ assert.equal(processOwner, '1234:1235', 'web process must run under the new identity')+ const identity = docker(['exec', server, 'gosu', 'node', 'id']).stdout+ assert.match(identity, /uid=1234\(node\) gid=1235\(node\)/)+ docker(['exec', server, 'gosu', 'node', '/bin/sh', '-eu', '-c', `+ test "$(cat /data/review-state.txt)" = preserved+ test "$(cat /data/restored/private.txt)" = restored+ test -w /data/profiles/web/package.json+ `])+ console.log('PASS: web startup and private data access under the new identity')+} finally {+ for (const container of containers) {+ docker(['rm', '--force', container], { allowFailure: true })+ }+ for (const volume of volumes) {+ docker(['volume', 'rm', volume])+ }+}