# OpenClaw Gateway for Hugging Face Spaces # Build context: your Space repo (this Dockerfile + README + setup-hf-config.mjs). # OpenClaw is cloned during build; setup-hf-config.mjs is overridden by your Space repo copy. FROM node:22-bookworm # Optional: point to a fork or branch (set in Space Variables) ARG OPENCLAW_REPO=https://github.com/Josephrp/openclaw.git ARG OPENCLAW_REF=hf-spaces # Install git and Bun (needed for build scripts) RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends git ca-certificates && \ apt-get clean && rm -rf /var/lib/apt/lists/* \ && curl -fsSL https://bun.sh/install | bash ENV PATH="/root/.bun/bin:${PATH}" RUN corepack enable WORKDIR /app # Clone OpenClaw and build (no COPY from host; Space repo only has this Dockerfile) RUN git clone --depth 1 --branch "${OPENCLAW_REF}" "${OPENCLAW_REPO}" . \ && pnpm install --frozen-lockfile \ && pnpm build ENV OPENCLAW_PREFER_PNPM=1 RUN pnpm ui:build # Override the HF setup script with the customized version from Space repo # This adds OpenRouter/Perplexity support on top of the default HF config COPY setup-hf-config.mjs /app/spaces/huggingface/setup-hf-config.mjs ENV NODE_ENV=production # Spaces expose a single port (default 7860); gateway must listen on 0.0.0.0 EXPOSE 7860 # Entrypoint: set OPENCLAW_HOME, run HF Spaces setup (default model + token from secrets), then start gateway RUN printf '%s\n' \ '#!/bin/sh' \ 'set -e' \ 'if mkdir -p /data/.openclaw 2>/dev/null; then' \ ' export OPENCLAW_HOME=/data' \ 'else' \ ' export OPENCLAW_HOME=/home/user' \ ' mkdir -p /home/user/.openclaw' \ 'fi' \ 'node /app/spaces/huggingface/setup-hf-config.mjs' \ 'exec node /app/openclaw.mjs gateway --allow-unconfigured --bind lan --port 7860 "$@"' \ > /app/entrypoint.sh \ && chmod +x /app/entrypoint.sh # HF Spaces Dev Mode injects steps that expect /home/user; create it so they don't fail RUN chown -R node:node /app \ && mkdir -p /home/user \ && chown -R node:node /home/user USER node # Required Secrets in HF Space Settings: # OPENCLAW_GATEWAY_TOKEN — long random string for Control UI login (recommended) # OPENCLAW_GATEWAY_PASSWORD — alternative to token (token wins if both set) # HF_TOKEN — Hugging Face token with Inference Providers permission # OPENROUTER_API_KEY — OpenRouter API key for Perplexity Sonar search model # # Optional Secrets/Variables: # OPENCLAW_HF_DEFAULT_MODEL — e.g. huggingface/deepseek-ai/DeepSeek-R1 (default) # OPENCLAW_GATEWAY_TRUSTED_PROXIES — comma-separated proxy IPs # OPENCLAW_CONTROL_UI_ALLOWED_ORIGINS — comma-separated allowed origins ENTRYPOINT ["/app/entrypoint.sh"]