Spaces:
Sleeping
Sleeping
Claude Code Claude Opus 4.6 commited on
Commit ·
6e71b49
1
Parent(s): 444f882
Claude Code: Ultra-minimal Dockerfile - Python base only
Browse files- Simplify to single-stage python:3.10-slim
- Remove Node.js, multi-stage build, OpenClaw prebuilt
- Minimal requirements: gradio, fastapi, uvicorn, huggingface_hub
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Dockerfile +9 -147
- requirements.txt +2 -6
Dockerfile
CHANGED
|
@@ -1,155 +1,17 @@
|
|
| 1 |
-
#
|
| 2 |
-
|
| 3 |
|
| 4 |
-
# ── Stage 1: Pull pre-built OpenClaw ─────────────────────────────────────────
|
| 5 |
-
FROM ghcr.io/openclaw/openclaw:latest AS openclaw-prebuilt
|
| 6 |
-
|
| 7 |
-
# ── Stage 2: Runtime with Node.js + Python ───────────────────────────────────
|
| 8 |
-
# Using node:22-bookworm-slim for smaller base image size
|
| 9 |
-
FROM node:22-bookworm-slim
|
| 10 |
-
|
| 11 |
-
# Metadata for healthcheck and labeling
|
| 12 |
-
LABEL maintainer="HuggingClaw"
|
| 13 |
-
LABEL description="OpenClaw Cain - HuggingFace Space with Gradio Dashboard"
|
| 14 |
-
LABEL version="4.2.0"
|
| 15 |
-
|
| 16 |
-
SHELL ["/bin/bash", "-c"]
|
| 17 |
-
|
| 18 |
-
# ── Build arguments for configurable versions ─────────────────────────────────
|
| 19 |
-
ARG PYTHON_VERSION=python3.10
|
| 20 |
-
ARG NODE_ENV=production
|
| 21 |
-
|
| 22 |
-
# ── System dependencies (root) ───────────────────────────────────────────────
|
| 23 |
-
# Optimization: Install Python and system deps in minimal layers for caching
|
| 24 |
-
RUN echo "[build] Installing system dependencies..." && START=$(date +%s) \
|
| 25 |
-
&& apt-get update --retry-on-error \
|
| 26 |
-
# Minimal install: git for cloning, ca-certificates for HTTPS, curl for health checks
|
| 27 |
-
&& apt-get install -y --no-install-recommends \
|
| 28 |
-
git \
|
| 29 |
-
ca-certificates \
|
| 30 |
-
curl \
|
| 31 |
-
${PYTHON_VERSION} \
|
| 32 |
-
${PYTHON_VERSION}-pip \
|
| 33 |
-
${PYTHON_VERSION}-venv \
|
| 34 |
-
# Clean apt cache to reduce image size
|
| 35 |
-
&& rm -rf /var/lib/apt/lists/* \
|
| 36 |
-
&& apt-get clean \
|
| 37 |
-
&& echo "[build] System deps: $(($(date +%s) - START))s"
|
| 38 |
-
|
| 39 |
-
# ── Python dependencies (separate layer for Docker caching) ────────────────
|
| 40 |
-
# Optimization: Copy requirements first for better layer caching when only code changes
|
| 41 |
-
COPY requirements.txt /tmp/requirements.txt
|
| 42 |
-
|
| 43 |
-
RUN echo "[build] Installing Python packages..." && START=$(date +%s) \
|
| 44 |
-
# Use --no-cache-dir to avoid pip cache (saves space)
|
| 45 |
-
# Use --break-system-packages for Debian Python (required in bookworm-slim)
|
| 46 |
-
&& pip3 install --no-cache-dir --break-system-packages \
|
| 47 |
-
-r /tmp/requirements.txt \
|
| 48 |
-
# Remove temporary requirements file
|
| 49 |
-
&& rm /tmp/requirements.txt \
|
| 50 |
-
&& echo "[build] Python packages: $(($(date +%s) - START))s"
|
| 51 |
-
|
| 52 |
-
# ── Node.js package management ───────────────────────────────────────────────
|
| 53 |
-
# Enable corepack for npm/yarn/pnpm management
|
| 54 |
-
RUN corepack enable
|
| 55 |
-
|
| 56 |
-
# ── Directory setup with proper permissions ───────────────────────────────────
|
| 57 |
-
# Optimization: Create all directories in a single layer with correct ownership
|
| 58 |
-
RUN echo "[build] Setting up directories..." \
|
| 59 |
-
&& mkdir -p \
|
| 60 |
-
/app/openclaw \
|
| 61 |
-
/home/node/.openclaw/workspace \
|
| 62 |
-
/home/node/.openclaw/credentials \
|
| 63 |
-
/home/node/.local/bin \
|
| 64 |
-
&& chown -R node:node /app /home/node \
|
| 65 |
-
# Add node user to sudoers for npm global installs if needed (optional)
|
| 66 |
-
# Set proper umask for security
|
| 67 |
-
&& echo "[build] Directories created"
|
| 68 |
-
|
| 69 |
-
# ── Claude Code CLI (for coding agent extension — uses z.ai/Zhipu GLM) ──────
|
| 70 |
-
# Install in separate layer for caching
|
| 71 |
-
RUN echo "[build] Installing Claude Code CLI..." && START=$(date +%s) \
|
| 72 |
-
&& npm install -g @anthropic-ai/claude-code \
|
| 73 |
-
&& echo "[build] Claude Code CLI: $(($(date +%s) - START))s"
|
| 74 |
-
|
| 75 |
-
# ── Copy pre-built OpenClaw (skips clone + install + build entirely) ─────────
|
| 76 |
-
# Use chown to set correct ownership
|
| 77 |
-
COPY --from=openclaw-prebuilt --chown=node:node /app /app/openclaw
|
| 78 |
-
|
| 79 |
-
# ── Version extraction from OpenClaw ──────────────────────────────────────────
|
| 80 |
-
RUN echo "[build] Extracting OpenClaw version..." \
|
| 81 |
-
&& node -e "try{console.log(require('/app/openclaw/package.json').version)}catch(e){console.log('unknown')}" \
|
| 82 |
-
> /app/openclaw/.version \
|
| 83 |
-
&& echo "[build] OpenClaw version: $(cat /app/openclaw/.version)"
|
| 84 |
-
|
| 85 |
-
# ── Switch to non-root user for security ──────────────────────────────────────
|
| 86 |
-
USER node
|
| 87 |
-
ENV HOME=/home/node
|
| 88 |
WORKDIR /app
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
# To enable A2A, uncomment the gateway installation block
|
| 93 |
|
| 94 |
-
|
| 95 |
-
COPY
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
# ── Prepare runtime dirs ────────────────────────────────────────────────────
|
| 98 |
-
RUN mkdir -p /app/openclaw/empty-bundled-plugins
|
| 99 |
-
|
| 100 |
-
# ── Scripts + Config + Frontend (copy in specific order for layer caching) ──
|
| 101 |
-
# Copy scripts first (least frequently changed)
|
| 102 |
-
COPY --chown=node:node scripts /home/node/scripts
|
| 103 |
-
RUN chmod +x /home/node/scripts/entrypoint.sh /home/node/scripts/sync_hf.py
|
| 104 |
-
|
| 105 |
-
# Copy workspace templates
|
| 106 |
-
COPY --chown=node:node workspace-templates /home/node/workspace-templates
|
| 107 |
-
|
| 108 |
-
# Copy openclaw.json config
|
| 109 |
-
COPY --chown=node:node openclaw.json /home/node/scripts/openclaw.json.default
|
| 110 |
-
|
| 111 |
-
# Copy Python apps
|
| 112 |
-
COPY --chown=node:node gradio_dashboard.py /home/node/gradio_dashboard.py
|
| 113 |
-
COPY --chown=node:node app.py /home/node/app.py
|
| 114 |
-
|
| 115 |
-
# ── Frontend ───────────────────────────────────────────────────────────────────
|
| 116 |
-
# REMOVED: frontend COPY (minimal mode - Gradio only, no Electron UI)
|
| 117 |
-
# To enable full UI, restore the frontend COPY and index.html generation steps
|
| 118 |
-
|
| 119 |
-
# ── Environment variables for production ─────────────────────────────────────
|
| 120 |
-
# Default values for HuggingFace Spaces compatibility
|
| 121 |
-
ENV NODE_ENV=production
|
| 122 |
-
ENV OPENCLAW_BUNDLED_PLUGINS_DIR=/app/openclaw/empty-bundled-plugins
|
| 123 |
-
ENV OPENCLAW_PREFER_PNPM=1
|
| 124 |
-
ENV PATH="/home/node/.local/bin:$PATH"
|
| 125 |
-
|
| 126 |
-
# Gradio/FastAPI defaults (can be overridden by HuggingFace Spaces)
|
| 127 |
-
ENV GRADIO_SERVER_NAME=0.0.0.0
|
| 128 |
ENV PORT=7860
|
| 129 |
-
ENV CAIN_API_URL="http://127.0.0.1:7860"
|
| 130 |
-
|
| 131 |
-
# Python settings for stability
|
| 132 |
-
ENV PYTHONUNBUFFERED=1
|
| 133 |
-
ENV PYTHONDONTWRITEBYTECODE=1
|
| 134 |
-
|
| 135 |
-
# Working directory for the application
|
| 136 |
-
WORKDIR /home/node
|
| 137 |
-
|
| 138 |
-
# ── Health check configuration ───────────────────────────────────────────────
|
| 139 |
-
# Health check endpoint: /health on FastAPI app
|
| 140 |
-
# Interval: 30s, Timeout: 10s, Start period: 40s (give app time to boot)
|
| 141 |
-
# Retries: 3 before marking container as unhealthy
|
| 142 |
-
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
| 143 |
-
CMD curl -f http://localhost:${PORT}/health || exit 1
|
| 144 |
-
|
| 145 |
-
# ── Signal handling for graceful shutdown ─────────────────────────────────────
|
| 146 |
-
# The entrypoint.sh script handles SIGTERM/SIGINT for graceful shutdown
|
| 147 |
-
# Docker will send SIGTERM, then SIGKILL after 10 seconds if not stopped
|
| 148 |
-
|
| 149 |
-
# Expose the default port (HuggingFace Spaces uses 7860)
|
| 150 |
EXPOSE 7860
|
| 151 |
|
| 152 |
-
|
| 153 |
-
# Use shell form to allow signal propagation to child processes
|
| 154 |
-
# entrypoint.sh will exec the Python app which handles signals properly
|
| 155 |
-
CMD ["/home/node/scripts/entrypoint.sh"]
|
|
|
|
| 1 |
+
# Minimal Python Dockerfile for Cain
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
WORKDIR /app
|
| 5 |
|
| 6 |
+
COPY requirements.txt .
|
| 7 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
| 8 |
|
| 9 |
+
COPY app.py .
|
| 10 |
+
COPY gradio_dashboard.py .
|
| 11 |
+
COPY scripts scripts/
|
| 12 |
+
COPY openclaw.json .
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
ENV PORT=7860
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
EXPOSE 7860
|
| 16 |
|
| 17 |
+
CMD ["python", "app.py"]
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,8 +1,4 @@
|
|
| 1 |
-
|
| 2 |
fastapi>=0.104.0
|
| 3 |
uvicorn[standard]>=0.24.0
|
| 4 |
-
|
| 5 |
-
gradio>=4.0.0
|
| 6 |
-
psutil>=5.9.0
|
| 7 |
-
websockets>=12.0
|
| 8 |
-
httpx>=0.25.0 # For connection pooling configuration
|
|
|
|
| 1 |
+
gradio>=4.0.0
|
| 2 |
fastapi>=0.104.0
|
| 3 |
uvicorn[standard]>=0.24.0
|
| 4 |
+
huggingface_hub>=0.24.5
|
|
|
|
|
|
|
|
|
|
|
|