|
| 1 | +# OpenCode CLI Container<!-- omit from toc --> |
| 2 | + |
| 3 | +- [Container Architecture](#container-architecture) |
| 4 | +- [Building the Container Image](#building-the-container-image) |
| 5 | + - [Build Arguments](#build-arguments) |
| 6 | +- [Authentication Setup](#authentication-setup) |
| 7 | + - [Environment File Option](#environment-file-option) |
| 8 | + - [Important Environment Variables](#important-environment-variables) |
| 9 | + - [Verifying Authentication](#verifying-authentication) |
| 10 | +- [Azure Foundry Provider](#azure-foundry-provider) |
| 11 | +- [Working with OpenCode from the Container](#working-with-opencode-from-the-container) |
| 12 | + - [Basic Usage Pattern](#basic-usage-pattern) |
| 13 | + - [Volume Mounts Explained](#volume-mounts-explained) |
| 14 | + - [Working Directory Context](#working-directory-context) |
| 15 | +- [Usage Examples](#usage-examples) |
| 16 | + - [Interactive Session](#interactive-session) |
| 17 | + - [Single Command Execution](#single-command-execution) |
| 18 | + - [Environment File Usage](#environment-file-usage) |
| 19 | + - [Shell Alias for Convenience](#shell-alias-for-convenience) |
| 20 | +- [Included Tooling and Skills](#included-tooling-and-skills) |
| 21 | +- [Release Model](#release-model) |
| 22 | +- [Repository Structure](#repository-structure) |
| 23 | +- [Development and Validation](#development-and-validation) |
| 24 | +- [Troubleshooting](#troubleshooting) |
| 25 | + - [Authentication and Config Issues](#authentication-and-config-issues) |
| 26 | + - [File Access Issues](#file-access-issues) |
| 27 | + - [Build and Runtime Issues](#build-and-runtime-issues) |
| 28 | + |
| 29 | +A containerized OpenCode CLI environment with bundled runtime tooling, provider integrations, |
| 30 | +and OpenCode skills. This image is designed to give you a ready-to-run `opencode` setup for |
| 31 | +local project work while keeping your configuration and working directory mounted from the host. |
| 32 | + |
| 33 | +## Container Architecture |
| 34 | + |
| 35 | +- **OpenCode entrypoint**: The container starts `opencode` directly through `entrypoint.sh` |
| 36 | +- **Bun-based image**: Uses `oven/bun:latest` as the base image and installs `opencode-ai` |
| 37 | +- **Mise-managed tooling**: Activates `mise` for both interactive and non-interactive shells |
| 38 | +- **Curated additions**: Bundles Azure Foundry provider support, helper tooling, and reusable skills |
| 39 | + |
| 40 | +## Building the Container Image |
| 41 | + |
| 42 | +Build from the provided Dockerfile: |
| 43 | + |
| 44 | +```bash |
| 45 | +docker build -t opencode-cli:dev . |
| 46 | +``` |
| 47 | + |
| 48 | +You can also use the included `Makefile`: |
| 49 | + |
| 50 | +```bash |
| 51 | +make build |
| 52 | +``` |
| 53 | + |
| 54 | +### Build Arguments |
| 55 | + |
| 56 | +Customize the image version and local tag as needed: |
| 57 | + |
| 58 | +```bash |
| 59 | +docker build \ |
| 60 | + --build-arg OPENCODE_VERSION=latest \ |
| 61 | + -t opencode-cli:dev . |
| 62 | +``` |
| 63 | + |
| 64 | +With `make`: |
| 65 | + |
| 66 | +```bash |
| 67 | +make build IMAGE=opencode-cli TAG=dev OPENCODE_VERSION=latest |
| 68 | +``` |
| 69 | + |
| 70 | +## Authentication Setup |
| 71 | + |
| 72 | +OpenCode configuration is stored under the container user's config directory. For practical use, |
| 73 | +mount your host home directory so configuration persists across runs. |
| 74 | + |
| 75 | +Typical run pattern: |
| 76 | + |
| 77 | +```bash |
| 78 | +docker run -it --rm \ |
| 79 | + -v $HOME:/home/bun \ |
| 80 | + -v ${PWD}:/work \ |
| 81 | + opencode-cli:dev |
| 82 | +``` |
| 83 | + |
| 84 | +This gives the container access to: |
| 85 | + |
| 86 | +- `/home/bun` for OpenCode config and any persisted credentials |
| 87 | +- `/work` for the project you want OpenCode to read and modify |
| 88 | + |
| 89 | +### Environment File Option |
| 90 | + |
| 91 | +If your OpenCode setup depends on provider-specific environment variables, keep them in a local |
| 92 | +env file instead of placing secrets directly on the command line. |
| 93 | + |
| 94 | +```bash |
| 95 | +install -m 600 /dev/null .env |
| 96 | +${EDITOR:-vi} .env |
| 97 | + |
| 98 | +docker run -it --rm \ |
| 99 | + -v $HOME:/home/bun \ |
| 100 | + -v ${PWD}:/work \ |
| 101 | + --env-file .env \ |
| 102 | + opencode-cli:dev |
| 103 | +``` |
| 104 | + |
| 105 | +Security tips: |
| 106 | + |
| 107 | +- Keep `.env` files out of version control |
| 108 | +- Restrict permissions to the current user only |
| 109 | +- Prefer short-lived credentials where possible |
| 110 | + |
| 111 | +### Important Environment Variables |
| 112 | + |
| 113 | +The exact variables depend on the provider configuration you use with OpenCode. This image does |
| 114 | +not hardcode credentials, so pass provider settings at runtime with `-e` or `--env-file`. |
| 115 | + |
| 116 | +Common patterns include: |
| 117 | + |
| 118 | +- OpenAI-compatible endpoints and API keys |
| 119 | +- Azure-related endpoint, deployment, and credential variables |
| 120 | +- Any custom variables required by OpenCode providers you enable in your config |
| 121 | + |
| 122 | +### Verifying Authentication |
| 123 | + |
| 124 | +Once your configuration is mounted and any required variables are provided, verify the container |
| 125 | +starts correctly: |
| 126 | + |
| 127 | +```bash |
| 128 | +docker run -it --rm \ |
| 129 | + -v $HOME:/home/bun \ |
| 130 | + -v ${PWD}:/work \ |
| 131 | + --env-file .env \ |
| 132 | + opencode-cli:dev --help |
| 133 | +``` |
| 134 | + |
| 135 | +If your setup is correct, OpenCode should start without configuration-related errors. |
| 136 | + |
| 137 | +## Azure Foundry Provider |
| 138 | + |
| 139 | +The image builds and installs the `azure-foundry-provider` package during the Docker build and |
| 140 | +places the compiled provider under `/usr/local/provider/azure-foundry-provider`. |
| 141 | + |
| 142 | +This means the container is prepared for Azure Foundry-oriented OpenCode setups without requiring |
| 143 | +you to compile the provider on first run. Provider credentials and runtime configuration are still |
| 144 | +supplied by your OpenCode config and environment variables. |
| 145 | + |
| 146 | +## Working with OpenCode from the Container |
| 147 | + |
| 148 | +For normal usage, mount both your home directory and the current project directory. |
| 149 | + |
| 150 | +### Basic Usage Pattern |
| 151 | + |
| 152 | +```bash |
| 153 | +docker run -it --rm \ |
| 154 | + -v $HOME:/home/bun \ |
| 155 | + -v ${PWD}:/work \ |
| 156 | + --env-file .env \ |
| 157 | + opencode-cli:dev [OPENCODE_ARGS] |
| 158 | +``` |
| 159 | + |
| 160 | +Replace `[OPENCODE_ARGS]` with the arguments supported by your installed `opencode-ai` version. |
| 161 | + |
| 162 | +### Volume Mounts Explained |
| 163 | + |
| 164 | +- `-v $HOME:/home/bun`: Persists OpenCode config and other user-level state |
| 165 | +- `-v ${PWD}:/work`: Mounts your current project into the container working directory |
| 166 | +- `--env-file .env`: Supplies provider credentials and runtime settings without exposing them in shell history |
| 167 | +- `--rm`: Removes the container after the process exits |
| 168 | +- `-it`: Provides an interactive terminal for CLI workflows |
| 169 | + |
| 170 | +### Working Directory Context |
| 171 | + |
| 172 | +The container runs in `/work`, which maps to your current host directory. This means: |
| 173 | + |
| 174 | +- Project files are immediately available to OpenCode |
| 175 | +- Files created or edited by OpenCode are written back to your local directory |
| 176 | +- Relative paths behave as expected inside the container |
| 177 | + |
| 178 | +## Usage Examples |
| 179 | + |
| 180 | +### Interactive Session |
| 181 | + |
| 182 | +Start an interactive OpenCode session in the current project: |
| 183 | + |
| 184 | +```bash |
| 185 | +docker run -it --rm \ |
| 186 | + -v $HOME:/home/bun \ |
| 187 | + -v ${PWD}:/work \ |
| 188 | + --env-file .env \ |
| 189 | + opencode-cli:dev |
| 190 | +``` |
| 191 | + |
| 192 | +### Single Command Execution |
| 193 | + |
| 194 | +Run a one-off command such as help or version output: |
| 195 | + |
| 196 | +```bash |
| 197 | +docker run -it --rm \ |
| 198 | + -v $HOME:/home/bun \ |
| 199 | + -v ${PWD}:/work \ |
| 200 | + --env-file .env \ |
| 201 | + opencode-cli:dev --version |
| 202 | +``` |
| 203 | + |
| 204 | +### Environment File Usage |
| 205 | + |
| 206 | +If you want to keep project-local settings, create a dedicated env file and reuse it: |
| 207 | + |
| 208 | +```bash |
| 209 | +install -m 600 /dev/null .env |
| 210 | +${EDITOR:-vi} .env |
| 211 | + |
| 212 | +docker run -it --rm \ |
| 213 | + -v $HOME:/home/bun \ |
| 214 | + -v ${PWD}:/work \ |
| 215 | + --env-file .env \ |
| 216 | + opencode-cli:dev --help |
| 217 | +``` |
| 218 | + |
| 219 | +### Shell Alias for Convenience |
| 220 | + |
| 221 | +Create a short alias for daily use: |
| 222 | + |
| 223 | +```bash |
| 224 | +# Add to your ~/.bashrc or ~/.zshrc |
| 225 | +alias opencodec='docker run -it --rm -v $HOME:/home/bun -v ${PWD}:/work --env-file .env opencode-cli:dev' |
| 226 | + |
| 227 | +# Then use simply: |
| 228 | +opencodec --help |
| 229 | +opencodec |
| 230 | +``` |
| 231 | + |
| 232 | +## Included Tooling and Skills |
| 233 | + |
| 234 | +The image currently installs or bundles the following pieces during build: |
| 235 | + |
| 236 | +- `opencode-ai` |
| 237 | +- `mise` |
| 238 | +- `python` |
| 239 | +- `go` |
| 240 | +- `ripgrep` |
| 241 | +- `uv` |
| 242 | +- `git` |
| 243 | +- `sudo`, `curl`, `gpg`, `make` |
| 244 | +- Azure Foundry provider build output |
| 245 | +- OpenCode skills for `humanizer`, `aleph`, and changelog automation |
| 246 | + |
| 247 | +The repository also includes `git-export.py`, a helper script that exports a single directory from |
| 248 | +a GitHub repository using a treeless, sparse clone workflow. |
| 249 | + |
| 250 | +## Release Model |
| 251 | + |
| 252 | +This repo publishes container images to GitHub Container Registry from version tags. |
| 253 | + |
| 254 | +- `create-linked-release.yml` polls an upstream repository release stream and mirrors matching tags into this repo |
| 255 | +- `build-and-deploy.yml` runs on `v*` tags, validates semver, and publishes the image to `ghcr.io/ophiosdev/opencode-cli` |
| 256 | +- Published tags include semver variants, a commit SHA tag, and `latest` when enabled for the default branch |
| 257 | + |
| 258 | +## Repository Structure |
| 259 | + |
| 260 | +- `Dockerfile`: Builds the OpenCode container image and installs providers, tools, and skills |
| 261 | +- `entrypoint.sh`: Loads shell environment and starts `opencode` |
| 262 | +- `git-export.py`: Sparse GitHub directory export helper |
| 263 | +- `Makefile`: Convenience targets for local image build and cleanup |
| 264 | +- `.github/workflows/`: PR validation, release sync, and registry publishing workflows |
| 265 | +- `mise.toml`: Local tool definitions for linting and validation utilities |
| 266 | + |
| 267 | +## Development and Validation |
| 268 | + |
| 269 | +The repo uses `pre-commit` for lightweight validation of committed files. |
| 270 | + |
| 271 | +Configured checks include: |
| 272 | + |
| 273 | +- YAML linting with `yamllint` |
| 274 | +- Dockerfile linting with `hadolint` |
| 275 | +- Markdown linting with `markdownlint-cli2` |
| 276 | +- GitHub Actions validation with `actionlint` |
| 277 | +- Spelling checks with `typos` |
| 278 | + |
| 279 | +The pull request workflow also performs a Docker build smoke test when `Dockerfile` changes. |
| 280 | + |
| 281 | +## Troubleshooting |
| 282 | + |
| 283 | +### Authentication and Config Issues |
| 284 | + |
| 285 | +- Repeated setup prompts: ensure `-v $HOME:/home/bun` is present so config persists |
| 286 | +- Missing credentials: confirm required provider variables are passed with `-e` or `--env-file` |
| 287 | +- Startup config failures: run `opencode-cli:dev --help` first to confirm the base container starts cleanly |
| 288 | + |
| 289 | +### File Access Issues |
| 290 | + |
| 291 | +- Project files not visible: confirm `-v ${PWD}:/work` is included |
| 292 | +- Output files not appearing locally: check that your command is operating inside `/work` |
| 293 | +- Permission mismatches: inspect ownership on your mounted directories and rebuild or adjust runtime strategy if needed |
| 294 | + |
| 295 | +### Build and Runtime Issues |
| 296 | + |
| 297 | +- Build failures fetching dependencies: verify network access to npm, GitHub, and other upstream sources used in the Docker build |
| 298 | +- Provider or skill changes upstream: rebuild the image to refresh fetched components |
| 299 | +- Command invocation errors: place OpenCode arguments after the image name and use `--help` to confirm supported flags |
0 commit comments