FROM python:3.13-slim AS build

ENV DEBIAN_FRONTEND=noninteractive \
  LANG=en_US.UTF-8

WORKDIR /usr/src/app

COPY . .

RUN pip install setuptools wheel build --break-system-packages
RUN pip install . --break-system-packages

RUN playwright install firefox

FROM python:3.13-slim

ENV DEBIAN_FRONTEND=noninteractive \
  LANG=en_US.UTF-8 \
  PYTHONDONTWRITEBYTECODE=1 \
  OPENSSL_CONF='/etc/wapiti/openssl_conf' \
  PLAYWRIGHT_BROWSERS_PATH=/opt/ms-playwright

COPY --from=build /usr/local/lib/python3.13/site-packages/ /usr/local/lib/python3.13/site-packages/
COPY --from=build /usr/local/bin/wapiti /usr/local/bin/wapiti-getcookie /usr/local/bin/playwright /usr/local/bin/
COPY --from=build --chmod=755 /root/.cache/ms-playwright/ /opt/ms-playwright/
COPY --chmod=755 openssl_conf /etc/wapiti/

RUN apt update \
  && apt-get install -y --no-install-recommends --no-install-suggests \
     xz-utils curl bzip2 \
  && playwright install-deps firefox  \
  && apt clean -yq \
  && apt autoremove -yq \
  && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
  && truncate -s 0 /var/log/*log \
  && echo "PLAYWRIGHT_BROWSERS_PATH=$PLAYWRIGHT_BROWSERS_PATH" >> /etc/environment

ENTRYPOINT ["wapiti"]

