# KERN Code's UI audit (kc_ui_audit.py): a real Chromium driven by Playwright for Python signs in to the person's app and measures
# every page at phone, tablet and desktop width. axe-core is the accessibility rule set (contrast, names, labels), injected into each
# page. Built on the person's own machine by uiAudit.ts; the tag carries a hash of this file and kc_ui_audit.py.
FROM mcr.microsoft.com/playwright/python:v1.48.0-noble

# the image carries the browsers; the Python package is the same version as them
RUN pip install --no-cache-dir --break-system-packages playwright==1.48.0

ARG AXE_VERSION=4.10.2
RUN python3 -c "import io, tarfile, urllib.request; \
data = urllib.request.urlopen('https://registry.npmjs.org/axe-core/-/axe-core-${AXE_VERSION}.tgz').read(); \
t = tarfile.open(fileobj=io.BytesIO(data)); \
open('/opt/axe.min.js', 'wb').write(t.extractfile('package/axe.min.js').read()); \
open('/opt/axe-LICENSE', 'wb').write(t.extractfile('package/LICENSE').read())"

COPY kc_ui_audit.py /usr/local/bin/kc_ui_audit.py
ENTRYPOINT ["python3", "/usr/local/bin/kc_ui_audit.py"]
