Spaces:
Paused
Paused
File size: 6,766 Bytes
eeab434 0fba7cd eeab434 0fba7cd eeab434 0fba7cd eeab434 0fba7cd eeab434 0fba7cd eeab434 0fba7cd eeab434 0fba7cd eeab434 0fba7cd eeab434 0fba7cd eeab434 0fba7cd eeab434 | 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | FROM debian:bookworm-slim
ARG VERSION=0.53.43
# =========================================================
# System dependencies (NO nodejs/npm here)
# =========================================================
RUN apt-get update && apt-get install -y \
curl \
git \
python3 \
tar \
ca-certificates \
libssl-dev \
sudo \
netcat-openbsd \
xvfb \
xdotool \
libx11-6 \
libxext6 \
libxrandr2 \
libxfixes3 \
libxi6 \
libxrender1 \
libxss1 \
libxtst6 \
libgtk-3-0 \
libnss3 \
libasound2 \
libgbm1 \
libxkbcommon0 \
libxkbcommon-x11-0 \
&& rm -rf /var/lib/apt/lists/*
# =========================================================
# Install Node.js 24 (ONLY from NodeSource)
# =========================================================
RUN curl -fsSL https://deb.nodesource.com/setup_24.x | bash - && \
apt-get install -y nodejs && \
node --version && \
npm --version
# =========================================================
# Install pnpm
# =========================================================
RUN npm install -g pnpm@10.10.0
# =========================================================
# Install OpenHuman Core
# =========================================================
RUN curl -L \
"https://github.com/tinyhumansai/openhuman/releases/download/v${VERSION}/openhuman-core-${VERSION}-x86_64-unknown-linux-gnu.tar.gz" \
-o core.tar.gz && \
mkdir -p /tmp/core && \
tar -xzf core.tar.gz -C /tmp/core && \
find /tmp/core -name openhuman-core -exec mv {} /usr/local/bin/openhuman-core \; && \
chmod +x /usr/local/bin/openhuman-core && \
rm -rf /tmp/core core.tar.gz
# =========================================================
# Create app user
# =========================================================
RUN useradd -m -u 1000 appuser
USER appuser
ENV HOME=/home/appuser
WORKDIR /app
# =========================================================
# Clone OpenHuman
# =========================================================
RUN git clone --recursive \
--branch v${VERSION} \
https://github.com/tinyhumansai/openhuman.git /app
# =========================================================
# Install frontend dependencies
# =========================================================
RUN pnpm install
# =========================================================
# Create RPC proxy (uses only built-in Node http module)
# =========================================================
RUN cat > /app/rpc-proxy.js << 'EOF'
const http = require('http');
const PROXY_PORT = 7789;
const CORE_PORT = 7788;
const CORE_TOKEN = "hf_space_token_123";
function forward(body) {
return new Promise((resolve) => {
const req = http.request({
hostname: '127.0.0.1',
port: CORE_PORT,
path: '/rpc',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${CORE_TOKEN}`
}
}, (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
try {
resolve(JSON.parse(data));
} catch (e) {
resolve({ jsonrpc: "2.0", error: { code: -32700, message: "Parse error" } });
}
});
});
req.on('error', (e) => {
resolve({ jsonrpc: "2.0", error: { code: -32000, message: String(e) } });
});
req.write(JSON.stringify(body));
req.end();
});
}
const server = http.createServer((req, res) => {
if (req.method !== 'POST' || req.url !== '/rpc') {
res.writeHead(404);
return res.end('Not found');
}
let body = '';
req.on('data', chunk => body += chunk);
req.on('end', async () => {
let json;
try {
json = JSON.parse(body);
} catch (e) {
res.writeHead(400);
return res.end('Bad JSON');
}
const method = json.method || '';
console.log('RPC ->', method);
// Force authenticated state
if (
method === 'openhuman.app_state_snapshot' ||
method === 'openhuman.health_snapshot'
) {
const original = await forward(json);
if (!original.result) original.result = {};
original.result.authenticated = true;
original.result.onboardingCompleted = true;
original.result.sessionToken = "self-hosted";
original.result.coreMode = "runtime";
res.writeHead(200, { 'Content-Type': 'application/json' });
return res.end(JSON.stringify(original));
}
// Mock cloud RPCs
if (
method.includes('billing') ||
method.includes('team') ||
method.includes('auth') ||
method.includes('profile')
) {
res.writeHead(200, { 'Content-Type': 'application/json' });
return res.end(JSON.stringify({
jsonrpc: "2.0",
id: json.id,
result: { mocked: true, selfHosted: true }
}));
}
// Forward everything else
const response = await forward(json);
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(response));
});
});
server.listen(PROXY_PORT, '0.0.0.0', () => {
console.log(`RPC Proxy running on port ${PROXY_PORT}`);
});
EOF
# =========================================================
# Create startup script
# =========================================================
RUN cat > /app/start.sh << 'EOF'
#!/bin/bash
set -e
export OPENHUMAN_CORE_TOKEN="hf_space_token_123"
export OPENHUMAN_WORKSPACE="/home/appuser/workspace"
mkdir -p "$OPENHUMAN_WORKSPACE"
echo "=== STARTING XVFB ==="
Xvfb :99 -screen 0 1024x768x24 -nolisten tcp &
export DISPLAY=:99
sleep 2
echo "=== STARTING OPENHUMAN CORE ==="
openhuman-core run \
--host 127.0.0.1 \
--port 7788 \
--jsonrpc-only \
> /tmp/core.log 2>&1 &
echo "=== WAITING FOR CORE ==="
for i in $(seq 1 60); do
if nc -z 127.0.0.1 7788; then
echo "=== CORE READY ==="
break
fi
sleep 1
done
echo "=== STARTING RPC PROXY ==="
node /app/rpc-proxy.js &
echo "=== WRITING VITE CONFIG ==="
cat > /app/app/vite.hf.config.ts << 'VITECONFIG'
import { defineConfig, mergeConfig } from "vite";
import baseConfig from "./vite.config";
export default defineConfig(async (env) => {
const cfg = typeof baseConfig === "function" ? await baseConfig(env) : baseConfig;
return mergeConfig(cfg, {
server: {
host: "0.0.0.0",
port: 7860,
allowedHosts: true,
proxy: {
"/rpc": {
target: "http://127.0.0.1:7789",
changeOrigin: true,
ws: true
}
}
}
});
});
VITECONFIG
echo "=== STARTING FRONTEND ==="
cd /app/app
tail -f /tmp/core.log &
pnpm exec vite \
--config vite.hf.config.ts \
--host 0.0.0.0 \
--port 7860
EOF
RUN chmod +x /app/start.sh
EXPOSE 7860
ENV PORT=7860
CMD ["/app/start.sh"] |