# Autodoc MCP Server - Lightweight Image
# ~200MB vs ~3GB for full image
# Excludes ML dependencies (chromadb, sentence-transformers, torch)
# Semantic search falls back to keyword search

FROM python:3.11-slim

WORKDIR /app

# Install minimal Python dependencies directly
RUN pip install --no-cache-dir \
    fastmcp>=2.14.1 \
    pydantic>=2.0.0 \
    pyyaml>=6.0.1 \
    click>=8.1.7 \
    rich>=13.7.0 \
    python-dotenv>=1.0.0

# Create source directory structure
RUN mkdir -p /app/src/autodoc

# Copy only necessary source files
COPY src/autodoc/__about__.py /app/src/autodoc/
COPY src/autodoc/config.py /app/src/autodoc/
COPY src/autodoc/mcp_server.py /app/src/autodoc/
COPY src/autodoc/skill_generator.py /app/src/autodoc/
COPY src/autodoc/features.py /app/src/autodoc/

# Create minimal __init__.py (avoid importing heavy sdk module)
RUN echo 'from autodoc.__about__ import __version__' > /app/src/autodoc/__init__.py

# Create stub for chromadb_embedder (imported lazily in mcp_server)
RUN echo '# Stub - not available in lightweight image' > /app/src/autodoc/chromadb_embedder.py

# Create non-root user and fix permissions
RUN useradd -m -u 1000 autodoc && \
    chown -R autodoc:autodoc /app

USER autodoc

ENV PORT=8080
ENV HOST=0.0.0.0
ENV PYTHONPATH=/app/src

# Run MCP server
CMD ["python", "-m", "autodoc.mcp_server", "--transport", "sse", "--host", "0.0.0.0", "--port", "8080"]
