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=7860 ENV OPENCLAW_GATEWAY_MODE=local ENV OPENCLAW_GATEWAY_PASSWORD=${SETUP_PASSWORD} # 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 # Check for required environment variables if [ -z "$GEMINI_API_KEY_1" ]; then echo "ERROR: GEMINI_API_KEY_1 is not set. Agent will fail. Exiting." exit 1 fi # 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 < /root/.openclaw/openclaw.json { "env": { }, "gateway": { "mode": "local", "bind": "lan", "port": 7860, "trustedProxies": ["0.0.0.0/0"], "auth": { "mode": "token", "token": "${SETUP_PASSWORD}" }, "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" }] } } } } 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 7860..." exec openclaw gateway run --port 7860 EOF RUN chmod +x /usr/local/bin/start-openclaw CMD ["/usr/local/bin/start-openclaw"]