Image size: 5.0 GB

For more on pulling from the registry, see the ilifu documentation.

First, once: add the registry and make it your default

singularity remote add --no-login idia-registry https://sregistry.idia.ac.za
singularity remote use idia-registry

If you added it before, as the ilifu docs describe, remote add says it already exists: just run remote use.

Log in, for a private collection

singularity remote login idia-registry

Paste a token from your token page when asked. Public collections need no login.

Pull the container

singularity pull library://rstudio/rstudio:sha256.d63394cfdf599c46a472c8f5d9236790bf800d3210265d47d039586fb5ee74c5

Shell into the container

singularity shell library://rstudio/rstudio:sha256.d63394cfdf599c46a472c8f5d9236790bf800d3210265d47d039586fb5ee74c5

Run the container

singularity run library://rstudio/rstudio:sha256.d63394cfdf599c46a472c8f5d9236790bf800d3210265d47d039586fb5ee74c5

First, once: add the registry and make it your default

apptainer remote add --no-login idia-registry https://sregistry.idia.ac.za
apptainer remote use idia-registry

If you added it before, as the ilifu docs describe, remote add says it already exists: just run remote use.

Log in, for a private collection

apptainer remote login idia-registry

Paste a token from your token page when asked. Public collections need no login.

Pull the container

apptainer pull library://rstudio/rstudio:sha256.d63394cfdf599c46a472c8f5d9236790bf800d3210265d47d039586fb5ee74c5

Shell into the container

apptainer shell library://rstudio/rstudio:sha256.d63394cfdf599c46a472c8f5d9236790bf800d3210265d47d039586fb5ee74c5

Run the container

apptainer run library://rstudio/rstudio:sha256.d63394cfdf599c46a472c8f5d9236790bf800d3210265d47d039586fb5ee74c5
Base singularity definition file, to create ubuntu-jammy.sif, which can then be used as a basis for more specific containers

This image has 3 apps. Pick one to see how to use it.

singularity run --app R library://rstudio/rstudio:sha256.d63394cfdf599c46a472c8f5d9236790bf800d3210265d47d039586fb5ee74c5

This works once you've added the registry as a remote (see the CLI tab). Add the app's arguments after the command. With Apptainer, start it with apptainer instead.

Runs

exec R "${@}"
singularity run --app Rscript library://rstudio/rstudio:sha256.d63394cfdf599c46a472c8f5d9236790bf800d3210265d47d039586fb5ee74c5

This works once you've added the registry as a remote (see the CLI tab). Add the app's arguments after the command. With Apptainer, start it with apptainer instead.

Runs

exec Rscript "${@}"
singularity run --app rstudio library://rstudio/rstudio:sha256.d63394cfdf599c46a472c8f5d9236790bf800d3210265d47d039586fb5ee74c5

This works once you've added the registry as a remote (see the CLI tab). Add the app's arguments after the command. With Apptainer, start it with apptainer instead.

Runs

if [ -z "${RSTUDIO_PASSWORD}" ]; then
  export RSTUDIO_PASSWORD=$( tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1 )
  echo "The environment variable RSTUDIO_PASSWORD was not set, so your password has been chosen for you. It's: ${RSTUDIO_PASSWORD}"
fi
PORT=$( python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()' )
HOST=$( /bin/hostname )
echo "Running rserver on port ${PORT}"
echo "To connect to this server run this on your local machine:"
echo "    ssh -A ${USER}@${HOST} -o \"ProxyCommand=ssh ${USER}@slurm.ilifu.ac.za nc ${HOST} 22\" -L8081:localhost:${PORT}"
echo "then visit http://localhost:8081 in your browser and use the username \"${USER}\" to login with the password \"${RSTUDIO_PASSWORD}\""
echo "(You may need to choose a different port (other than 8081), so remember to change this in both the ssh and browser)"
exec rserver --server-user ${USER} --auth-none 0 --auth-pam-helper rstudio_auth --secure-cookie-key-file ${HOME}/.RStudio.rserver/secure-cookie.key --www-port ${PORT} --server-data-dir ${HOME}/.RStudio.rserver/data "${@}"
Bootstrap: localimage
From: /software/common/containers/ubuntu-jammy-compile.sif

%labels
  Maintainer Dane Kennedy
  R_Version 4.4.1
  RStudio_Version 2023.06.1-524

%help
  RStudio 2023.06.1-524 container, built with R 4.4.1

%apprun R
  exec R "${@}"

%apprun Rscript
  exec Rscript "${@}"

%apprun rstudio
  if [ -z "${RSTUDIO_PASSWORD}" ]; then
    export RSTUDIO_PASSWORD=$( tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1 )
    echo "The environment variable RSTUDIO_PASSWORD was not set, so your password has been chosen for you. It's: ${RSTUDIO_PASSWORD}"
  fi
  PORT=$( python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()' )
  HOST=$( /bin/hostname )
  echo "Running rserver on port ${PORT}"
  echo "To connect to this server run this on your local machine:"
  echo "    ssh -A ${USER}@${HOST} -o \"ProxyCommand=ssh ${USER}@slurm.ilifu.ac.za nc ${HOST} 22\" -L8081:localhost:${PORT}"
  echo "then visit http://localhost:8081 in your browser and use the username \"${USER}\" to login with the password \"${RSTUDIO_PASSWORD}\""
  echo "(You may need to choose a different port (other than 8081), so remember to change this in both the ssh and browser)"
  exec rserver --server-user ${USER} --auth-none 0 --auth-pam-helper rstudio_auth --secure-cookie-key-file ${HOME}/.RStudio.rserver/secure-cookie.key --www-port ${PORT} --server-data-dir ${HOME}/.RStudio.rserver/data "${@}"

%runscript
  if [ -z "${RSTUDIO_PASSWORD}" ]; then
    export RSTUDIO_PASSWORD=$( tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1 )
    echo "The environment variable RSTUDIO_PASSWORD was not set, so your password has been chosen for you. It's: ${RSTUDIO_PASSWORD}"
  fi
  PORT=$( python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()' )
  HOST=$( /bin/hostname )
  echo "Running rserver on port ${PORT}"
  echo "To connect to this server run this on your local machine:"
  echo "    ssh -A ${USER}@${HOST} -o \"ProxyCommand=ssh ${USER}@slurm.ilifu.ac.za nc ${HOST} 22\" -L8081:localhost:${PORT}"
  echo "then visit http://localhost:8081 in your browser and use the username \"${USER}\" to login with the password \"${RSTUDIO_PASSWORD}\""
  echo "(You may need to choose a different port (other than 8081), so remember to change this in both the ssh and browser)"
  exec rserver --server-user ${USER} --auth-none 0 --auth-pam-helper rstudio_auth --secure-cookie-key-file ${HOME}/.RStudio.rserver/secure-cookie.key --www-port ${PORT} --server-data-dir ${HOME}/.RStudio.rserver/data "${@}"

%environment
  export R_VERSION=4.4.1
  export RSTUDIO_VERSION=2023.06.1-524
  export PATH=/usr/lib/rstudio-server/bin:${PATH}

# Thanks to nickjer for this! https://github.com/nickjer/singularity-rstudio/blob/master/Singularity.3.6.0
%setup
  mkdir -p ${SINGULARITY_ROOTFS}/usr/lib/rstudio-server/bin

%files
  files/rstudio_auth.sh /usr/lib/rstudio-server/bin/rstudio_auth

%post
  # Create Installation Directories and export paths. This is needed as part of post.
  # %environment scriptlet does not define these paths during %post, only after.
  export R_VERSION=4.4.1
  export RSTUDIO_VERSION=2023.06.1-524
  export DEBIAN_FRONTEND=noninteractive

  # Update apt
  apt-get update -y && apt-get upgrade -y && apt-get dist-upgrade -y
  apt-get install -y \
    apt-utils \
    build-essential \
    dirmngr \
    git \
    imagemagick \
    libfribidi-dev \
    libharfbuzz-dev \
    pandoc \
    pandoc-citeproc \
    python-is-python3 \
    pkg-config \
    texlive \
    texlive-extra-utils \
    texlive-fonts-extra \
    texlive-latex-extra \
    texlive-pictures \
    texlive-pstricks \
    texlive-publishers \
    texlive-science \
    texlive-xetex \
    ca-certificates \
    gdebi-core \
    systemd \
    wget \

  # Add R repositories
  wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
  add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"

  apt update

# Install R and requirements
  apt-get install -y --no-install-recommends \
    ca-certificates \
    gdebi-core \
    hdf5-tools \
    libcairo2-dev \
    libcurl4-openssl-dev \
    libfontconfig-dev \
    libfreetype6-dev \
    libfribidi-bin \
    libfribidi-dev \
    libgit2-dev \
    libgsl27 \
    libgsl-dev \
    libharfbuzz-dev \
    libhdf5-dev \
    libjpeg-dev \
    libnetcdf-dev \
    libpng-dev \
    libssl-dev \
    libtiff5-dev \
    libxml2-dev \
    libxt-dev \
    netcdf-bin \
    patchelf \
    r-base=${R_VERSION}* \
    r-base-core=${R_VERSION}* \
    r-base-dev=${R_VERSION}* \
    r-recommended=${R_VERSION}* \
    r-base-html=${R_VERSION}* \
    r-doc-html=${R_VERSION}* \
    systemd \
    wget \

  apt-mark hold r-base*

  # Add a default CRAN mirror
  echo "options(repos = c(CRAN = 'https://cran.rstudio.com/'), download.file.method = 'libcurl')" >> /usr/lib/R/etc/Rprofile.site

  # Add a directory for host R libraries
  mkdir -p /library
  echo "R_LIBS_SITE=/library:\${R_LIBS_SITE}" >> /usr/lib/R/etc/Renviron.site

  cd /tmp
  wget https://download2.rstudio.org/server/jammy/amd64/rstudio-server-${RSTUDIO_VERSION}-amd64.deb
  gdebi -n rstudio-server-${RSTUDIO_VERSION}-amd64.deb
  rm rstudio-server-${RSTUDIO_VERSION}-amd64.deb

  # install a few basics
  Rscript -e 'install.packages(
    c(
      "circlize",
      "data.table",
      "devtools",
      "DBI",
      "gprofiler2",
      "mgcv",
      "nlme",
      "pacman",
      "rmarkdown",
      "Rcpp",
      "shiny",
      "tidyverse",
      "xtable"
    ), Ncpus=32)'
  Rscript -e 'update.packages(ask=FALSE)'
  Rscript -e 'devtools::install_github("hadley/devtools")'

  mkdir -p /var/run/rstudio-server
  chmod ugo+w /var/run/rstudio-server
  chmod +t /var/run/rstudio-server

  Rscript -e 'install.packages("BiocManager", Ncpus=32)'
  Rscript -e 'BiocManager::install(ask=FALSE, update=TRUE)'

  Rscript -e 'BiocManager::install(
    pkgs = c("DESeq2", "edgeR", "limma", "MethylSeekR", "methylKit", "bsseq"),
    dependencies = TRUE, Ncpus=32
  )'

  Rscript -e 'install.packages(
    pkgs = "bcbioRNASeq",
    repos = c(
        "https://r.acidgenomics.com",
        BiocManager::repositories()
    ),
    dependencies = TRUE, Ncpus=32
  )'

  Rscript -e 'install.packages(
    pkgs = "DESeqAnalysis",
    repos = c(
        "https://r.acidgenomics.com",
        BiocManager::repositories()
    ),
    dependencies = TRUE, Ncpus=32
  )'

  # Cleanup the container
  apt-get clean
  apt-get autoclean

%test
  R_VERSION=4.4.1
  R --version | grep -q "${R_VERSION}"
Download rstudio-rstudio_RStudio2023.06.1_R4.4.1.def
#!/bin/sh

  if [ -z "${RSTUDIO_PASSWORD}" ]; then
    export RSTUDIO_PASSWORD=$( tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1 )
    echo "The environment variable RSTUDIO_PASSWORD was not set, so your password has been chosen for you. It's: ${RSTUDIO_PASSWORD}"
  fi
  PORT=$( python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()' )
  HOST=$( /bin/hostname )
  echo "Running rserver on port ${PORT}"
  echo "To connect to this server run this on your local machine:"
  echo "    ssh -A ${USER}@${HOST} -o \"ProxyCommand=ssh ${USER}@slurm.ilifu.ac.za nc ${HOST} 22\" -L8081:localhost:${PORT}"
  echo "then visit http://localhost:8081 in your browser and use the username \"${USER}\" to login with the password \"${RSTUDIO_PASSWORD}\""
  echo "(You may need to choose a different port (other than 8081), so remember to change this in both the ssh and browser)"
  exec rserver --server-user ${USER} --auth-none 0 --auth-pam-helper rstudio_auth --secure-cookie-key-file ${HOME}/.RStudio.rserver/secure-cookie.key --www-port ${PORT} --server-data-dir ${HOME}/.RStudio.rserver/data "${@}"
#!/bin/sh

  R_VERSION=4.4.1
  R --version | grep -q "${R_VERSION}"
# /.singularity.d/env/90-environment.sh
#!/bin/sh
# Custom environment shell code should follow


  export INSTALLER_PATH=/installer
  export SOFTWARE_PATH=/software
  export PATH=${SOFTWARE_PATH}/bin:${PATH}
  export LC_ALL=C
  unset XDG_RUNTIME_DIR



  export INSTALLER_PATH=/installer
  export SOFTWARE_PATH=/software
  export PATH=${SOFTWARE_PATH}/bin:${PATH}
  export LD_LIBRARY_PATH=${SOFTWARE_PATH}/lib:${LD_LIBRARY_PATH}
  export LIBRARY_PATH=${SOFTWARE_PATH}/lib:${LIBRARY_PATH}
  export CPATH=${SOFTWARE_PATH}/include:${CPATH}
  export INCLUDE=${SOFTWARE_PATH}/include/:${INCLUDE}
  export PKG_CONFIG_PATH=${SOFTWARE_PATH}/lib/pkgconfig:${PKG_CONFIG_PATH}

  export LC_ALL=C
  unset XDG_RUNTIME_DIR



  export R_VERSION=4.4.1
  export RSTUDIO_VERSION=2023.06.1-524
  export PATH=/usr/lib/rstudio-server/bin:${PATH}

# Thanks to nickjer for this! https://github.com/nickjer/singularity-rstudio/blob/master/Singularity.3.6.0