# Helios CFD on your computer: the pinned OpenFOAM v2312 runtime from wind-service/container
# plus the room-CFD scripts and a small agent that pairs once and solves queued runs.
# linux/amd64 is intentional: the solver binaries are pinned upstream builds.
FROM python:3.12.12-slim-bookworm@sha256:593bd06efe90efa80dc4eee3948be7c0fde4134606dd40d8dd8dbcade98e669c
ENV DEBIAN_FRONTEND=noninteractive PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 \
    TMPDIR=/tmp HOME=/tmp OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1
RUN rm -f /etc/apt/sources.list.d/* && \
    printf 'deb [check-valid-until=no] https://snapshot.debian.org/archive/debian/20251115T000000Z bookworm main\ndeb [check-valid-until=no] https://snapshot.debian.org/archive/debian-security/20251115T000000Z bookworm-security main\n' > /etc/apt/sources.list && \
    apt-get update && apt-get install -y --no-install-recommends ca-certificates curl binutils libgomp1 && \
    rm -rf /var/lib/apt/lists/*
COPY wind-service/container/requirements.txt /opt/helios/requirements.txt
RUN python3 -m pip install --no-cache-dir --only-binary=:all: --require-hashes --no-deps -r /opt/helios/requirements.txt
COPY wind-service/install-local-solver.sh /opt/helios/install-local-solver.sh
RUN sed -i 's|http://archive.ubuntu.com|https://archive.ubuntu.com|g' /opt/helios/install-local-solver.sh && \
    mkdir -p /scratch && TMPDIR=/tmp bash /opt/helios/install-local-solver.sh && \
    rm -rf /tmp/of/x /tmp/of/mpi-wheel /tmp/of/scotch/x-* /tmp/of/*.deb /tmp/of/scotch/*.deb
COPY wind-service/container/runtime-manifest.py wind-service/container/entrypoint.sh /opt/helios/
RUN python3 /opt/helios/runtime-manifest.py seal && chmod -R a+rX /tmp/of /opt/helios
COPY room-cfd/ /opt/helios/room-cfd/
COPY local-compute/cfd-docker/local-agent.py local-compute/cfd-docker/source-manifest.py /opt/helios/
RUN python3 /opt/helios/source-manifest.py seal
RUN mkdir -p /data /scratch && chown 1000:1000 /data /scratch
ENV TMPDIR=/scratch HOME=/scratch
USER 1000:1000
ENTRYPOINT ["bash", "/opt/helios/entrypoint.sh"]
CMD ["python3", "/opt/helios/local-agent.py"]
