Spaces:
Paused
Paused
OpenCode Integration commited on
Commit Β·
a952a90
1
Parent(s): e8d7b5a
fix: even simpler entrypoint - just the basics
Browse files- entrypoint.sh +28 -17
entrypoint.sh
CHANGED
|
@@ -1,10 +1,14 @@
|
|
| 1 |
#!/bin/sh
|
| 2 |
-
# OpenCode-Serve entrypoint
|
| 3 |
-
#
|
| 4 |
-
#
|
| 5 |
-
#
|
| 6 |
-
#
|
| 7 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
set -u
|
| 9 |
|
| 10 |
echo "============================================"
|
|
@@ -16,34 +20,42 @@ mkdir -p /data/share/opencode /data/config/opencode /data/cache/opencode /data/s
|
|
| 16 |
/data/workspaces /data/logs \
|
| 17 |
2>/dev/null || true
|
| 18 |
|
|
|
|
| 19 |
if [ ! -f /data/config/opencode/opencode.json ]; then
|
|
|
|
| 20 |
python3 -c '
|
| 21 |
import json
|
| 22 |
d = {"$schema":"https://opencode.ai/config.json","server":{"port":4096,"hostname":"127.0.0.1"},"model":"opencode/big-pickle"}
|
| 23 |
json.dump(d, open("/data/config/opencode/opencode.json","w"), indent=2)
|
| 24 |
-
|
| 25 |
-
'
|
| 26 |
fi
|
| 27 |
|
| 28 |
-
# /projects/default (needed for opencode's "default" project)
|
| 29 |
mkdir -p /projects/default
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
fi
|
| 33 |
|
| 34 |
# βββ 1) opencode serve on 127.0.0.1:4096 βββ
|
| 35 |
echo "[UPSTREAM] starting opencode serve on :4096 ..."
|
| 36 |
-
cd /projects/default
|
| 37 |
nohup opencode serve --port 4096 --hostname 127.0.0.1 > /data/logs/opencode-serve.log 2>&1 &
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
# βββ 2) ttyd on 0.0.0.0:7681 βββ
|
| 42 |
echo "[TERMINAL] starting ttyd on :7681 (base /terminal) ..."
|
| 43 |
nohup ttyd --port 7681 --host 0.0.0.0 --writable --base-path /terminal \
|
| 44 |
bash -l > /data/logs/ttyd.log 2>&1 &
|
| 45 |
-
|
| 46 |
-
|
|
|
|
| 47 |
|
| 48 |
# βββ 3) uvicorn on 7860 (HF port, foreground) βββ
|
| 49 |
echo "[GATEWAY] starting uvicorn on :7860 ..."
|
|
@@ -52,5 +64,4 @@ exec python3 -m uvicorn backend.app.main:app \
|
|
| 52 |
--host 0.0.0.0 \
|
| 53 |
--port "${PORT:-7860}" \
|
| 54 |
--proxy-headers \
|
| 55 |
-
--no-access-log \
|
| 56 |
--log-level info
|
|
|
|
| 1 |
#!/bin/sh
|
| 2 |
+
# OpenCode-Serve entrypoint:
|
| 3 |
+
# * opencode serve on :4096 (internal, the AI server with chat UI)
|
| 4 |
+
# * ttyd on :7681 (internal, the embedded terminal)
|
| 5 |
+
# * uvicorn on :7860 (HF exposed port)
|
| 6 |
+
#
|
| 7 |
+
# uvicorn ONLY routes specific prefixes; everything else falls back to
|
| 8 |
+
# opencode-on-7860 directly... no wait, that requires two services on
|
| 9 |
+
# the same port. Instead:
|
| 10 |
+
# * uvicorn proxies /terminal/* to ttyd
|
| 11 |
+
# * uvicorn proxies everything else to opencode serve
|
| 12 |
set -u
|
| 13 |
|
| 14 |
echo "============================================"
|
|
|
|
| 20 |
/data/workspaces /data/logs \
|
| 21 |
2>/dev/null || true
|
| 22 |
|
| 23 |
+
# Default config
|
| 24 |
if [ ! -f /data/config/opencode/opencode.json ]; then
|
| 25 |
+
mkdir -p /data/config/opencode
|
| 26 |
python3 -c '
|
| 27 |
import json
|
| 28 |
d = {"$schema":"https://opencode.ai/config.json","server":{"port":4096,"hostname":"127.0.0.1"},"model":"opencode/big-pickle"}
|
| 29 |
json.dump(d, open("/data/config/opencode/opencode.json","w"), indent=2)
|
| 30 |
+
' 2>/dev/null || true
|
|
|
|
| 31 |
fi
|
| 32 |
|
|
|
|
| 33 |
mkdir -p /projects/default
|
| 34 |
+
cd /projects/default
|
| 35 |
+
if [ ! -d .git ]; then
|
| 36 |
+
git init -q 2>/dev/null
|
| 37 |
+
git config user.email 'opencode@local.com' 2>/dev/null
|
| 38 |
+
git config user.name 'OpenCode' 2>/dev/null
|
| 39 |
+
git commit --allow-empty -q -m 'Init' 2>/dev/null || true
|
| 40 |
fi
|
| 41 |
|
| 42 |
# βββ 1) opencode serve on 127.0.0.1:4096 βββ
|
| 43 |
echo "[UPSTREAM] starting opencode serve on :4096 ..."
|
|
|
|
| 44 |
nohup opencode serve --port 4096 --hostname 127.0.0.1 > /data/logs/opencode-serve.log 2>&1 &
|
| 45 |
+
|
| 46 |
+
# Wait briefly (don't block forever)
|
| 47 |
+
for i in 1 2 3 4 5; do
|
| 48 |
+
curl -sf http://127.0.0.1:4096/global/health >/dev/null 2>&1 && break
|
| 49 |
+
sleep 1
|
| 50 |
+
done
|
| 51 |
|
| 52 |
# βββ 2) ttyd on 0.0.0.0:7681 βββ
|
| 53 |
echo "[TERMINAL] starting ttyd on :7681 (base /terminal) ..."
|
| 54 |
nohup ttyd --port 7681 --host 0.0.0.0 --writable --base-path /terminal \
|
| 55 |
bash -l > /data/logs/ttyd.log 2>&1 &
|
| 56 |
+
|
| 57 |
+
# Brief wait so ttyd binds
|
| 58 |
+
sleep 1
|
| 59 |
|
| 60 |
# βββ 3) uvicorn on 7860 (HF port, foreground) βββ
|
| 61 |
echo "[GATEWAY] starting uvicorn on :7860 ..."
|
|
|
|
| 64 |
--host 0.0.0.0 \
|
| 65 |
--port "${PORT:-7860}" \
|
| 66 |
--proxy-headers \
|
|
|
|
| 67 |
--log-level info
|