# syntax=docker/dockerfile:1.7
# Dask scheduler and workers for ISSSTELEON's TEA EEG batches (age baselines, EEG analysis). Build it with
# ./build.sh, which writes requirements.lock and passes the ISSSTELEON checkout as the `isssteleon` build context.
#
# Only what the workers run: the tea library and the models package its tasks come from, with their dependencies
# at the versions of the platform's lockfile (ISSSTELEON/WebApi/uv.lock). The same base as the platform's image,
# so Python is the one distributed's version check expects.
FROM python:3.12-slim

COPY --from=ghcr.io/astral-sh/uv:0.13.1 /uv /bin/uv

# One BLAS thread per worker process, as the platform's own local cluster does.
ENV OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 MKL_NUM_THREADS=1 \
    UV_SYSTEM_PYTHON=1 UV_NO_CACHE=1

COPY requirements.lock /opt/isssteleon/requirements.lock
RUN uv pip install -r /opt/isssteleon/requirements.lock

# The workers unpickle models.tea.eeg tasks, which import models, tea, core and persistance.
COPY --from=isssteleon Core        /opt/isssteleon/Core
COPY --from=isssteleon Persistance /opt/isssteleon/Persistance
COPY --from=isssteleon Extraction  /opt/isssteleon/Extraction
COPY --from=isssteleon models      /opt/isssteleon/models
RUN uv pip install --no-deps \
        /opt/isssteleon/Core /opt/isssteleon/Persistance /opt/isssteleon/Extraction \
        /opt/isssteleon/models/libs/tea /opt/isssteleon/models \
    && python -c "import models.tea.eeg.train, models.tea.eeg.analyze, models.eeg_analysis, tea, distributed; print('distributed', distributed.__version__)"

COPY versions.py /opt/isssteleon/versions.py
RUN useradd --uid 10001 --create-home dask
USER dask
WORKDIR /home/dask

ARG ISSSTELEON_COMMIT=unknown
LABEL org.opencontainers.image.title="isssteleon-dask" isssteleon.commit=$ISSSTELEON_COMMIT
