# =============================================================================
# textual-docs-mcp — Multi-stage Docker build
# =============================================================================
# Image: ghcr.io/diaz3618/textual-docs-mcp
#
# Build:  docker build -t textual-docs-mcp .
# Run:    docker run -i textual-docs-mcp
#
# The server uses STDIO transport by default — connect via MCP client.
# =============================================================================

FROM python:3.12-slim AS builder

WORKDIR /app

# Install build dependencies
RUN pip install --no-cache-dir uv

# Copy only dependency specifications first (cache layer)
COPY pyproject.toml README.md LICENSE ./
COPY src/ ./src/

# Build wheel
RUN uv pip install --system build && python -m build --wheel

# ---------------------------------------------------------------------------
# Runtime stage
# ---------------------------------------------------------------------------
FROM python:3.12-slim AS runtime

LABEL org.opencontainers.image.source="https://github.com/diaz3618/textual-docs-mcp"
LABEL org.opencontainers.image.description="MCP server for Textual TUI documentation"
LABEL org.opencontainers.image.licenses="MIT"

WORKDIR /app

# Create non-root user
RUN useradd --create-home --shell /bin/bash appuser

# Copy wheel from builder and install
COPY --from=builder /app/dist/*.whl /tmp/
RUN pip install --no-cache-dir /tmp/*.whl && rm -rf /tmp/*.whl

# Switch to non-root user
USER appuser

# MCP server uses STDIO transport
ENTRYPOINT ["textual-docs-mcp"]
