# App test runner for Docker Desktop: Python, pytest and the framework's dependencies, no repository code.
# scripts/docker_app_tests mounts the project (or the repository) at /work, so every run uses the current
# tests and writes its reports to the project's reports/ folder. The phone it drives runs elsewhere (scripts/docker_android,
# reached at host.docker.internal:4725 through the apps.yaml target android-docker-runner).
FROM python:3.12-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PYTHONUTF8=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1

# In the iHarmony repository the image gets requirements.txt (the mounted source is the framework). In a project
# made by "iharmony init" there is no requirements.txt: the framework comes from PyPI, at the version the
# scripts pass in IHARMONY_VERSION (the one in the project's .venv).
ARG IHARMONY_VERSION=
COPY docker/app-tests/Dockerfile requirements.tx[t] /tmp/build/
RUN if [ -f /tmp/build/requirements.txt ]; then \
        pip install --no-cache-dir -r /tmp/build/requirements.txt "Appium-Python-Client==6.0.7"; \
    else \
        pip install --no-cache-dir "iharmony[apps,html-reporting]${IHARMONY_VERSION:+==$IHARMONY_VERSION}"; \
    fi \
    && rm -rf /tmp/build \
    && useradd --create-home --uid 1000 tester

USER tester
WORKDIR /work
ENTRYPOINT ["python", "-m", "pytest"]
