Skip to content

Commit

Permalink
small base image
Browse files Browse the repository at this point in the history
  • Loading branch information
cboettig committed Sep 27, 2024
1 parent 4b25081 commit deb1af4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 32 deletions.
40 changes: 8 additions & 32 deletions images/Dockerfile.R
Original file line number Diff line number Diff line change
@@ -1,40 +1,16 @@
FROM quay.io/jupyter/pytorch-notebook:cuda12-ubuntu-24.04
COPY jupyter-ai.yml environment.yml

RUN conda update -n base -c conda-forge conda && \
conda env update --file environment.yml
FROM quay.io/jupyter/minimal-notebook

USER root
RUN curl -fsSL https://code-server.dev/install.sh | sh && rm -rf .cache
RUN git config --system pull.rebase false && \
echo '"\e[5~": history-search-backward' >> /etc/inputrc && \
echo '"\e[6~": history-search-forward' >> /etc/inputrc

RUN usermod -a -G staff ${NB_USER} \
&& echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \
&& locale-gen en_US.utf8 \
&& /usr/sbin/update-locale LANG=en_US.UTF-8

## Set some variables
ENV LC_ALL en_US.UTF-8
ENV LANG en_US.UTF-8
ENV DEBIAN_FRONTEND noninteractive
ENV TZ UTC
# Install R
COPY install_r.sh install_r.sh
RUN bash install_r.sh

RUN curl -fsSL https://raw.githubusercontent.com/eddelbuettel/r2u/refs/heads/master/inst/scripts/add_cranapt_noble.sh | sh
RUN apt-get update && \
apt-get install -y --no-install-recommends \
r-base r-base-dev r-recommended \
r-cran-docopt r-cran-littler r-cran-remotes \
python3-dbus python3-gi python3-apt sudo \
&& Rscript -e 'install.packages("bspm")' \
## Support user-level installation of R packages
&& chown root:staff /usr/lib/R/site-library \
&& chmod g+ws /usr/lib/R/site-library \
&& echo "options(bspm.sudo = TRUE)" >> /usr/lib/R/etc/Rprofile.site
# Now install any CRAN packages the usual way
RUN R -e "install.packages(c('terra', 'stars'))"

## add user to sudoers
RUN echo "${NB_USER} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
## Or the more concise Rocker way
RUN install2.r rstan ROracle

## RStudio
RUN conda install jupyter-rsession-proxy
Expand Down
48 changes: 48 additions & 0 deletions images/install_r.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

## First: update apt and get keys
apt update -qq && apt install --yes --no-install-recommends wget ca-certificates gnupg
wget -q -O- https://eddelbuettel.github.io/r2u/assets/dirk_eddelbuettel_key.asc \
| tee -a /etc/apt/trusted.gpg.d/cranapt_key.asc

## Second: add the repo -- here we use the well-connected mirror
echo "deb [arch=amd64] https://r2u.stat.illinois.edu/ubuntu noble main" > /etc/apt/sources.list.d/cranapt.list
apt update

## Third: ensure current R is used
wget -q -O- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc \
| tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
echo "deb [arch=amd64] https://cloud.r-project.org/bin/linux/ubuntu noble-cran40/" > /etc/apt/sources.list.d/cran_r.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 67C2D66C4B1D4339 51716619E084DAB9
apt update -qq
DEBIAN_FRONTEND=noninteractive apt install --yes --no-install-recommends r-base r-base-dev r-recommended

## Fourth: add pinning to ensure package sorting
echo "Package: *" > /etc/apt/preferences.d/99cranapt
echo "Pin: release o=CRAN-Apt Project" >> /etc/apt/preferences.d/99cranapt
echo "Pin: release l=CRAN-Apt Packages" >> /etc/apt/preferences.d/99cranapt
echo "Pin-Priority: 700" >> /etc/apt/preferences.d/99cranapt

## Fifth: install bspm (and its Python requirements) and enable it
## If needed (in bare container, say) install python tools for bspm and R itself
apt install --yes --no-install-recommends python3-{dbus,gi,apt} \
make sudo r-cran-{docopt,littler,remotes}
## Then install bspm (as root) and enable it, and enable a speed optimization
Rscript -e 'install.packages("bspm")'
RHOME=$(R RHOME)
echo "suppressMessages(bspm::enable())" >> ${RHOME}/etc/Rprofile.site
echo "options(bspm.version.check=FALSE)" >> ${RHOME}/etc/Rprofile.site

chown root:staff ${RHOME}/site-library
chmod g+ws ${RHOME}/site-library
echo "options('bspm.sudo' = TRUE)" >> ${RHOME}/etc/Rprofile.site


ln -s /usr/lib/R/site-library/littler/examples/install2.r /usr/local/bin/install2.r


## add user to sudoers
usermod -a -G staff ${NB_USER}
echo "${NB_USER} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers


0 comments on commit deb1af4

Please sign in to comment.