FROM python:3.12-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
    curl openssh-client \
    && rm -rf /var/lib/apt/lists/* \
    && curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-27.5.1.tgz \
    | tar xz --strip-components=1 -C /usr/local/bin docker/docker

WORKDIR /app

# Install nanoclaude dependencies
COPY nanoclaude/requirements.txt ./requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Copy nanoclaude app
COPY nanoclaude/ ./

# Copy infra/ for infra_tool integration
COPY infra/ ./infra/

# Ensure infra has its own dependencies (pydantic, asyncssh already in requirements)
# Python path: /app is WORKDIR, so "from infra.core..." and "from tools..." both work

ENV PYTHONUNBUFFERED=1

RUN mkdir -p /app/data

EXPOSE 8100

HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
    CMD curl -f http://localhost:8100/health || exit 1

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8100"]
