-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
144 lines (128 loc) · 4.45 KB
/
Copy pathentrypoint.sh
File metadata and controls
144 lines (128 loc) · 4.45 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/sh
set -e
echo "1claw runtime-base starting (runtime_id=${ONECLAW_RUNTIME_ID:-unknown}, agent_id=${ONECLAW_AGENT_ID:-unknown})"
USER_PORT="${USER_PORT:-8000}"
# Cloud Run sets PORT for the ingress listener. Sidecar inbound binds here when enabled.
PUBLIC_PORT="${PORT:-8080}"
start_sidecar() {
if [ ! -x /usr/local/bin/shroud-sidecar ]; then
echo "WARN: shroud-sidecar binary not found; shell/inbound proxy disabled"
return 0
fi
if [ "${ONECLAW_SIDECAR_ENABLED:-0}" != "1" ]; then
echo "Sidecar disabled (set ONECLAW_SIDECAR_ENABLED=1 to enable shell/inbound)"
return 0
fi
export USER_PORT
export INBOUND_ADDR=":${PUBLIC_PORT}"
# Privileged sidecar APIs stay on loopback; only INBOUND_ADDR is public.
export LISTEN_ADDR="127.0.0.1:8082"
export INBOUND_AUTH="${INBOUND_AUTH:-public}"
export ONECLAW_JWKS_URL="${ONECLAW_JWKS_URL:-https://api.1claw.co/.well-known/jwks.json}"
export ONECLAW_BASE_URL="${ONECLAW_BASE_URL:-https://api.1claw.co}"
# Shell-only unless agent credentials are present (avoids fatal on missing API key).
if [ -z "${ONECLAW_AGENT_API_KEY:-}" ] && [ -z "${ONECLAW_AGENT_TOKEN:-}" ]; then
export ONECLAW_SHELL_ONLY=1
fi
echo "Starting shroud-sidecar (inbound :${PUBLIC_PORT} → user :${USER_PORT}, terminal /terminal)"
/usr/local/bin/shroud-sidecar &
SIDECAR_PID=$!
# Give sidecar a moment; user process is the long-lived child below.
sleep 0.2
echo "Sidecar pid=${SIDECAR_PID}"
}
# Clone source repository if provided
if [ -n "$SOURCE_REPO" ]; then
case "$SOURCE_REPO" in
https://*|git://*|git@*) ;;
*) echo "ERROR: SOURCE_REPO must be https://, git://, or git@"; exit 1 ;;
esac
BRANCH="${SOURCE_BRANCH:-main}"
case "$BRANCH" in
-*|*".."*|*" "*) echo "ERROR: invalid SOURCE_BRANCH"; exit 1 ;;
esac
echo "Cloning source from ${SOURCE_REPO} (branch: ${BRANCH})..."
git clone --depth 1 --branch "$BRANCH" -- "$SOURCE_REPO" /app/workspace/src
cd /app/workspace/src
if [ -f requirements.txt ]; then
echo "Installing Python dependencies..."
python -m venv /app/.venv 2>/dev/null || true
if [ -f /app/.venv/bin/pip ]; then
/app/.venv/bin/pip install --no-cache-dir -r requirements.txt
else
pip install --no-cache-dir --user -r requirements.txt 2>/dev/null || true
fi
fi
if [ -f package.json ]; then
echo "Installing Node.js dependencies..."
npm install --omit=dev
fi
else
cd /app/workspace
if [ -f package.json ]; then
echo "Detected Node.js project, installing dependencies..."
npm install --omit=dev 2>/dev/null || true
fi
if [ -f requirements.txt ]; then
echo "Detected Python project, installing dependencies..."
python -m venv /app/.venv 2>/dev/null || true
if [ -f /app/.venv/bin/pip ]; then
/app/.venv/bin/pip install --no-cache-dir -r requirements.txt
else
pip install --no-cache-dir --user -r requirements.txt 2>/dev/null || true
fi
fi
fi
if [ -n "$ONECLAW_AGENT_API_KEY" ]; then
export ONECLAW_AGENT_API_KEY
fi
start_sidecar
# User process must listen on USER_PORT (sidecar proxies public PORT → USER_PORT).
export PORT="$USER_PORT"
run_user() {
if [ -n "$STARTUP_COMMAND" ]; then
echo "Running startup command via sh -c (argv-safe)"
# Quote the whole command as a single -c argument (never unquoted exec).
exec /bin/sh -c "$STARTUP_COMMAND"
fi
if [ -f entrypoint.sh ]; then
exec ./entrypoint.sh
elif [ -f agent.ts ]; then
exec npx tsx agent.ts
elif [ -f agent.js ]; then
exec node agent.js
elif [ -f agent.py ]; then
if [ -f /app/.venv/bin/python ]; then
exec /app/.venv/bin/python agent.py
else
exec python agent.py
fi
elif [ -f main.py ]; then
if [ -f /app/.venv/bin/python ]; then
exec /app/.venv/bin/python main.py
else
exec python main.py
fi
elif [ -f app.py ]; then
if [ -f /app/.venv/bin/python ]; then
exec /app/.venv/bin/python app.py
else
exec python app.py
fi
elif [ -f index.ts ]; then
exec npx tsx index.ts
elif [ -f index.js ]; then
exec node index.js
else
echo "No entrypoint found. Set STARTUP_COMMAND or add main.py/index.ts/agent.ts"
exec node -e "
const http = require('http');
const port = process.env.PORT || 8000;
http.createServer((req, res) => {
if (req.url === '/health') { res.writeHead(200); res.end('ok'); }
else { res.writeHead(404); res.end('not found'); }
}).listen(port, () => console.log('Health server on port ' + port));
"
fi
}
run_user