File size: 2,318 Bytes
9149dda
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
FROM node:22-slim

# Install system dependencies
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*

# Install OpenClaw globally
RUN npm install -g openclaw@latest

# 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}

# 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\
  },\n\
  "gateway": {\n\
    "mode": "local",\n\
    "bind": "lan",\n\
    "port": 18789,\n\
    "trustedProxies": ["0.0.0.0/0"],\n\
    "auth": {\n\
      "mode": "token",\n\
      "token": "${OPENCLAW_GATEWAY_PASSWORD}"\n\
    },\n\
    "controlUi": {\n\
      "allowInsecureAuth": true\n\
    }\n\
  },\n\
  "agents": {\n\
    "defaults": {\n\
      "model": {\n\
        "primary": "google/gemini-1.5-pro"\n\
      }\n\
    }\n\
  }\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"]