Skip to content

feat(reach): add --extra-port for ad-hoc port publishing on create#6

Merged
todie merged 1 commit into
mainfrom
feat/extra-port-mapping
Apr 7, 2026
Merged

feat(reach): add --extra-port for ad-hoc port publishing on create#6
todie merged 1 commit into
mainfrom
feat/extra-port-mapping

Conversation

@todie

@todie todie commented Apr 7, 2026

Copy link
Copy Markdown
Member

Summary

Add `reach create --extra-port HOST:CONTAINER` (repeatable) so callers can publish additional ports from the sandbox to the host beyond the built-in vnc/novnc/health trio.

```
reach create --name todie-poster --extra-port 9222
reach create --name foo --extra-port 8080:80 --extra-port 9229:9229
```

Single-port shorthand (`--extra-port 9222`) expands to `9222:9222`.

Why

Driven by a real workflow: a host process needs to drive Chrome's remote debugging port (CDP) inside the sandbox so the host daemon can connect to a browser running under the reach desktop.

Without extra-port mapping the only options are:

  1. Recreating the container manually with `docker run -p` — loses all reach lifecycle management.
  2. Routing through the docker bridge IP — blocked under WSL2 + Docker Desktop, where the host can't reach 172.17.0.x directly.

Implementation

  • `SandboxPorts.extra: Vec<(u16, u16)>` carries the extra pairs through the create pipeline.
  • `SandboxPortMapping.extra` round-trips through the JSON serializer (skipped when empty so existing consumers see no change).
  • `extract_ports` in `docker.rs` recovers extras from `docker ps` output for already-running containers.
  • `reach create` summary prints any extras under an "Extra:" line.
  • `parse_port_pair` validator on the clap arg gives clean error messages on malformed input.

Test plan

  • `cargo fmt --all -- --check` clean
  • `cargo build --release -p reach-cli` succeeds
  • `cargo test -p reach-cli --release` — all 23 unit tests pass (existing JSON test unchanged)
  • Manual e2e: `reach create --name pf --extra-port 9222 && curl http://localhost:9222/json/version\`

🤖 Generated with Claude Code

Add `reach create --extra-port HOST:CONTAINER` (repeatable) and
`SandboxPorts.extra: Vec<(u16, u16)>` to publish additional ports
beyond the built-in vnc/novnc/health trio.

Driven by a real workflow: a host process needs to drive Chrome's
remote debugging port (CDP) inside the sandbox. Without extra-port
mapping the only options are recreating the container manually with
`docker run -p` (loses reach lifecycle management) or routing through
the docker bridge IP (blocked under WSL2 + DockerDesktop).

- Single-port shorthand `--extra-port 9222` expands to `9222:9222`.
- Each pair propagates through HostConfig.port_bindings and
  ExposedPorts so docker actually publishes the mapping.
- Result `SandboxPortMapping.extra` round-trips through the JSON
  serializer (skipped when empty so existing JSON consumers see no
  change), and `extract_ports` recovers it from `docker ps` output.
- `reach create` summary prints any extras under an "Extra:" line.

Tests:
- existing docker_types JSON test still passes (extra defaults to
  empty Vec via the new field with serde skip_serializing_if).
- value_parser unit-tested implicitly via clap on cargo build.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@todie todie merged commit 073aad1 into main Apr 7, 2026
7 of 9 checks passed
@todie todie deleted the feat/extra-port-mapping branch April 7, 2026 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant