Ghinayunita p-yan commited on
Commit
7ca4acf
Β·
0 Parent(s):

Duplicate from p-yan/opencode-cloud

Browse files

Co-authored-by: Peter Yan <p-yan@users.noreply.huggingface.co>

Files changed (3) hide show
  1. .gitattributes +35 -0
  2. Dockerfile +36 -0
  3. README.md +87 -0
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM node:20-bookworm-slim
2
+
3
+ # System dependencies
4
+ RUN apt-get update && apt-get install -y --no-install-recommends \
5
+ git \
6
+ ca-certificates \
7
+ curl \
8
+ && rm -rf /var/lib/apt/lists/*
9
+
10
+ # Install OpenCode globally via the official installer.
11
+ # OPENCODE_INSTALL_DIR points the installer at /usr/local/bin so the
12
+ # `opencode` binary is on the default PATH for every user.
13
+ ENV OPENCODE_INSTALL_DIR=/usr/local/bin
14
+ RUN curl -fsSL https://opencode.ai/install | bash
15
+
16
+ # Hugging Face Spaces runs containers as UID 1000.
17
+ RUN useradd -m -u 1000 user
18
+
19
+ ENV HOME=/home/user
20
+ # Make sure the `user` account picks up /usr/local/bin (root's PATH already
21
+ # includes it, but $HOME/.local/bin is the conventional place for user bins).
22
+ ENV PATH=/home/user/.local/bin:/usr/local/bin:${PATH}
23
+
24
+ # Create a workspace directory the user can clone projects into and own it.
25
+ RUN mkdir -p $HOME/workspace && chown -R user:user $HOME
26
+
27
+ USER user
28
+ WORKDIR $HOME/workspace
29
+
30
+ # The port must match `app_port` in the README's YAML block.
31
+ EXPOSE 4096
32
+
33
+ # Start the OpenCode web server.
34
+ # --hostname 0.0.0.0 => reachable by HF's reverse proxy (not just localhost)
35
+ # OPENCODE_SERVER_PASSWORD env var (set as a Space secret) enables basic auth.
36
+ CMD ["opencode", "web", "--port", "4096", "--hostname", "0.0.0.0"]
README.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: OpenCode Cloud
3
+ emoji: πŸ€–
4
+ colorFrom: blue
5
+ colorTo: indigo
6
+ sdk: docker
7
+ app_port: 4096
8
+ pinned: false
9
+ license: mit
10
+ ---
11
+
12
+ # OpenCode on Hugging Face Spaces
13
+
14
+ Run [OpenCode](https://opencode.ai) β€” an open-source AI coding agent that supports 75+ LLM providers β€” in your browser, hosted on Hugging Face's free CPU tier.
15
+
16
+ ## Setup (one-time, ~2 minutes)
17
+
18
+ 1. **Duplicate this Space** to your own HF account (top-right β†’ `Duplicate Space`).
19
+ 2. **Add your secrets** in **Settings β†’ Variables and secrets**:
20
+
21
+ | Secret name | Required? | Where to get it |
22
+ |---|---|---|
23
+ | `OPENCODE_SERVER_PASSWORD` | Yes | Any password you choose β€” protects the web UI |
24
+ | `ANTHROPIC_API_KEY` | One of these | https://console.anthropic.com |
25
+ | `OPENAI_API_KEY` | (pick your | https://platform.openai.com/api-keys |
26
+ | `GEMINI_API_KEY` | provider) | https://aistudio.google.com/apikey |
27
+ | `OPENCODE_API_KEY` | | https://opencode.ai/zen (curated models) |
28
+
29
+ 3. The Space will rebuild (~60-90 seconds) and start on the URL shown above.
30
+ 4. Log in with username **`opencode`** and the password you set.
31
+
32
+ That's it. You now have a free, browser-accessible AI coding agent.
33
+
34
+ ## How it works
35
+
36
+ - The `Dockerfile` installs [OpenCode](https://opencode.ai) via the official install script and runs `opencode web`.
37
+ - The web UI is bound to `0.0.0.0:4096` so HF's reverse proxy can reach it.
38
+ - HTTP basic auth is enabled via the `OPENCODE_SERVER_PASSWORD` secret.
39
+ - Your workspace lives at `/home/user/workspace` inside the container.
40
+
41
+ ## Using OpenCode
42
+
43
+ Once you're in the web UI:
44
+
45
+ - **New session** β†’ describe what you want to build, refactor, or fix
46
+ - **Files panel** β†’ browse your workspace, upload code, or open the in-browser editor
47
+ - **Plan mode** (press `Tab`) β†’ have the agent draft a plan before changing anything
48
+ - **Share** β†’ get a public link to any session for sharing or debugging
49
+ - **`/init`** β†’ generates an `AGENTS.md` for your project so OpenCode remembers context across sessions
50
+
51
+ For full usage docs, see https://opencode.ai/docs/
52
+
53
+ ## Persistence: read this
54
+
55
+ **Free CPU Spaces are ephemeral.** Anything not pushed to git will be lost when the Space restarts (which happens after ~48h of inactivity, or when the free tier quota resets).
56
+
57
+ **Recommended workflow:**
58
+
59
+ 1. In the OpenCode terminal, `cd workspace`
60
+ 2. `git clone https://github.com/your-user/your-repo.git`
61
+ 3. Work on the project
62
+ 4. `git add . && git commit -m "..." && git push` before stepping away
63
+
64
+ For pure scratch work (no git), everything resets on restart β€” so commit early and often.
65
+
66
+ ## Caveats
67
+
68
+ - **CPU only** β€” no GPU. The agent works fine; you just can't run local LLMs here.
69
+ - **Sleeps after ~48h idle** on the free tier (Hugging Face does this automatically).
70
+ - **Resource limits** β€” free CPU Spaces are throttled compared to local dev. Heavy multi-file refactors can be slower.
71
+ - **No outbound ports** β€” the agent can `git clone` public repos, but you can't expose additional services.
72
+ - **CORS / session storage** β€” sessions live in the container's filesystem, so restarts wipe them. Use the `/share` command to save a session URL externally.
73
+
74
+ ## If you want to upgrade later
75
+
76
+ When you outgrow the free tier:
77
+
78
+ | Need | Upgrade to |
79
+ |---|---|
80
+ | Always-on, no sleep | HF Spaces paid CPU ($0.03/hr β‰ˆ $5/mo) |
81
+ | Persistent storage | HF Spaces Storage bucket add-on |
82
+ | More CPU/RAM | Spaces hardware upgrade to `cpu-upgrade` or `cpu-performance` |
83
+ | Always-on + git auto-sync | Self-host on Oracle Cloud Always Free (24GB RAM, 4 ARM cores) β€” different guide |
84
+
85
+ ## License
86
+
87
+ MIT. OpenCode is Β© Anomaly. This Dockerfile is just glue.