FROM node:22-slim # Install system dependencies RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* RUN npm cache clean --force \ && rm -rf /usr/local/lib/node_modules/openclaw \ && rm -f /usr/local/bin/openclaw # 安装最新版,并强制 rebuild(加 --force --no-optional 如果有 native deps 问题) RUN npm install -g openclaw@latest --force # Create config directory RUN mkdir -p /root/.openclaw # Set up environment for Hugging Face Spaces ENV PORT=18789 ENV OPENCLAW_GATEWAY_MODE=local ENV OPENCLAW_GATEWAY_PASSWORD=${OPENCLAW_GATEWAY_PASSWORD} ENV API_KEY=${API_KEY} ENV MODELSCOPE_API_KEY=${MODELSCOPE_API_KEY} ENV DEEPSEEK_API_KEY=${DEEPSEEK_API_KEY} ENV FEISHU_SECRET={FEISHU_SECRET} # Expose the port (Hugging Face default) EXPOSE 18789 # Create a startup script that generates config and starts OpenClaw RUN echo '#!/bin/bash\n\ set -x\n\ \n\ # Check for required environment variables\n\ if [ -z "$GEMINI_APIKEY" ]; then\n\ echo "ERROR: GEMINI_APIKEY is not set. Agent will fail. Exiting."\n\ exit 1\n\ fi\n\ \n\ # Create critical missing directories\n\ mkdir -p /root/.openclaw/agents/main/agent\n\ mkdir -p /root/.openclaw/agents/main/sessions\n\ mkdir -p /root/.openclaw/credentials\n\ \n\ # Remove auth-profiles.json if it exists to force env var usage\n\ rm -f /root/.openclaw/agents/main/agent/auth-profiles.json\n\ \n\ # Generate minimal config if not exists\n\ if [ ! -f /root/.openclaw/openclaw.json ]; then\n\ cat > /root/.openclaw/openclaw.json << EOF\n\ {\n\ "env": {\n\ "GOOGLE_API_KEY": "${GEMINI_APIKEY}",\n\ "GEMINI_API_KEY": "${GEMINI_APIKEY}",\n\ "GOOGLE_GENERATIVE_AI_API_KEY": "${GEMINI_APIKEY}",\n\ "PALM_API_KEY": "${GEMINI_APIKEY}"\n\ },"channels":{"feishu":{"appId":"cli_a9284492f7b8dccb","appSecret":"${FEISHU_SECRET}","dmPolicy":"pairing","allowFrom":["*"],"enabled":true}},\n\ "gateway": {\n\ "mode": "local",\n\ "bind": "lan",\n\ "port": 18789,\n\ "trustedProxies": [\n\ "0.0.0.0/0", \n\ "10.0.0.0/8", \n\ "172.16.0.0/12", \n\ "192.168.0.0/16", \n\ "127.0.0.1", \n\ "::1"\n\ ],\n\ "auth": {\n\ "mode": "token",\n\ "token": "${OPENCLAW_GATEWAY_PASSWORD}"\n\ },\n\ "controlUi": {\n\ "enabled": true,\n\ "dangerouslyAllowHostHeaderOriginFallback": true,\n\ "dangerouslyDisableDeviceAuth": true,\n\ "allowInsecureAuth": true,\n\ "allowedOrigins": ["*"]\n\ }\n\ },"models":{"providers":{"deepseek":{"baseUrl":"https://api.edgefn.net/v1","apiKey":"${DEEPSEEK_API_KEY}","api":"openai-completions","models":[{"id":"DeepSeek-V3.2","name":"DeepSeek-V3.2","reasoning":false,"input":["text"],"cost":{"input":0,"output":0,"cacheRead":0,"cacheWrite":0},"contextWindow":200000,"maxTokens":8192}]},"custom-custom54":{"baseUrl":"https://open.bigmodel.cn/api/paas/v4","apiKey":"${API_KEY}","api":"openai-completions","models":[{"id":"GLM-4.7-Flash","name":"GLM-4.7-Flash","reasoning":false,"input":["text"],"cost":{"input":0,"output":0,"cacheRead":0,"cacheWrite":0},"contextWindow":200000,"maxTokens":8192}]},"modelscope":{"baseUrl":"https://api-inference.modelscope.cn/v1","apiKey":"${MODELSCOPE_API_KEY}","api":"openai-completions","models":[{"id":"Qwen/Qwen3.5-397B-A17B","name":"Qwen/Qwen3.5-397B-A17B","reasoning":false,"input":["text"],"cost":{"input":0,"output":0,"cacheRead":0,"cacheWrite":0},"contextWindow":200000,"maxTokens":8192},{"id":"MiniMax/MiniMax-M2.5","name":"MiniMax/MiniMax-M2.5","reasoning":false,"input":["text"],"cost":{"input":0,"output":0,"cacheRead":0,"cacheWrite":0},"contextWindow":200000,"maxTokens":8192},{"id":"ZhipuAI/GLM-5","name":"ZhipuAI/GLM-5","reasoning":false,"input":["text"],"cost":{"input":0,"output":0,"cacheRead":0,"cacheWrite":0},"contextWindow":200000,"maxTokens":8192},{"id":"stepfun-ai/Step-3.5-Flash","name":"stepfun-ai/Step-3.5-Flash","reasoning":false,"input":["text"],"cost":{"input":0,"output":0,"cacheRead":0,"cacheWrite":0},"contextWindow":200000,"maxTokens":8192},{"id":"Qwen/Qwen3.5-122B-A10B","name":"Qwen/Qwen3.5-122B-A10B","reasoning":false,"input":["text"],"cost":{"input":0,"output":0,"cacheRead":0,"cacheWrite":0},"contextWindow":200000,"maxTokens":8192}]}}},\n\ "agents": {\n\ "defaults": {\n\ "model": {\n\ "primary": "deepseek/DeepSeek-V3.2","fallbacks":["modelscope/MiniMax/MiniMax-M2.5","modelscope/Qwen/Qwen3.5-397B-A17B","modelscope/ZhipuAI/GLM-5","modelscope/stepfun-ai/Step-3.5-Flash","modelscope/Qwen/Qwen3.5-122B-A10B","custom-custom54/GLM-4.7-Flash"]\n\ },\n\ "models": {\n\ "deepseek/DeepSeek-V3.2": {"params":{"enable_thinking": false}},\n\ "custom-custom54/GLM-4.7-Flash": {"params":{"thinking":{"type":"disabled"}}},\n\ "modelscope/Qwen/Qwen3.5-397B-A17B": {"params":{"enable_thinking": false}},\n\ "modelscope/MiniMax/MiniMax-M2.5": {"params":{"enable_thinking": false}},\n\ "modelscope/stepfun-ai/Step-3.5-Flash": {"params":{"enable_thinking": false}},\n\ "modelscope/ZhipuAI/GLM-5": {"params":{"enable_thinking": false}},\n\ "modelscope/Qwen/Qwen3.5-122B-A10B": {"params":{"enable_thinking": false}}\n\ }\n\ }\n\ },"plugins":{"entries":{"feishu":{"enabled":true}}}\n\ }\n\ EOF\n\ fi\n\ \n\ # Fix permissions\n\ chmod 700 /root/.openclaw\n\ chmod 600 /root/.openclaw/openclaw.json\n\ chmod 600 /root/.openclaw/agents/main/agent/auth-profiles.json\n\ \n\ # Fix config if needed\n\ openclaw doctor --fix\n\ \n\ # Start OpenClaw gateway\n\ echo "Starting OpenClaw gateway on port 18789..."\n\ exec openclaw gateway run --port 18789\n\ ' > /usr/local/bin/start-openclaw && chmod +x /usr/local/bin/start-openclaw CMD ["/usr/local/bin/start-openclaw"]