FROM node:20-bookworm-slim # System dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ git \ ca-certificates \ curl \ && rm -rf /var/lib/apt/lists/* # Install OpenCode globally via the official installer. # OPENCODE_INSTALL_DIR points the installer at /usr/local/bin so the # `opencode` binary is on the default PATH for every user. ENV OPENCODE_INSTALL_DIR=/usr/local/bin RUN curl -fsSL https://opencode.ai/install | bash # Hugging Face Spaces runs containers as UID 1000. RUN useradd -m -u 1000 user ENV HOME=/home/user # Make sure the `user` account picks up /usr/local/bin (root's PATH already # includes it, but $HOME/.local/bin is the conventional place for user bins). ENV PATH=/home/user/.local/bin:/usr/local/bin:${PATH} # Create a workspace directory the user can clone projects into and own it. RUN mkdir -p $HOME/workspace && chown -R user:user $HOME USER user WORKDIR $HOME/workspace # The port must match `app_port` in the README's YAML block. EXPOSE 4096 # Start the OpenCode web server. # --hostname 0.0.0.0 => reachable by HF's reverse proxy (not just localhost) # OPENCODE_SERVER_PASSWORD env var (set as a Space secret) enables basic auth. CMD ["opencode", "web", "--port", "4096", "--hostname", "0.0.0.0"]