FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder

ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy

WORKDIR /app

# Copy vendored schwab-scraper (checked out cleanly by CI) and pyproject.toml
COPY vendor/schwab-scraper /tmp/schwab-scraper
COPY pyproject.toml uv.lock ./

# Install schwab-scraper from the clean build-time checkout, then remaining deps.
# We strip the git dependency line so uv doesn't try to fetch over the network.
RUN uv venv && \
    uv pip install /tmp/schwab-scraper && \
    sed -i '/schwab-scraper/d' pyproject.toml && \
    uv pip install -r pyproject.toml && \
    uv pip install --upgrade playwright && \
    rm -rf /tmp/schwab-scraper

COPY . .

FROM python:3.12-slim-bookworm

RUN apt-get update && \
    apt-get install -y --no-install-recommends curl && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /app
COPY --from=builder /app /app

ENV PATH="/app/.venv/bin:$PATH"
ENV PORT=8000

EXPOSE 8000
CMD ["python", "server.py"]
