File size: 2,569 Bytes
486ef89
 
cf565b0
 
 
 
486ef89
5cfdc71
cf565b0
486ef89
 
 
 
fef2a52
 
486ef89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de293c1
 
 
 
 
 
 
486ef89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fef2a52
486ef89
 
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
FROM node:22-slim

ENV DEBIAN_FRONTEND=noninteractive
ENV VIRTUAL_ENV=/opt/venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends python3 python3-pip python3-venv git && \
    python3 -m venv $VIRTUAL_ENV && \
    pip install --no-cache-dir huggingface_hub && \
    rm -rf /var/lib/apt/lists/*

COPY sync_data.py /app/sync_data.py
COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh

# 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=7860
ENV GATEWAY_MODE=local

# Expose the port (Hugging Face default)
EXPOSE 7860

# Create a startup script that generates config and starts OpenClaw
RUN cat <<'EOF' > /usr/local/bin/start-openclaw
#!/bin/bash
set -x

# Create critical missing directories
mkdir -p /root/.openclaw/agents/main/agent
mkdir -p /root/.openclaw/agents/main/sessions
mkdir -p /root/.openclaw/credentials

# Remove auth-profiles.json if it exists to force env var usage
rm -f /root/.openclaw/agents/main/agent/auth-profiles.json

# Generate minimal config if not exists
if [ ! -f /root/.openclaw/openclaw.json ]; then
  cat <<JSON > /root/.openclaw/openclaw.json
{
  "env": {
  },
  "gateway": {
    "mode": "local",
    "bind": "lan",
    "port": ${PORT},
    "trustedProxies": ["0.0.0.0/0"],
    "auth": {
      "mode": "token",
      "token": "${GATEWAY_AUTH_TOKEN}"
    },
    "controlUi": {
      "allowInsecureAuth": true
    }
  },
  "agents": {
    "defaults": {
      "model": {
        "primary": "nvidia/minimaxai/minimax-m2.1"
      }
    }
  },
  "models": {
    "providers": {
      "nvidia": {
        "baseUrl": "https://integrate.api.nvidia.com/v1",
        "apiKey": "${MOONSHOT_API_KEY}",
        "api": "openai-completions",
        "models": [{ "id": "minimaxai/minimax-m2.1", "name": "minimax-m2.1" }]
      }
    }
  },
  "channels": {
    "telegram": {
      "enabled": true,
      "botToken": "${TG_BOT_TOKEN}",
      "dmPolicy": "pairing"
    }
  }
}
JSON
fi

# Fix permissions
chmod 700 /root/.openclaw
chmod 600 /root/.openclaw/openclaw.json || true
chmod 600 /root/.openclaw/agents/main/agent/auth-profiles.json || true

# Fix config if needed
openclaw doctor --fix

# Start OpenClaw gateway
echo "Starting OpenClaw gateway on port ${PORT}..."
exec openclaw gateway run --port ${PORT}
EOF

RUN chmod +x /usr/local/bin/start-openclaw

ENTRYPOINT ["/app/entrypoint.sh"]

CMD ["/usr/local/bin/start-openclaw"]