Skip to content

feat: initial Containerfile, devfile, and scripts for containerized OpenCode #1

Closed

Description

@jflowers

Context

This is the implementation issue for the containerized OpenCode environment described in Discussion #88. The goal is security through isolation — AI agents run inside a Podman container so destructive actions can't reach the host filesystem.

Platforms: macOS arm64 (MacBook Pro), Fedora amd64 (workstation/server)
CDE: Eclipse Che / Red Hat Dev Spaces via Devfile 2.2.0

Deliverables

1. Containerfile (multi-arch: arm64 + amd64)

Base image: quay.io/fedora/fedora:latest
Published to: quay.io/unbound-force/opencode-dev

Tools to install via go install (no Homebrew in container):

  • uf (github.com/unbound-force/unbound-force/cmd/unbound-force@latest)
  • Dewey (github.com/unbound-force/dewey@latest)
  • Replicator (github.com/unbound-force/replicator/cmd/replicator@latest)
  • Gaze (github.com/unbound-force/gaze/cmd/gaze@latest)
  • golangci-lint (github.com/golangci/golangci-lint/cmd/golangci-lint@latest)
  • govulncheck (golang.org/x/vuln/cmd/govulncheck@latest)

Tools to install via package manager / installer:

  • Go 1.24+ (dnf install golang)
  • Node.js 20+ (dnf install nodejs)
  • Git, gh CLI (dnf install git gh)
  • OpenCode (curl -fsSL https://opencode.ai/install | bash)
  • OpenSpec CLI (npm install -g @fission-ai/openspec@latest)
  • uv + specify CLI (curl -LsSf https://astral.sh/uv/install.sh | sh && uv tool install specify-cli --from git+https://github.com/github/spec-kit.git)

NOT in the container:

  • Ollama — runs on host, container connects via DEWEY_EMBEDDING_ENDPOINT=http://host.containers.internal:11434

Multi-stage build recommended:

  • Stage 1: Go build stage (install all Go tools)
  • Stage 2: Runtime stage (copy binaries + install Node.js/npm tools + OpenCode)
  • Keep Go in final image (agents need go test, go build)

Non-root user: Create a dev user. Container should not run as root.

2. Containerfile.udi (CDE variant)

Base image: quay.io/devfile/universal-developer-image:latest
Same tool installation but UDI already has Go, Node.js, Git pre-installed.

3. devfile.yaml (Eclipse Che / Dev Spaces)

Devfile 2.2.0 spec referencing the custom image:

schemaVersion: 2.2.0
metadata:
  name: unbound-force-workspace
components:
  - name: opencode-runtime
    container:
      image: quay.io/unbound-force/opencode-dev:latest
      memoryLimit: 8G
      cpuLimit: "4"
      mountSources: true
      env:
        - name: DEWEY_EMBEDDING_ENDPOINT
          value: "http://host.containers.internal:11434"
      endpoints:
        - name: opencode-server
          targetPort: 4096
          exposure: internal
commands:
  - id: start-server
    exec:
      component: opencode-runtime
      commandLine: "opencode serve --port 4096 --hostname 0.0.0.0"
      workingDir: /projects
  - id: init-workspace
    exec:
      component: opencode-runtime
      commandLine: "uf init"
      workingDir: /projects

4. devfile-dynamic.yaml (UDI + postStart, no custom image)

Alternative devfile that uses UDI as-is and installs tools via postStart commands. No custom image to maintain but slower workspace start.

5. Scripts

Script Purpose
scripts/install-uf-tools.sh Install all UF tools via go install (used in Containerfile and devfile postStart)
scripts/entrypoint.sh Container entrypoint — auto-runs uf init on first start, starts opencode serve
scripts/extract-changes.sh Git format-patch extraction from container to host
scripts/connect.sh Host-side script to start container + attach via opencode attach

6. podman-compose.yml

Local Podman orchestration for Model B (headless server):

services:
  opencode:
    image: quay.io/unbound-force/opencode-dev:latest
    ports:
      - "4096:4096"
    volumes:
      - ./:/workspace:ro
      - opencode-workdir:/workspace-rw
      - ~/.local/share/opencode:/home/dev/.local/share/opencode
    environment:
      - DEWEY_EMBEDDING_ENDPOINT=http://host.containers.internal:11434
      - OPENCODE_SERVER_PASSWORD=${OPENCODE_SERVER_PASSWORD:-changeme}
    deploy:
      resources:
        limits:
          memory: 8g
          cpus: "4"
    command: opencode serve --port 4096 --hostname 0.0.0.0
volumes:
  opencode-workdir:

7. CI: Multi-arch build + push to quay.io

.github/workflows/build-push.yml:

  • Trigger on push to main and version tags
  • Build for linux/arm64 and linux/amd64
  • Push to quay.io/unbound-force/opencode-dev
  • Tag strategy: latest + semver matching uf releases

8. README.md

Document:

  • 3 deployment models (interactive, headless, CDE)
  • Security model (rootless, read-only mounts, no push creds, resource limits, SELinux)
  • Change extraction (git format-patch vs direct mount)
  • Prerequisites (Podman, Ollama on host)
  • Quick start commands

Security Model

Layer Protection
Podman rootless No root access, user namespace isolation
Read-only mount (Model B) Host filesystem untouched
No push credentials No SSH keys or git push tokens in container
Resource limits --memory 8g --cpus 4
SELinux (Fedora) :Z relabeling
Non-root user Container runs as dev
Ollama on host Embedding model outside blast radius

Change Extraction

Mode 1: Git-based (default)
Agent commits inside container. Host extracts via git format-patch. Human reviews before applying.

Mode 2: Direct mount (convenience)
Read-write mount. Agent writes directly. Host reviews via git diff.

Repo Structure

unbound-force/containerfile/
├── Containerfile
├── Containerfile.udi
├── devfile.yaml
├── devfile-dynamic.yaml
├── podman-compose.yml
├── scripts/
│   ├── install-uf-tools.sh
│   ├── entrypoint.sh
│   ├── extract-changes.sh
│   └── connect.sh
├── README.md
└── .github/
    └── workflows/
        └── build-push.yml

Related

  • Discussion #88 — full architecture and design rationale
  • uf sandbox CLI command — tracked separately in the meta repo (will consume this image)
  • dewey#36 — Dewey startup timeout (closed, fixed)
  • dewey#40 — Dewey relative path fix (closed, fixed)
  • replicator#5 — Replicator init command (closed, done)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions