Installer

This commit is contained in:
Jarek Rozanski 2026-09-27 20:49:11 +02:00
commit 4cb1328ad6
No known key found for this signature in database
3 changed files with 119 additions and 2 deletions

View file

@ -25,10 +25,31 @@ A rootless Podman container for running [OpenCode](https://github.com/anomalyco/
make build # build (or rebuild) the container image
make opencode # launch the OpenCode TUI in the current directory
make shell # open a bash shell in the container instead
make install # build, then install a global `opencode-sandbox` shortcut (see below)
```
Run `make opencode` or `make shell` from any project directory — the image is shared, so there's nothing per-project to set up.
### `make install`
Installs a shim at `~/.local/bin/opencode-sandbox` that runs `make opencode`
against this repo's Makefile, using whatever directory you're standing in —
not this repo — as `/workspace`. Once installed, `opencode-sandbox` works as
a global command from any directory, no `cd` into this repo required. (Only
`opencode` gets a shortcut; `make shell` still has to be run from here.)
It also makes sure `~/.local/bin` is on `PATH` for future shells, based on
your login shell (`$SHELL`):
- zsh → appended to `~/.zshrc` (or `~/.zshenv` if that's the only one of the two that already exists; `~/.zshrc` is created if neither does)
- bash → `~/.bash_profile` on macOS, `~/.bashrc` on Linux (created if missing)
- fish → added via `fish_add_path` (no config file edit needed)
- anything else → appended to `~/.profile`
The edit is wrapped in `# >>> opencode-sandbox >>>` markers so re-running
`make install` never duplicates it, and is skipped entirely if
`~/.local/bin` is already on `PATH`.
## How it's put together
**Containerfile** — multi-stage build on `debian:trixie-slim`:
@ -37,7 +58,7 @@ Run `make opencode` or `make shell` from any project directory — the image is
- OpenCode is downloaded directly from its canonical GitHub releases (`github.com/anomalyco/opencode`) for the container's architecture, and its SHA256 is checked against a hash pinned in the Containerfile before it's installed — there's no maintainer-published signature for OpenCode releases, so this hash is captured by hand and is the actual root of trust here. Bump `OPENCODE_VERSION` and re-run the `sha256sum` steps documented in the Containerfile's comments whenever you upgrade it.
- A few build-time smoke tests (`ldd`, `java -version`, `node --version`, etc.) fail the build immediately if anything is broken, rather than surfacing at first `make opencode`.
**Makefile** — three targets only, as designed:
**Makefile** — four targets:
- `build` builds the image.
- `opencode` and `shell` both run the container with the same flags: `--userns=keep-id` (so files created in the container are owned by your real host user, not root — verified: rootless Podman's user-namespace remapping means `id` shows `root` *inside* the container's own namespace view, but the file lands on the host owned by your actual UID/GID), the current directory bind-mounted to `/workspace`, and OpenCode's three XDG directories bind-mounted from your home directory: