-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathentrypoint.sh
More file actions
71 lines (59 loc) · 2.1 KB
/
entrypoint.sh
File metadata and controls
71 lines (59 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
PUID=${PUID:-1000}
PGID=${PGID:-1000}
OPENCODE_SERVER_PASSWORD=${OPENCODE_SERVER_PASSWORD:-}
if [ "$(id -g node)" -ne "$PGID" ]; then
groupmod -o -g "$PGID" node
fi
if [ "$(id -u node)" -ne "$PUID" ]; then
usermod -o -u "$PUID" node
fi
chown -R node:node /home/node/.local/share/opencode
chown -R node:node /home/node/.config/opencode
chown -R node:node /home/node/project
# Allow overriding via environment variables
PROXY_PORT=${OPENCODE_PROXY_PORT:-10000}
SERVER_PORT=${OPENCODE_SERVER_PORT:-10001}
if [[ "${OPENCODE_PROXY_PROMPT_MODE:-standard}" == "plugin-inject" ]]; then
echo "Preparing opencode2api plugin-inject prompt mode..."
mkdir -p /home/node/.config/opencode/plugin/opencode2api-empty
cat > /home/node/.config/opencode/plugin/opencode2api-empty/index.js <<'EOF'
export const Opencode2apiEmptyPlugin = async () => ({})
export default Opencode2apiEmptyPlugin
EOF
cat > /home/node/.config/opencode/opencode.json <<'EOF'
{
"plugin": ["/home/node/.config/opencode/plugin/opencode2api-empty/index.js"],
"instructions": [],
"theme": "system"
}
EOF
chown -R node:node /home/node/.config/opencode
fi
if [[ "$1" == "opencode" && "$2" == "serve" ]]; then
echo "Initializing OpenCode-to-OpenAI (Server + Proxy)"
echo "Starting OpenCode Server on internal port ${SERVER_PORT}..."
gosu node opencode serve --hostname 0.0.0.0 --port ${SERVER_PORT} &
SERVER_PID=$!
echo "Waiting for OpenCode Server to become available..."
MAX_RETRIES=30
COUNT=0
while ! curl -s http://127.0.0.1:${SERVER_PORT}/health > /dev/null; do
if [ $COUNT -ge $MAX_RETRIES ]; then
echo "Timeout waiting for OpenCode Server."
kill $SERVER_PID 2>/dev/null
exit 1
fi
if ! kill -0 $SERVER_PID 2>/dev/null; then
echo "OpenCode Server process died unexpectedly."
exit 1
fi
sleep 1
COUNT=$((COUNT+1))
done
echo "OpenCode Server is up!"
echo "Starting OpenAI Proxy on port ${PROXY_PORT}..."
exec gosu node node index.js
else
exec gosu node "$@"
fi