mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
fix(sandbox): pin neutral entrypoint and persist opencode upgrades across rebuilds
This commit is contained in:
1 parent
cadc283738
commit
f2d0ae0595
14 files changed
+339
-15
No files matched your search
@@ -81,6 +81,7 @@ services:
|
||||
volumes:
|
||||
- ${OCM_WORKSPACE_HOST_PATH:-opencode-workspace}:/workspace
|
||||
- opencode-data:/app/data
|
||||
- opencode-bin:/home/node/.opencode/bin
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:5003/api/health"]
|
||||
@@ -94,6 +95,8 @@ volumes:
|
||||
driver: local
|
||||
opencode-data:
|
||||
driver: local
|
||||
opencode-bin:
|
||||
driver: local
|
||||
```
|
||||
|
||||
## Environment Variables
|
||||
@@ -127,8 +130,10 @@ VAPID_SUBJECT=mailto:you@example.com
|
||||
The container entrypoint (`scripts/docker-entrypoint.sh`) automatically:
|
||||
|
||||
1. **Verifies Bun** is installed (installed at build time, fallback install if missing)
|
||||
2. **Verifies OpenCode** is installed (installed at build time, fallback install if missing)
|
||||
3. **Upgrades OpenCode** if below minimum version (1.0.137)
|
||||
2. **Reconciles the persisted OpenCode home binary** (`/home/node/.opencode/bin/opencode`):
|
||||
- any valid persisted binary is retained, including a user-selected version older than the image-bundled `OPENCODE_BUNDLED_VERSION`;
|
||||
- a persisted binary that is malformed or unversioned is removed (only that binary), so `PATH` falls back to the image-bundled `/usr/local/bin/opencode` without a download
|
||||
3. **Installs OpenCode** only when no usable binary is present: if opencode is missing entirely, or if the surviving binary is still below the minimum version (1.0.137), the pinned bundled version is downloaded into the persisted `bin` volume
|
||||
4. **Validates AUTH_SECRET** is set (required for startup)
|
||||
5. **Aligns the `node` account** to `PUID`/`PGID` (default `1000`) before chowning the workspace, the `/app/data` directory, and the `node` home directory. If `PUID`/`PGID` are already used by another account in the image, startup aborts with an explicit error. Group alignment runs first, so a free `PGID` combined with an occupied `PUID` mutates `/etc/group` before the UID collision is detected and aborts startup; realign to the original ids or pick a free pair before retrying.
|
||||
|
||||
@@ -261,6 +266,23 @@ Contains:
|
||||
|
||||
Uses a named volume for data persistence.
|
||||
|
||||
### OpenCode Binary
|
||||
|
||||
```yaml
|
||||
volumes:
|
||||
- opencode-bin:/home/node/.opencode/bin
|
||||
```
|
||||
|
||||
Persists the OpenCode binary that OpenCode's own `upgrade --method curl` command (run from the UI's OpenCode settings) installs into `~/.opencode/bin`, so an upgrade survives container recreations. The volume is limited to the binary and leaves existing workspace and XDG persistence behavior for config, auth, and chat state unchanged.
|
||||
|
||||
On startup the entrypoint reconciles the persisted binary:
|
||||
|
||||
- any valid persisted binary is retained, including a user-selected version older than the image-bundled `OPENCODE_BUNDLED_VERSION`;
|
||||
- a malformed or unversioned persisted binary is removed so `PATH` falls back to the image-bundled `/usr/local/bin/opencode`, avoiding a download;
|
||||
- a persisted binary still below the minimum version (1.0.137) is replaced by the pinned bundled version, which is downloaded into this volume.
|
||||
|
||||
A fresh volume starts empty and the image-bundled binary is used until an upgrade installs into the volume.
|
||||
|
||||
### Import Existing OpenCode Chats From Your Host
|
||||
|
||||
If you already use standalone OpenCode on your machine and want Dockerized OpenCode Manager to show those chats on first setup, bind your host OpenCode config/state into the container and bind your repo root to the same absolute path that standalone OpenCode used.
|
||||
@@ -405,9 +427,12 @@ services:
|
||||
# Start
|
||||
docker-compose up -d
|
||||
|
||||
# Stop
|
||||
# Stop (containers removed; named volumes are preserved)
|
||||
docker-compose down
|
||||
|
||||
# Stop and remove containers and all named volumes (workspace, database, OpenCode binary)
|
||||
docker-compose down -v
|
||||
|
||||
# Restart
|
||||
docker-compose restart
|
||||
|
||||
@@ -418,6 +443,8 @@ docker-compose logs -f
|
||||
docker-compose logs --tail 100
|
||||
```
|
||||
|
||||
The package scripts mirror these: `pnpm docker:down` stops and removes containers while preserving all named volumes, and `pnpm docker:reset` is the destructive variant that also deletes the workspace, database, and OpenCode binary volumes.
|
||||
|
||||
### Maintenance
|
||||
|
||||
```bash
|
||||
|
||||
@@ -61,6 +61,8 @@ All projects share one microVM named `ocm-workspace`:
|
||||
- Each command supplies its own working directory through `msb exec -w`.
|
||||
- A session outside the mounted roots is refused rather than executed on the host.
|
||||
- The Manager verifies the microVM image, resources, user, network policy, mounts (including the `/tmp` tmpfs size and mount options), labels, and secret mask before reuse.
|
||||
- MSB pulls the configured `SANDBOX_IMAGE` (default `node:24`) automatically; no custom image build is needed.
|
||||
- The Manager pins a neutral `/usr/bin/env` entrypoint, so the image's own OCI entrypoint is never inherited.
|
||||
- A stale or unverifiable microVM is removed and recreated.
|
||||
- Manager shutdown and an enforced-to-disabled restart stop the managed microVM.
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ The container automatically:
|
||||
|
||||
- Installs OpenCode if not present
|
||||
- Builds and serves the frontend
|
||||
- Creates persistent volumes for workspace and database
|
||||
- Creates persistent volumes for the workspace, database, and OpenCode binary
|
||||
- Configures health checks and auto-restart
|
||||
|
||||
### Docker Commands
|
||||
@@ -32,9 +32,12 @@ The container automatically:
|
||||
# Start the container
|
||||
docker-compose up -d
|
||||
|
||||
# Stop and remove container
|
||||
# Stop and remove containers (named volumes are preserved)
|
||||
docker-compose down
|
||||
|
||||
# Stop and remove containers and all named volumes (workspace, database, OpenCode binary)
|
||||
docker-compose down -v
|
||||
|
||||
# Rebuild the image
|
||||
docker-compose build
|
||||
|
||||
@@ -54,6 +57,7 @@ docker exec -it opencode-manager sh
|
||||
|--------|---------------|---------|
|
||||
| `opencode-workspace` | `/workspace` | Repository storage |
|
||||
| `opencode-data` | `/app/data` | Database and config |
|
||||
| `opencode-bin` | `/home/node/.opencode/bin` | OpenCode binary, persisted across container recreations |
|
||||
|
||||
## Local Development
|
||||
|
||||
|
||||
@@ -27,6 +27,29 @@ lsof -i :5003
|
||||
docker-compose build --no-cache
|
||||
```
|
||||
|
||||
### Reset a Broken OpenCode Binary
|
||||
|
||||
**Symptoms:** Container won't start after an OpenCode upgrade, or the OpenCode settings show a malformed binary
|
||||
|
||||
The OpenCode binary lives in its own named volume (`opencode-bin`). To remove only that volume and let the entrypoint reinstall the pinned bundled version on next start, without touching the workspace or database volumes:
|
||||
|
||||
```bash
|
||||
docker-compose down
|
||||
# <project> is the Compose project name, usually the directory containing docker-compose.yml
|
||||
docker volume rm <project>_opencode-bin
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
Or via the package scripts:
|
||||
|
||||
```bash
|
||||
pnpm docker:down
|
||||
docker volume rm <project>_opencode-bin
|
||||
pnpm docker:up
|
||||
```
|
||||
|
||||
Do not use `docker-compose down -v` (or `pnpm docker:reset`) here: that also deletes the workspace and database volumes.
|
||||
|
||||
### Port Already in Use
|
||||
|
||||
**Symptoms:** Error about port 5003 being in use
|
||||
|
||||
Reference in new issue
Block a user