FROM python:3.12-slim

WORKDIR /app

# System dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    git \
    curl \
    openssh-client \
    && rm -rf /var/lib/apt/lists/*

# Install Node.js (for Claude Code CLI)
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
    && apt-get install -y --no-install-recommends nodejs \
    && rm -rf /var/lib/apt/lists/*

# Install Claude Code CLI
RUN npm install -g @anthropic-ai/claude-code

# Install uv for fast Python dependency management
RUN pip install --no-cache-dir uv

# Copy project files
COPY . .

# Install dobby
RUN uv pip install --system -e .

# Create data directories
RUN mkdir -p /data/results /root/.claude

# Default environment
ENV DOBBY_HOST=0.0.0.0
ENV DOBBY_PORT=8420

# Expose default port (overridden per tenant)
EXPOSE 8420

# Volume for persistent data (db, results, claude auth)
VOLUME ["/data", "/root/.claude"]

# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
    CMD curl -f http://localhost:${DOBBY_PORT}/health || exit 1

# Entrypoint script
COPY deploy/multi-tenant/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
