Skip to content

Commit 13720b0

Browse files
author
opencode-bot
committed
feat(config): add server.docker (and image) to auto-use Docker server for TUI when enabled; update TUI to honor config
1 parent 544ccce commit 13720b0

4 files changed

Lines changed: 60 additions & 0 deletions

File tree

.opencode/docker-server-pr.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Adds an optional Docker-backed server mode for the TUI and headless server to isolate the runtime environment without sacrificing TUI performance.
2+
3+
Why
4+
- Improve security/isolation by running the server in a container
5+
- Avoid host tooling/version conflicts while keeping the TUI native on the host
6+
- Keep this fully optional; default behavior is unchanged
7+
8+
What
9+
- TUI/Serve: `--docker` flag to start the server in Docker, mounting `$PWD` to `/workspace` and mapping a host port to container `8080`.
10+
- Image: default to `opencodeai/opencode:server`; support `--docker-image`.
11+
- Local builds: support `--dockerfile`, `--docker-context`, `--docker-build` for building a local image; added `script/docker-build` and `docker:build` script.
12+
- Auth: sync only opencode-managed provider credentials to the server (`PUT /auth/:id`) and inject only provider-defined env vars (from models.dev) into the container (e.g. `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`). No $HOME/XDG dirs are mounted.
13+
- Dockerfile: based on `oven/bun`; installs minimal tools (`git`, `curl`, `unzip`, `tar`, `nodejs`, `npm`, `golang`) and runs `bun run /app/src/index.ts serve --hostname 0.0.0.0 --port 8080`.
14+
- CI: GitHub Action to publish `opencodeai/opencode:server` on release (multi-arch).
15+
- Docs: README snippet for Docker usage.
16+
17+
Usage
18+
- TUI: `opencode --docker` (uses Hub image) or `opencode --docker --docker-image opencode:local` after a local build
19+
- Serve: `opencode serve --docker --port 8080`
20+
- Build: `bun run docker:build` (tags both `opencodeai/opencode:server` and `opencode:local`)
21+
22+
Notes
23+
- Backwards-compatible and opt-in.
24+
- Only provider credentials are synced; no other host secrets are exposed.

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ Or use the helper:
126126
./script/docker-build [Dockerfile] [context]
127127
```
128128

129+
Auto-enable Docker mode via config:
130+
131+
```jsonc
132+
// ~/.config/opencode/config.json
133+
{
134+
"server": {
135+
"docker": true,
136+
"image": "opencodeai/opencode:server"
137+
}
138+
}
139+
```
140+
129141
#### Development Notes
130142

131143
**API Client**: After making changes to the TypeScript API endpoints in `packages/opencode/src/server/server.ts`, you will need the opencode team to generate a new stainless sdk for the clients.

packages/opencode/src/cli/cmd/tui.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,17 @@ export const TuiCommand = cmd({
132132
return "needs_provider"
133133
}
134134
const cfg = await Config.get()
135+
<<<<<<< HEAD
135136
const useDocker = (args.docker ?? (cfg.server?.docker === true)) === true
136137

137138
const server = await (async () => {
138139
if (!useDocker) {
140+
=======
141+
const docker = (args.docker ?? (cfg.server?.docker === true)) === true
142+
143+
const server = await (async () => {
144+
if (!docker) {
145+
>>>>>>> 31983999 (feat(config): add server.docker (and image) to auto-use Docker server for TUI when enabled; update TUI to honor config)
139146
return Server.listen({ port: args.port, hostname: args.hostname })
140147
}
141148

@@ -228,9 +235,15 @@ export const TuiCommand = cmd({
228235
port,
229236
url,
230237
stop: async () => {
238+
<<<<<<< HEAD
231239
const stop = Bun.spawn({ cmd: [dockerBin, "stop", id], stdout: "ignore", stderr: "inherit" })
232240
await stop.exited
233241
},
242+
=======
243+
const stop = Bun.spawn({ cmd: [dockerBin, "stop", id], stdout: "ignore", stderr: "inherit" })
244+
await stop.exited
245+
},
246+
>>>>>>> 31983999 (feat(config): add server.docker (and image) to auto-use Docker server for TUI when enabled; update TUI to honor config)
234247
}
235248
})()
236249

@@ -254,7 +267,11 @@ export const TuiCommand = cmd({
254267
Log.Default.info("tui", {
255268
cmd,
256269
})
270+
<<<<<<< HEAD
257271
if (useDocker) {
272+
=======
273+
if (docker) {
274+
>>>>>>> 31983999 (feat(config): add server.docker (and image) to auto-use Docker server for TUI when enabled; update TUI to honor config)
258275
const auth = await Auth.all()
259276
await Promise.all(
260277
Object.entries(auth).map(([id, info]) =>

packages/opencode/src/config/config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,13 @@ export namespace Config {
485485
.optional(),
486486
})
487487
.optional(),
488+
server: z
489+
.object({
490+
docker: z.boolean().optional().describe("Run the server in Docker by default for the TUI"),
491+
image: z.string().optional().describe("Default Docker image to use for the server"),
492+
})
493+
.optional()
494+
.describe("Server runtime preferences"),
488495
})
489496
.strict()
490497
.openapi({

0 commit comments

Comments
 (0)