Update README.md with detailed usage instructions and configuration options for OpenCode on Hugging Face Spaces
Browse files- Dockerfile +37 -0
- README.md +24 -1
Dockerfile
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# OpenCode on Hugging Face Spaces (Docker)
|
| 2 |
+
# 使用官方安装脚本安装 opencode,并以 headless HTTP server 方式暴露 API
|
| 3 |
+
|
| 4 |
+
FROM ubuntu:24.04
|
| 5 |
+
|
| 6 |
+
# 避免交互式提示
|
| 7 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 8 |
+
|
| 9 |
+
# 安装依赖:安装脚本需要 curl、tar(Linux 解压)
|
| 10 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 11 |
+
ca-certificates \
|
| 12 |
+
curl \
|
| 13 |
+
tar \
|
| 14 |
+
git \
|
| 15 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 16 |
+
|
| 17 |
+
# 按 HF Spaces 要求:使用 UID 1000 的用户
|
| 18 |
+
RUN useradd -m -u 1000 user
|
| 19 |
+
|
| 20 |
+
ENV HOME=/home/user
|
| 21 |
+
ENV PATH=/home/user/.opencode/bin:$PATH
|
| 22 |
+
|
| 23 |
+
USER user
|
| 24 |
+
WORKDIR $HOME/app
|
| 25 |
+
|
| 26 |
+
# 使用官方安装脚本安装 opencode(--no-modify-path 不写 shell 配置)
|
| 27 |
+
RUN curl -fsSL https://opencode.ai/install | bash -s -- --no-modify-path
|
| 28 |
+
|
| 29 |
+
# 确保 opencode 在 PATH 中并可用
|
| 30 |
+
RUN opencode --version
|
| 31 |
+
|
| 32 |
+
# Hugging Face Spaces 默认暴露 7860
|
| 33 |
+
EXPOSE 7860
|
| 34 |
+
|
| 35 |
+
# 启动 headless HTTP server,监听 0.0.0.0 以便 Space 代理访问
|
| 36 |
+
# 文档与 API: /doc 为 OpenAPI 3.1 规范
|
| 37 |
+
CMD ["opencode", "serve", "--port", "7860", "--hostname", "0.0.0.0"]
|
README.md
CHANGED
|
@@ -4,7 +4,30 @@ emoji: ⚡
|
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: gray
|
| 6 |
sdk: docker
|
|
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: gray
|
| 6 |
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
pinned: false
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# OpenCode on Hugging Face Spaces
|
| 12 |
+
|
| 13 |
+
本 Space 通过 **Docker** 部署 [OpenCode](https://opencode.ai/) 的 HTTP API 服务(`opencode serve`),可在浏览器中调用 OpenCode 的接口。
|
| 14 |
+
|
| 15 |
+
## 使用方式
|
| 16 |
+
|
| 17 |
+
- **API 文档(OpenAPI 3.1)**:打开 Space 后访问 `/doc`,例如:
|
| 18 |
+
`https://huggingface.co/spaces/<你的用户名>/<Space 名>/doc`
|
| 19 |
+
- **健康检查**:`GET /global/health`
|
| 20 |
+
- 其余接口见 [OpenCode Server 文档](https://opencode.ai/docs/server/),如会话、消息、文件、LSP/MCP 等。
|
| 21 |
+
|
| 22 |
+
## 密钥与配置(可选)
|
| 23 |
+
|
| 24 |
+
若需使用需认证的模型(如 OpenAI、Claude 等),请在 Space 的 **Settings → Repository secrets** 中配置相应环境变量;OpenCode 会读取常见命名(如 `OPENCODE_*` 或各 provider 的 API key 变量)。
|
| 25 |
+
服务端 HTTP Basic 认证可设置:
|
| 26 |
+
|
| 27 |
+
- `OPENCODE_SERVER_PASSWORD`(必填时启用认证)
|
| 28 |
+
- `OPENCODE_SERVER_USERNAME`(可选,默认 `opencode`)
|
| 29 |
+
|
| 30 |
+
## 参考
|
| 31 |
+
|
| 32 |
+
- [Spaces 配置说明](https://huggingface.co/docs/hub/spaces-config-reference)
|
| 33 |
+
- [OpenCode Server](https://opencode.ai/docs/server/)
|