FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates curl python3 python3-pip python3-venv tini && \
    rm -rf /var/lib/apt/lists/*

# Install recipe-scrapers, Playwright, and Anthropic SDK in a virtualenv to isolate dependencies.
RUN python3 -m venv /opt/roux-venv && \
    /opt/roux-venv/bin/pip install --no-cache-dir recipe-scrapers==15.11.0 playwright==1.52.0 anthropic pyyaml && \
    rm -rf /root/.cache/pip

# Install Playwright system dependencies and Chromium browser.
RUN /opt/roux-venv/bin/playwright install-deps chromium && \
    /opt/roux-venv/bin/playwright install chromium

# Build timestamp — read at runtime for diagnostics.
RUN mkdir -p /build && date -u '+%Y-%m-%d %H:%M UTC' > /build/build-time

ADD roux-server /usr/local/bin/roux-server
ADD scripts/scrape-recipe /usr/local/bin/scrape-recipe
ADD scripts/convert-to-cooklang /usr/local/bin/convert-to-cooklang
ADD prompts /usr/local/share/roux/prompts/

RUN chmod +x /usr/local/bin/roux-server /usr/local/bin/scrape-recipe /usr/local/bin/convert-to-cooklang
ENV PATH="/opt/roux-venv/bin:${PATH}"

ENTRYPOINT ["/usr/bin/tini", "-s", "--"]

# Recipes are mounted at /recipes at runtime via docker-compose volume mount.
RUN mkdir /recipes
WORKDIR /recipes

EXPOSE 8080

CMD ["/usr/local/bin/roux-server", "--host", "0.0.0.0", "--config-file", "/roux/config.yaml", "--port", "8080", "--recipe-dir", "/recipes"]
