OpenCode Integration commited on
Commit
a952a90
Β·
1 Parent(s): e8d7b5a

fix: even simpler entrypoint - just the basics

Browse files
Files changed (1) hide show
  1. entrypoint.sh +28 -17
entrypoint.sh CHANGED
@@ -1,10 +1,14 @@
1
  #!/bin/sh
2
- # OpenCode-Serve entrypoint β€” minimal multi-service bootstrap.
3
- # No git clone, no extra setup. Just:
4
- # 1. /data dirs
5
- # 2. opencode serve on 127.0.0.1:4096
6
- # 3. ttyd on 0.0.0.0:7681 (--base-path /terminal)
7
- # 4. uvicorn on 0.0.0.0:7860 (HF exposed port)
 
 
 
 
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
- print("[CONFIG] wrote default config")
25
- '
26
  fi
27
 
28
- # /projects/default (needed for opencode's "default" project)
29
  mkdir -p /projects/default
30
- if [ ! -d /projects/default/.git ]; then
31
- (cd /projects/default && git init -q && git config user.email 'opencode@local.com' && git config user.name 'OpenCode' && git commit --allow-empty -q -m 'Init') || true
 
 
 
 
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
- OCPID=$!
39
- echo "[UPSTREAM] pid=$OCPID"
 
 
 
 
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
- TTYD_PID=$!
46
- echo "[TERMINAL] pid=$TTYD_PID"
 
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