FROM rocker/tidyverse:4.4.1

RUN apt-get update && apt-get install -y --no-install-recommends \
    make \
    curl \
    ca-certificates \
    texlive-latex-base \
    texlive-latex-recommended \
    texlive-fonts-recommended \
    texlive-pictures \
    texlive-latex-extra \
    lmodern \
    && rm -rf /var/lib/apt/lists/*

ENV RENV_CONFIG_REPOS_OVERRIDE=https://packagemanager.posit.co/cran/__linux__/jammy/latest \
    RENV_CONFIG_AUTOLOADER_ENABLED=FALSE

COPY figures/renv.lock /tmp/figures/renv.lock
RUN R -e 'install.packages("renv"); setwd("/tmp/figures"); renv::restore(prompt = FALSE)' && rm -rf /tmp/figures

ADD https://astral.sh/uv/install.sh /uv-installer.sh
RUN UV_INSTALL_DIR=/usr/local/bin sh /uv-installer.sh && rm /uv-installer.sh

ENV UV_PROJECT_ENVIRONMENT=/opt/venv \
    UV_PYTHON_INSTALL_DIR=/opt/uv-python \
    PATH=/opt/venv/bin:$PATH

COPY analysis/pyproject.toml analysis/uv.lock /tmp/analysis/
RUN cd /tmp/analysis && uv sync --frozen --no-install-project && rm -rf /tmp/analysis \
    && chmod -R o+rX /opt/venv /opt/uv-python

WORKDIR /work/eval
