From 1c4068edc8eb1d0b21d04f7cda4befeca21638c7 Mon Sep 17 00:00:00 2001 From: grallewellyn Date: Thu, 19 Feb 2026 09:06:56 -0800 Subject: [PATCH 1/2] separate r-base image and tested --- base_images/2i2c/pangeo/environment.yml | 2 +- base_images/2i2c/r-base/docker/Dockerfile | 71 +++++++++++++++++++ base_images/2i2c/r-base/environment.yml | 15 ++++ base_images/2i2c/r-base/scripts/init-user.sh | 33 +++++++++ .../2i2c/{r => r-base}/scripts/install2.r | 0 .../scripts/install_cran_packages_r.sh | 0 .../scripts/print_package_versions.R | 0 .../scripts/r_package_versions.txt | 0 base_images/2i2c/r/docker/Dockerfile | 47 +----------- base_images/2i2c/r/environment.yml | 18 +---- 10 files changed, 124 insertions(+), 62 deletions(-) create mode 100644 base_images/2i2c/r-base/docker/Dockerfile create mode 100644 base_images/2i2c/r-base/environment.yml create mode 100644 base_images/2i2c/r-base/scripts/init-user.sh rename base_images/2i2c/{r => r-base}/scripts/install2.r (100%) rename base_images/2i2c/{r => r-base}/scripts/install_cran_packages_r.sh (100%) rename base_images/2i2c/{r => r-base}/scripts/print_package_versions.R (100%) rename base_images/2i2c/{r => r-base}/scripts/r_package_versions.txt (100%) diff --git a/base_images/2i2c/pangeo/environment.yml b/base_images/2i2c/pangeo/environment.yml index e8c57d6..10b13f7 100644 --- a/base_images/2i2c/pangeo/environment.yml +++ b/base_images/2i2c/pangeo/environment.yml @@ -3,7 +3,7 @@ channels: - conda-forge - nodefaults dependencies: - - pip=25.2 + - pip=26.0 - pip: - rio-tiler==8.0.5 - maap-py==4.2.0 diff --git a/base_images/2i2c/r-base/docker/Dockerfile b/base_images/2i2c/r-base/docker/Dockerfile new file mode 100644 index 0000000..7fdcc44 --- /dev/null +++ b/base_images/2i2c/r-base/docker/Dockerfile @@ -0,0 +1,71 @@ +FROM ghcr.io/nmfs-opensci/container-images/py-rocket-geospatial-2:2026.01.25 +ENV LANG=en_US.UTF-8 +ENV TZ=US/Pacific +ARG DEBIAN_FRONTEND=noninteractive + +USER root + +# Install system R and development libraries +# R will be completely separate from conda +RUN apt-get clean && apt-get update && \ + apt-get install -y --no-install-recommends \ + gdal-bin=3.8.4+dfsg-3ubuntu3 \ + lbzip2=2.5-2.3 \ + libfftw3-dev=3.3.10-1ubuntu3 \ + libgdal-dev=3.8.4+dfsg-3ubuntu3 \ + libgeos-dev=3.12.1-3build1 \ + libgl1-mesa-dev=25.0.7-0ubuntu0.24.04.2 \ + libglu1-mesa-dev=9.0.2-1.1build1 \ + libhdf4-alt-dev=4.2.16-4build1 \ + libhdf5-dev=1.10.10+repack-3.1ubuntu4 \ + libjq-dev=1.7.1-3ubuntu0.24.04.1 \ + libpq-dev=16.11-0ubuntu0.24.04.1 \ + libproj-dev=9.4.0-1build2 \ + libprotobuf-dev=3.21.12-8.2ubuntu0.2 \ + libnetcdf-dev=1:4.9.2-5ubuntu4 \ + libsqlite3-dev=3.45.1-1ubuntu2.5 \ + libssl-dev=3.0.13-0ubuntu3.6 \ + libudunits2-dev=2.2.28-7build1 \ + netcdf-bin=1:4.9.2-5ubuntu4 \ + postgis=3.4.2+dfsg-1ubuntu3 \ + protobuf-compiler=3.21.12-8.2ubuntu0.2 \ + sqlite3=3.45.1-1ubuntu2.5 \ + tk-dev=8.6.14build1 \ + unixodbc-dev=2.3.12-1ubuntu0.24.04.1 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +USER ${NB_USER} + +# Install additional packages from environment.yml +COPY ./environment.yml /tmp +RUN conda env update -n ${CONDA_ENV} -f "/tmp/environment.yml" \ + && find ${CONDA_DIR}/ -follow -type f -name '*.a' -delete \ + && find ${CONDA_DIR}/ -follow -type f -name '*.js.map' -delete \ + && ${CONDA_DIR}/bin/conda clean -afy + +RUN conda init + +USER root +SHELL ["/bin/bash", "-c"] +ADD . / +RUN ["chmod", "+x", "/scripts/install_cran_packages_r.sh"] +# Install R packages using SYSTEM R (not conda R) +# Do NOT activate conda environment here +# Clear conda's compiler paths to force use of system compiler +RUN export PATH=/usr/local/bin:/usr/bin:/bin:$PATH && \ + /scripts/install_cran_packages_r.sh + +RUN PYTHON_PATH=$(which python) && \ + R_HOME=$(R RHOME) && \ + echo "library(reticulate)" >> "$R_HOME/etc/Rprofile.site" && \ + echo "use_python(\"$PYTHON_PATH\", required = TRUE)" >> "$R_HOME/etc/Rprofile.site" && \ + echo "py_config()" >> "$R_HOME/etc/Rprofile.site" + +COPY scripts/init-user.sh /usr/local/bin/init-user.sh +RUN chmod +x /usr/local/bin/init-user.sh + +USER ${NB_USER} + +# This script returns control to base image's /srv/start after +ENTRYPOINT ["/usr/local/bin/init-user.sh"] \ No newline at end of file diff --git a/base_images/2i2c/r-base/environment.yml b/base_images/2i2c/r-base/environment.yml new file mode 100644 index 0000000..8a7485e --- /dev/null +++ b/base_images/2i2c/r-base/environment.yml @@ -0,0 +1,15 @@ +name: notebook +channels: + - conda-forge + - nodefaults +dependencies: + # Python packages only - NO R packages in conda + - gdal=3.10.2 + - nodejs=20.19.5 + - rtree=1.4.1 + - unzip=6.0 + - pip=26.0 + - pip: + # - git+https://github.com/MAAP-Project/stac_ipyleaflet.git@0.3.6 + - morecantile==6.1.0 + - rio-tiler==7.2.2 \ No newline at end of file diff --git a/base_images/2i2c/r-base/scripts/init-user.sh b/base_images/2i2c/r-base/scripts/init-user.sh new file mode 100644 index 0000000..c02443f --- /dev/null +++ b/base_images/2i2c/r-base/scripts/init-user.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +R_SITE_ENV=$(R RHOME)/etc/Renviron.site + +# Variables we want to add to Renviron +VARS=("AWS_ROLE_ARN" "AWS_WEB_IDENTITY_TOKEN_FILE" "AWS_DEFAULT_REGION" "MAAP_PGT") + +echo "--- Updating R Site Environment Variables ---" + +# Loop through the variables and append them if they exist in the current shell +for var_name in "${VARS[@]}"; do + # Use indirect expansion to get the value of the variable name + var_value="${!var_name}" + + if [ -n "$var_value" ]; then + echo "Adding $var_name to $R_SITE_ENV" + # Check if the line already exists to avoid duplicates + if ! grep -q "^$var_name=" "$R_SITE_ENV"; then + echo "$var_name=$var_value" >> "$R_SITE_ENV" + else + # Update existing line if it changed + sed -i "s|^$var_name=.*|$var_name=$var_value|" "$R_SITE_ENV" + fi + else + echo "Skipping $var_name: Not set in shell environment." + fi +done + +# File ends with a newline +echo "" >> "$R_SITE_ENV" + +# Hand control to the base image's /srv/start which handles all initialization +exec /srv/start "$@" \ No newline at end of file diff --git a/base_images/2i2c/r/scripts/install2.r b/base_images/2i2c/r-base/scripts/install2.r similarity index 100% rename from base_images/2i2c/r/scripts/install2.r rename to base_images/2i2c/r-base/scripts/install2.r diff --git a/base_images/2i2c/r/scripts/install_cran_packages_r.sh b/base_images/2i2c/r-base/scripts/install_cran_packages_r.sh similarity index 100% rename from base_images/2i2c/r/scripts/install_cran_packages_r.sh rename to base_images/2i2c/r-base/scripts/install_cran_packages_r.sh diff --git a/base_images/2i2c/r/scripts/print_package_versions.R b/base_images/2i2c/r-base/scripts/print_package_versions.R similarity index 100% rename from base_images/2i2c/r/scripts/print_package_versions.R rename to base_images/2i2c/r-base/scripts/print_package_versions.R diff --git a/base_images/2i2c/r/scripts/r_package_versions.txt b/base_images/2i2c/r-base/scripts/r_package_versions.txt similarity index 100% rename from base_images/2i2c/r/scripts/r_package_versions.txt rename to base_images/2i2c/r-base/scripts/r_package_versions.txt diff --git a/base_images/2i2c/r/docker/Dockerfile b/base_images/2i2c/r/docker/Dockerfile index aa72b2b..ae1551a 100644 --- a/base_images/2i2c/r/docker/Dockerfile +++ b/base_images/2i2c/r/docker/Dockerfile @@ -1,40 +1,8 @@ -FROM ghcr.io/nmfs-opensci/container-images/py-rocket-geospatial-2:2026.01.25 +FROM mas.dit.maap-project.org/root/maap-workspaces/2i2c/r-base:develop ENV LANG=en_US.UTF-8 ENV TZ=US/Pacific ARG DEBIAN_FRONTEND=noninteractive -USER root - -# Install system R and development libraries -# R will be completely separate from conda -RUN apt-get clean && apt-get update && \ - apt-get install -y --no-install-recommends \ - gdal-bin=3.8.4+dfsg-3ubuntu3 \ - lbzip2=2.5-2.3 \ - libfftw3-dev=3.3.10-1ubuntu3 \ - libgdal-dev=3.8.4+dfsg-3ubuntu3 \ - libgeos-dev=3.12.1-3build1 \ - libgl1-mesa-dev=25.0.7-0ubuntu0.24.04.2 \ - libglu1-mesa-dev=9.0.2-1.1build1 \ - libhdf4-alt-dev=4.2.16-4build1 \ - libhdf5-dev=1.10.10+repack-3.1ubuntu4 \ - libjq-dev=1.7.1-3ubuntu0.24.04.1 \ - libpq-dev=16.11-0ubuntu0.24.04.1 \ - libproj-dev=9.4.0-1build2 \ - libprotobuf-dev=3.21.12-8.2ubuntu0.2 \ - libnetcdf-dev=1:4.9.2-5ubuntu4 \ - libsqlite3-dev=3.45.1-1ubuntu2.5 \ - libssl-dev=3.0.13-0ubuntu3.6 \ - libudunits2-dev=2.2.28-7build1 \ - netcdf-bin=1:4.9.2-5ubuntu4 \ - postgis=3.4.2+dfsg-1ubuntu3 \ - protobuf-compiler=3.21.12-8.2ubuntu0.2 \ - sqlite3=3.45.1-1ubuntu2.5 \ - tk-dev=8.6.14build1 \ - unixodbc-dev=2.3.12-1ubuntu0.24.04.1 && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - USER ${NB_USER} # Install additional packages from environment.yml @@ -44,15 +12,4 @@ RUN conda env update -n ${CONDA_ENV} -f "/tmp/environment.yml" \ && find ${CONDA_DIR}/ -follow -type f -name '*.js.map' -delete \ && ${CONDA_DIR}/bin/conda clean -afy -RUN conda init - -USER root -SHELL ["/bin/bash", "-c"] -ADD . / -RUN ["chmod", "+x", "/scripts/install_cran_packages_r.sh"] -# Install R packages using SYSTEM R (not conda R) -# Do NOT activate conda environment here -# Clear conda's compiler paths to force use of system compiler -RUN export PATH=/usr/local/bin:/usr/bin:/bin:$PATH && \ - /scripts/install_cran_packages_r.sh -USER ${NB_USER} \ No newline at end of file +RUN conda init \ No newline at end of file diff --git a/base_images/2i2c/r/environment.yml b/base_images/2i2c/r/environment.yml index 5248c02..463c083 100644 --- a/base_images/2i2c/r/environment.yml +++ b/base_images/2i2c/r/environment.yml @@ -3,16 +3,8 @@ channels: - conda-forge - nodefaults dependencies: - # Python packages only - NO R packages in conda - - gdal=3.10.2 - - nodejs=20.19.5 - - rtree=1.4.1 - - unzip=6.0 - - pip=25.2 + - pip=26.0 - pip: - # - git+https://github.com/MAAP-Project/stac_ipyleaflet.git@0.3.6 - - morecantile==6.1.0 - - rio-tiler==7.2.2 - maap-py==4.2.0 - maap-algorithms-jupyter-extension==0.5.1 - maap-jupyter-server-extension==3.0.0 @@ -20,10 +12,4 @@ dependencies: # - maap-edsc-jupyter-extension==1.1.1 - maap-help-jupyter-extension==2.0.2 - maap-libs-jupyter-extension==1.2.5 - - maap-user-workspace-management-jupyter-extension==1.0.0 -variables: - TITILER_STAC_ENDPOINT: 'https://openveda.cloud/api/stac' - TITILER_ENDPOINT: 'https://openveda.cloud/api/raster' - STAC_CATALOG_NAME: 'VEDA STAC' - STAC_CATALOG_URL: 'https://openveda.cloud/api/stac' - STAC_BROWSER_URL: 'https://openveda.cloud/' \ No newline at end of file + - maap-user-workspace-management-jupyter-extension==1.0.0 \ No newline at end of file From 9741aa38eb46b9c338bcfb90aad453c40905bb12 Mon Sep 17 00:00:00 2001 From: grallewellyn Date: Thu, 19 Feb 2026 12:57:10 -0800 Subject: [PATCH 2/2] removed r essentials and added awscliv2 post install command (and tested) --- base_images/2i2c/r-base/docker/Dockerfile | 2 ++ base_images/2i2c/r-base/scripts/install_cran_packages_r.sh | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/base_images/2i2c/r-base/docker/Dockerfile b/base_images/2i2c/r-base/docker/Dockerfile index 7fdcc44..df4f18b 100644 --- a/base_images/2i2c/r-base/docker/Dockerfile +++ b/base_images/2i2c/r-base/docker/Dockerfile @@ -46,6 +46,8 @@ RUN conda env update -n ${CONDA_ENV} -f "/tmp/environment.yml" \ RUN conda init +RUN awscliv2 --install + USER root SHELL ["/bin/bash", "-c"] ADD . / diff --git a/base_images/2i2c/r-base/scripts/install_cran_packages_r.sh b/base_images/2i2c/r-base/scripts/install_cran_packages_r.sh index e1e4159..160ef4b 100644 --- a/base_images/2i2c/r-base/scripts/install_cran_packages_r.sh +++ b/base_images/2i2c/r-base/scripts/install_cran_packages_r.sh @@ -14,7 +14,6 @@ Rscript /scripts/install2.r --error --skipmissing --skipinstalled -l "$R_LIB" -r Rscript /scripts/install2.r --error --skipmissing --skipinstalled -l "$R_LIB" -r "https://cran.r-project.org" -n "$NCPUS" "tidyterra" Rscript /scripts/install2.r --error --skipmissing --skipinstalled -l "$R_LIB" -r "https://cran.r-project.org" -n "$NCPUS" "BIOMASS" Rscript /scripts/install2.r --error --skipmissing --skipinstalled -l "$R_LIB" -r "https://cran.r-project.org" -n "$NCPUS" "nlraa" -Rscript /scripts/install2.r --error --skipmissing --skipinstalled -l "$R_LIB" -r "https://cran.r-project.org" -n "$NCPUS" "essentials" Rscript /scripts/install2.r --error --skipmissing --skipinstalled -l "$R_LIB" -r "https://cran.r-project.org" -n "$NCPUS" "geojsonio" Rscript /scripts/install2.r --error --skipmissing --skipinstalled -l "$R_LIB" -r "https://cran.r-project.org" -n "$NCPUS" "future" Rscript /scripts/install2.r --error --skipmissing --skipinstalled -l "$R_LIB" -r "https://r-lidar.r-universe.dev" -n "$NCPUS" "lasR"