kovinape commited on
Commit
bca0e01
Β·
verified Β·
1 Parent(s): 62b650c

Create entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +68 -0
entrypoint.sh ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # ─────────────────────────────────────────────────────────────
3
+ # entrypoint.sh
4
+ # 1. Start Ollama server
5
+ # 2. Wait for it to be ready
6
+ # 3. Pull gpt-oss:20b
7
+ # 4. Launch ttyd on :7860 wrapping Claude Code CLI
8
+ # ─────────────────────────────────────────────────────────────
9
+ set -e
10
+
11
+ MODEL="gpt-oss:20b"
12
+
13
+ echo "════════════════════════════════════════"
14
+ echo " Starting Ollama server..."
15
+ echo "════════════════════════════════════════"
16
+ ollama serve &
17
+ OLLAMA_PID=$!
18
+
19
+ # ── Wait until Ollama HTTP API is responsive ─────────────────
20
+ echo "Waiting for Ollama to initialise..."
21
+ RETRIES=60
22
+ until curl -sf http://localhost:11434/api/tags > /dev/null 2>&1; do
23
+ RETRIES=$((RETRIES - 1))
24
+ if [ "$RETRIES" -le 0 ]; then
25
+ echo "ERROR: Ollama failed to start within 120 seconds."
26
+ exit 1
27
+ fi
28
+ sleep 2
29
+ done
30
+ echo "βœ“ Ollama is ready."
31
+
32
+ # ── Pull model if not already cached ────────────────────────
33
+ echo ""
34
+ echo "════════════════════════════════════════"
35
+ echo " Pulling model: $MODEL"
36
+ echo " (first run downloads ~12 GB β€” be patient)"
37
+ echo "════════════════════════════════════════"
38
+ ollama pull "$MODEL"
39
+ echo "βœ“ Model ready."
40
+
41
+ # ── Keep Ollama alive in background ─────────────────────────
42
+ # (already running as background job $OLLAMA_PID)
43
+
44
+ # ── Launch web terminal on port 7860 ────────────────────────
45
+ echo ""
46
+ echo "════════════════════════════════════════"
47
+ echo " Launching web terminal on port 7860"
48
+ echo " Open your Space URL to access Claude CLI"
49
+ echo "════════════════════════════════════════"
50
+
51
+ # ttyd flags:
52
+ # -p 7860 β†’ bind to HF Spaces exposed port
53
+ # -W β†’ writable (allow keyboard input)
54
+ # -t fontSize=15 β†’ comfortable size
55
+ # --once β†’ REMOVE this flag if you want multiple sessions
56
+ # The command run per-connection: claude --model gpt-oss:20b
57
+ exec ttyd \
58
+ -p 7860 \
59
+ -W \
60
+ -t fontSize=15 \
61
+ -t theme={"background":"#0d1117","foreground":"#c9d1d9"} \
62
+ /bin/bash -c "
63
+ export ANTHROPIC_AUTH_TOKEN=ollama
64
+ export ANTHROPIC_API_KEY=ollama
65
+ export ANTHROPIC_BASE_URL=http://localhost:11434
66
+ exec claude --model $MODEL
67
+ "
68
+