Skip to content

Commit

Permalink
Attempt to convert the R image to Rocker
Browse files Browse the repository at this point in the history
Attempting to convert the R image to Rocker, but it's kinda large.
  • Loading branch information
abkfenris committed Nov 19, 2024
1 parent 41445c1 commit 7750a45
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 935 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
services:
py:
build: ./py-base
platform: linux/amd64
command: jupyter lab --port=8080 --ip=0.0.0.0
ports:
- "8080:8080"

r:
build: ./r
platform: linux/amd64
command: jupyter lab --port=8080 --ip=0.0.0.0
ports:
- "8080:8080"
2 changes: 0 additions & 2 deletions r/CONDARC

This file was deleted.

234 changes: 129 additions & 105 deletions r/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,96 +1,131 @@
#syntax=docker/dockerfile:1.3
FROM continuumio/miniconda3:4.12.0@sha256:58b1c7df8d69655ffec017ede784a075e3c2e9feff0fc50ef65300fc75aa45ae

ENV NB_USER jovyan
ENV NB_UID 1000
ENV HOME /home/jovyan

ENV CONDA_DIR /opt/conda
ENV CONDA_ENV base
ENV R_LIBS_USER /opt/r

# Explicitly add littler to PATH
# See https://github.com/conda-forge/r-littler-feedstock/issues/6
ENV PATH ${CONDA_DIR}/lib/R/library/littler/bin:${CONDA_DIR}/bin:$PATH

# Output logging faster
ENV PYTHONUNBUFFERED 1
# Don't write bytecode
ENV PYTHONDONTWRITEBYTECODE 1

USER root
RUN adduser --disabled-password --gecos "Default Jupyter user" ${NB_USER} \
&& echo ". ${CONDA_DIR}/etc/profile.d/conda.sh ; conda activate ${CONDA_ENV}" > /etc/profile.d/init_conda.sh \
&& chown -R ${NB_USER}:${NB_USER} /srv

# Install these without 'recommended' packages to keep image smaller.
# Useful utils that folks sort of take for granted
RUN --mount=type=cache,id=ohw_r_apt,target=/var/cache/apt \
apt-get update -qq --yes > /dev/null && \
apt-get install --yes --no-install-recommends -qq \
curl \
git \
less \
tar \
tzdata \
vim \
wget \
locales \
psmisc \
sudo \
libapparmor1 \
libpq5 \
lsb-release \
ca-certificates \
libclang-dev > /dev/null \
&& update-ca-certificates \
&& rm -rf /var/lib/apt/lists/*

RUN echo "${LC_ALL} UTF-8" > /etc/locale.gen && \
locale-gen

# # Set path where R packages are installed
# # Download and install rstudio manually
# # Newer one has bug that doesn't work with jupyter-rsession-proxy
ENV RSTUDIO_URL https://download2.rstudio.org/server/bionic/amd64/rstudio-server-2022.07.1-554-amd64.deb
# ENV RSTUDIO_URL https://download2.rstudio.org/server/bionic/amd64/rstudio-server-1.2.5042-amd64.deb
RUN curl --silent --location --fail ${RSTUDIO_URL} > /tmp/rstudio.deb && \
dpkg -i /tmp/rstudio.deb && \
rm /tmp/rstudio.deb

USER ${USER}

WORKDIR ${HOME}
USER ${USER}

COPY ./conda-linux-64.lock /tmp/

RUN --mount=type=cache,id=ohw_r,target=/opt/conda/pkgs,uid=${NB_UID},gid=${NB_UID} \
conda install --name ${CONDA_ENV} --file /tmp/conda-linux-64.lock && \
# micromamba install --name ${CONDA_ENV} --file environment.yml && \
find -name '*.a' -delete && \
# rm -rf /opt/conda/conda-meta && \
rm -rf ${CONDA_DIR}/include && \
find -name '__pycache__' -type d -exec rm -rf '{}' '+'

ARG MAMBA_DOCKERFILE_ACTIVATE=1

# Install R libs from CRAN and GitHub
# 2024-10-10: Have there been improvements in install_cran and install_github such that
# dependencies, upgrade_dependencies, upgrade could now be set to TRUE or the default?
# RUN installGithub.R BigelowLab/rasf BigelowLab/ohwobpg # not working on GH but works locally :-/
RUN Rscript -e "remotes::install_cran('assertthat', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
Rscript -e "remotes::install_cran('forecast', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
Rscript -e "remotes::install_cran('ggspatial', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
Rscript -e "remotes::install_cran('plot.matrix', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
Rscript -e "remotes::install_cran('isdparser', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
Rscript -e "remotes::install_cran('geonames', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
Rscript -e "remotes::install_cran('readHAC', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
Rscript -e "remotes::install_cran('rnoaa', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
Rscript -e "remotes::install_cran('greybox', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
Rscript -e "remotes::install_cran('sfnetworks', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
Rscript -e "remotes::install_cran('smooth', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
Rscript -e "remotes::install_github('BigelowLab/ohwobpg', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
FROM ghcr.io/rocker-org/binder:4.4.1@sha256:0206f61770c76c3744ecd898c273a5778ad3dd18d1b30e396f90f00dec42d787

ENV NB_UID=1000

RUN --mount=type=cache,id=ohw_r,target=/tmp/downloaded_packages,uid=${NB_UID},gid=${NB_UID} \
install2.r -e \
assertthat \
forecast \
ggspatial \
plot.matrix \
isdparser \
geonames \
readHAC \
# rnoaa \ not available for this version of R
greybox \
sfnetworks \
smooth \
akima \
ape \
automap \
biomod2 \
bitops \
caret \
# catools \ not available for this version of R
checkmate \
commonmark \
cowplot \
crul \
# dbi \
# devtools \
# dichromat \
dismo \
# doparallel \ not available for this version of R
# dplyr \
earth \
rerddap \
foreach \
# foreign \
# fracdiff \
gbm >=2.1.3 \
geometry \
# geosphere \
# ggplot2 \
glmnet \
# gridextra \ not available for this version of R
gsw \
hexbin \
httpcache \
# httr \
# igraph \
# irkernel \
# jsonlite \
# knitr \
# lattice \
# leaflet \
# littler \
# lmtest \
# lpsolve \ not available for this version of R
# lubridate \
mmand \
# mapdata \
mapedit \
# maps \
# maptools \ not available for this version of R
marmap \
markdown \
# mass \
mda \
# metr \ not available for this version of R
# ncdf4 \
# nnet \
# nloptr \
oce \
ocedata \
rosm \
palmerpenguins \
patchwork \
PCICt \
plotly \
# proc >=1.15.0 \ not available for this version of R
# ps>=1.3.4 \
# purrr \
# r.utils \ not available for this version of R
# randomforest \ not available for this version of R
# rann \ not available for this version of R
# raster >=1.4.3 \
# rastervis \ not available for this version of R
# readr \
# remotes \
reshape \
# rgdal >=1.5 \ not available for this version of R
# rgeos \ not available for this version of R
rlang \
# rmarkdown \
rnaturalearth \
rnaturalearthdata \
robis \
# rpart \
# rsqlite \
rstackdeque \
rvest \
# s2 \
# scales \
# sf >=0.9_5 \
# sp \
# stars \
# terra \
# tibble \
# tidyr \
# tidygraph \
# tidyverse \
tiff \
# tmap \
# tmaptools \
# tseries \
tsibble \
tzdb \
udunits2 \
# urca \
vegan \
viridis \
# vroom \
wdpar \
xaringan
# xml2 \
# xts \

RUN Rscript -e "remotes::install_github('BigelowLab/ohwobpg', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
Rscript -e "remotes::install_github('BigelowLab/rasf', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
Rscript -e "remotes::install_github('BigelowLab/xyzt', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
Rscript -e "remotes::install_github('BigelowLab/ghrsst', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
Expand All @@ -102,15 +137,4 @@ RUN Rscript -e "remotes::install_cran('assertthat', dependencies=FALSE, upgrade_
Rscript -e "remotes::install_github('hvillalo/periods', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
Rscript -e "remotes::install_github('hvillalo/satin', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
Rscript -e "remotes::install_github('kwstat/pals', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)" && \
Rscript -e "remotes::install_github('JorGarMol/VoCC', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)"

COPY CONDARC ./.condarc
COPY Rprofile.site /opt/conda/lib/R/etc/

ENV PATH /usr/lib/rstudio-server/bin/:${PATH}

ENV LD_LIBRARY_PATH=${CONDA_DIR}/lib

# USER root
# RUN chown -R jovyan ${CONDA_DIR}
USER ${NB_USER}
Rscript -e "remotes::install_github('JorGarMol/VoCC', dependencies=FALSE, upgrade_dependencies=FALSE, upgrade=FALSE)"
5 changes: 0 additions & 5 deletions r/Rprofile.site

This file was deleted.

Loading

0 comments on commit 7750a45

Please sign in to comment.