FROM node:25-bookworm

# Set working directory
WORKDIR /home/node

# Set PNPM_HOME before installing global packages
ENV PNPM_HOME=/home/node/.local/share/pnpm
ENV PATH=$PNPM_HOME:/home/node/clawd/.local/bin:/usr/local/bin:/usr/bin:/bin

# Install Python3, pip, uv and system dependencies
# Install openclaw globally during build time (much faster than runtime install)
RUN apt-get update && apt-get install -y --no-install-recommends \
    python3 \
    python3-pip \
    python3-venv \
    && rm -rf /var/lib/apt/lists/* \
    && pip3 install --break-system-packages uv \
    && npm install -g pnpm bun \
    && npm install -g openclaw@latest

# Create necessary directories
RUN mkdir -p /home/node/.openclaw /home/node/clawd /home/node/.cache

# Set environment variables
# Python packages will be installed to /home/node/clawd so they persist after restart
ENV HOME=/home/node \
    TERM=xterm-256color \
    OPENCLAW_GATEWAY_BIND=0.0.0.0 \
    PYTHONUSERBASE=/home/node/clawd/.local \
    UV_CACHE_DIR=/home/node/clawd/.cache/uv \
    PIP_USER=1

# Expose ports
EXPOSE 18789 18790

CMD ["openclaw", "gateway", "--port", "18789", "--bind", "lan", "--verbose"]
