FROM python:3.11-slim

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    gcc \
    libpq-dev \
    && rm -rf /var/lib/apt/lists/*

# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv

# Copy dependency files first (including README.md required by pyproject.toml)
COPY pyproject.toml uv.lock README.md ./

# Copy package directories needed for installation
COPY wistx_mcp/ ./wistx_mcp/
COPY data_pipelines/ ./data_pipelines/

# Install dependencies (this will install the project including wistx_mcp)
RUN uv sync --frozen

# Copy application code
COPY api/ ./api/

# Expose port (Cloud Run sets PORT env var automatically based on container_port)
EXPOSE 8000

# Run application - read PORT from environment variable (Cloud Run sets it)
CMD ["sh", "-c", "uv run uvicorn api.main:app --host 0.0.0.0 --port ${PORT:-8000}"]
