FROM python:3.11-slim-bookworm # ── 1. System packages + R ────────────────────────────────────────── RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ r-base \ libcurl4-openssl-dev \ libssl-dev \ libxml2-dev \ libfontconfig1-dev \ libfreetype6-dev \ libharfbuzz-dev \ libfribidi-dev \ libpng-dev \ libjpeg-dev \ libtiff5-dev \ && rm -rf /var/lib/apt/lists/* # ── 2. R packages via Posit Package Manager (bookworm binaries) ────── RUN Rscript -e "\ options(repos = c(CRAN = 'https://packagemanager.posit.co/cran/__linux__/bookworm/latest')); \ install.packages(c( \ 'vctrs', 'rlang', 'pillar', \ 'readr', 'dplyr', 'tidyr', 'lubridate', \ 'ggplot2', 'MASS', 'zoo', 'jsonlite', 'scales' \ ), Ncpus = 2)" # ── 3. Install jupyter_client system-wide so IRkernel::installspec() can find it RUN pip install --no-cache-dir jupyter_client # ── 4. IRkernel — system-wide ──────────────────────────────────────── RUN Rscript -e "\ options(repos = c(CRAN = 'https://packagemanager.posit.co/cran/__linux__/bookworm/latest')); \ install.packages('IRkernel')" \ && Rscript -e "IRkernel::installspec(user = FALSE)" # ── 5. Non-root user (HF Spaces requirement) ───────────────────────── RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH WORKDIR /home/user/app # ── 6. Python dependencies ─────────────────────────────────────────── COPY --chown=user requirements.txt . RUN pip install --no-cache-dir --upgrade pip \ && pip install --no-cache-dir -r requirements.txt # ── 7. App source ──────────────────────────────────────────────────── COPY --chown=user . . # ── 8. Gradio networking ───────────────────────────────────────────── ENV GRADIO_SERVER_NAME="0.0.0.0" \ GRADIO_SERVER_PORT=7860 EXPOSE 7860 CMD ["python", "app.py"]