FROM python:3.13-slim AS build

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

WORKDIR /usr/src/app

RUN apt-get -y update &&\
  apt-get -y install --no-install-recommends\
  python3 python3-pip python3-setuptools ca-certificates &&\
  apt-get -y clean &&\
  apt-get -y autoremove &&\
  rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* &&\
  truncate -s 0 /var/log/*log

COPY . .

RUN pip3 install . --break-system-packages

RUN playwright install firefox

FROM python:3.13-slim

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

RUN apt-get -y update &&\
  apt-get -y install --no-install-recommends \
  python3 python3-setuptools curl &&\
  apt-get -y clean &&\
  apt-get -y autoremove &&\
  rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* &&\
  truncate -s 0 /var/log/*log

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 /root/.cache/ms-playwright/ /root/.cache/ms-playwright/

RUN playwright install-deps firefox

# Create the Wapiti config directory
RUN mkdir -p /root/.wapiti/config/cves

# Copy NVD files to .wapiti/config/cves
COPY ./tests/integration/wapiti/*.json.xz /root/.wapiti/config/cves/

COPY ./tests/integration/wapiti/test.py /usr/local/bin/test.py
COPY ./tests/integration/wapiti/templates_and_data.py /usr/local/bin/templates_and_data.py
COPY ./tests/integration/wapiti/misc_functions.py /usr/local/bin/misc_functions.py
COPY ./tests/integration/wapiti/behavior.json /usr/local/bin/behavior.json

# Required to test external script for crawler auth,
# comment the 2 following lines if you removed test_crawler_auth integration tests for any reason
COPY ./tests/integration/test_crawler_auth/external_script_crawler_auth_test.py /usr/local/bin/external_script_crawler_auth_test.py
COPY ./tests/integration/test_crawler_auth/stored_cookie.json  /usr/local/bin/stored_cookie.json

ENTRYPOINT [ "python3","-u","/usr/local/bin/test.py"]
