# Build stage
FROM python:3.11-slim AS builder

WORKDIR /app

# Install uv
RUN pip install uv

# Copy project files
COPY pyproject.toml ./
COPY src ./src

# Install the package (non-editable)
RUN uv pip install --system .

# Runtime stage
FROM python:3.11-slim

WORKDIR /app

# Copy installed packages and source
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /app/src ./src

# Railway and Cloud Run both set PORT automatically, default to 8080
ENV PORT=8080
ENV PYTHONPATH=/app/src

# Expose the port
EXPOSE 8080

# Run in HTTP mode, using PORT env variable
CMD ["sh", "-c", "python -m maeris_mcp --mode=http --port=${PORT}"]
