# Hyimg remote test runner image (Concepts/workflows/2610260400-remote-test-runner/README.md).
# Build context: this folder (Dockerfile, runner.py, entrypoint.sh, bindgen.sh). Dokploy builds it from a drop zip on the server:
#   scripts/testrunner/deploy.sh   (zips this folder; the Dokploy key comes from MetaSecret)
# Node LTS (the Mac runs 22) + pinned TypeScript (check.sh runs `tsc -p jsconfig.json`) in a build stage so npm stays out of the runtime image
FROM node:22-bookworm-slim AS node_tsc
ARG TYPESCRIPT=5.7.2
RUN npm install -g --no-audit --no-fund "typescript@${TYPESCRIPT}" && tsc --version

FROM python:3.12-slim-bookworm
ENV DEBIAN_FRONTEND=noninteractive PIP_NO_CACHE_DIR=1 PIP_DISABLE_PIP_VERSION_CHECK=1 PYTHONUNBUFFERED=1 \
    PLAYWRIGHT_BROWSERS_PATH=/opt/pw RUSTUP_HOME=/opt/rustup CARGO_HOME=/opt/cargo PATH=/data/bin:/opt/cargo/bin:$PATH
# tools: git over ssh for the fetch, a C toolchain for cargo's build scripts, ffmpeg for the media tests, tini as PID 1
RUN apt-get update && apt-get install -y --no-install-recommends git openssh-client ca-certificates curl xz-utils procps util-linux tini \
      build-essential pkg-config ffmpeg libgl1 libglib2.0-0 libvulkan1 \
 && rm -rf /var/lib/apt/lists/*
# Node LTS and pinned tsc (no npm in the runtime image)
COPY --from=node_tsc /usr/local/bin/node /usr/local/bin/node
COPY --from=node_tsc /usr/local/lib/node_modules/typescript /usr/local/lib/node_modules/typescript
RUN chmod -R a+rX /usr/local/lib/node_modules/typescript \
 && ln -s /usr/local/lib/node_modules/typescript/bin/tsc /usr/local/bin/tsc \
 && tsc --version
# what scripts/cloud_setup.sh installs, plus what the suites import (the heavy Mac-only ones are skipped by their tests)
RUN pip install pillow numpy certifi cryptography cairosvg pymupdf pillow-heif opencv-python-headless \
      pytest pytest-xdist pytest-timeout playwright
# Chromium and WebKit with their system libraries and fonts
RUN playwright install --with-deps chromium webkit && rm -rf /var/lib/apt/lists/* && chmod -R a+rX /opt/pw
# Rust stable + wasm32, wasm-bindgen as a prebuilt binary of the version hyrender/Cargo.lock pins (bindgen.sh)
RUN curl -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain stable -t wasm32-unknown-unknown --no-modify-path \
 && chown -R 10001:10001 /opt/rustup && chmod -R a+rX /opt/cargo
COPY bindgen.sh /app/bindgen.sh
ARG WASM_BINDGEN=0.2.129
RUN chmod +x /app/bindgen.sh && BINDGEN_DEST=/opt/cargo/bin /app/bindgen.sh "$WASM_BINDGEN" && wasm-bindgen --version
RUN useradd -u 10001 -m -s /bin/bash runner
COPY runner.py bundles.py entrypoint.sh xdist_isolate.py retry.py retry_pytest.py retry_node.mjs /app/
RUN chmod +x /app/entrypoint.sh
EXPOSE 8080
ENTRYPOINT ["tini", "--", "/app/entrypoint.sh"]
