-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michael Rade
committed
Sep 3, 2023
1 parent
0bcb086
commit 707d86f
Showing
5 changed files
with
298 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
## Singularity RStudio Server | ||
|
||
Image based on the Ubuntu 20.04 (R 4.2.2), see `./singularity/rstudio_server/recipe-4-2-2.def` for details | ||
|
||
### First step (get the image) | ||
|
||
Download the image at <https://cloud.sylabs.io/library/michael.rade/r-world/rstudio-server> or pull it: | ||
|
||
``` sh | ||
$ singularity pull --arch amd64 library://michael.rade/r-world/rstudio-server:1.0.0 | ||
``` | ||
|
||
### Second step (config and run) | ||
|
||
The following adjustments must be made in the `run.sh` file: | ||
|
||
- Set a port (variable `RSTUDIO_PORT`) | ||
- Set a path for the log files (variable `TMPDIR`) | ||
- The variable `RSTUDIO_PASSWORD` can be set to a password of your choice. Default is "password" | ||
- For parameter `auth-pam-helper` and `rsession-config-file` in run.sh: Set path to this folder. | ||
|
||
Furthermore, set your R library path in `./singularity/rsession.conf`. I recommend to create a new folder. It can lead to conflicts when folders with libraries of another R version are used. | ||
|
||
Now run the following : | ||
|
||
``` sh | ||
$ bash run.sh run rstudio-server:1.0.0.sif | ||
``` | ||
|
||
You can reach RStudio Server via your webbrowser (e.g. `localhost:8072/auth-sign-in`). Use the port that you have specified in the variable `RSTUDIO_PORT`. You can log in with your current user name and password you set in `RSTUDIO_PASSWORD`. | ||
|
||
### Notes | ||
|
||
You can also work on the command line | ||
|
||
``` sh | ||
# If you need to bind something that is not your user's home directory | ||
$ export SINGULARITY_BINDPATH="/mnt/example/" | ||
# Define path to R libraries | ||
$ export R_LIBS_USER="/home//michael.rade/R/x86_64-pc-linux-gnu-library/4.0.2.RStudioServer/" | ||
|
||
$ singularity shell rstudio-server:1.0.0.sif | ||
$ R | ||
``` | ||
|
||
You can build this singularity image with: | ||
|
||
``` sh | ||
$ sudo singularity build rstudio-server:1.0.0.sif recipe-4-2-2.def | ||
``` | ||
|
||
You can put more parameter to run.sh. To see all possible parameter use: | ||
|
||
``` sh | ||
$ singularity run --app rserver rstudio-server_1.0.0.sif --help | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
Bootstrap: docker | ||
From: ubuntu:20.04 | ||
|
||
%labels | ||
Maintainer Michael Rade | ||
R_Version 4.2.2 | ||
RStudio_Version 2021.09.2-382 | ||
|
||
%runscript | ||
exec rserver "${@}" | ||
|
||
%apprun rserver | ||
exec rserver "${@}" | ||
|
||
%environment | ||
export PATH=/usr/lib/rstudio-server/bin:${PATH} | ||
|
||
%setup | ||
install -Dv \ | ||
rstudio_auth.sh \ | ||
${SINGULARITY_ROOTFS}/usr/lib/rstudio-server/bin/rstudio_auth | ||
|
||
%post | ||
# Software versions | ||
export R_VERSION=4.2.2 | ||
export RSTUDIO_VERSION=2021.09.2-382 | ||
|
||
# Get dependencies | ||
apt-get update | ||
apt-get install -y --no-install-recommends \ | ||
locales \ | ||
wget | ||
|
||
# Get fonts | ||
apt-get update | ||
echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections | ||
apt-get install -y ubuntu-restricted-extras | ||
|
||
# Configure default locale | ||
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen | ||
locale-gen en_US.utf8 | ||
/usr/sbin/update-locale LANG=en_US.UTF-8 | ||
export LC_ALL=en_US.UTF-8 | ||
export LANG=en_US.UTF-8 | ||
|
||
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb | ||
apt install -y ./google-chrome-stable_current_amd64.deb | ||
|
||
# Get dependencies | ||
apt-get update | ||
apt-get install -y software-properties-common | ||
# add-apt-repository ppa:ubuntugis/ubuntugis-unstable | ||
# apt-get update | ||
apt-get install -y --no-install-recommends \ | ||
libpoppler-cpp-dev \ | ||
libgfortran4 \ | ||
libopenblas-dev \ | ||
libstdc++6 \ | ||
git \ | ||
libgit2-dev \ | ||
libpango1.0-dev \ | ||
libblas3 \ | ||
libblas-dev \ | ||
liblapack-dev \ | ||
liblapack3 \ | ||
curl \ | ||
gcc \ | ||
fort77 \ | ||
aptitude \ | ||
g++ \ | ||
xorg-dev \ | ||
libreadline-dev \ | ||
gfortran \ | ||
libcurl4-openssl-dev \ | ||
libssl-dev \ | ||
libxml2-dev \ | ||
libcairo2-dev \ | ||
libxt-dev \ | ||
libbz2-dev \ | ||
liblzma-dev \ | ||
ca-certificates \ | ||
gdebi-core \ | ||
zlib1g-dev \ | ||
r-cran-rjags \ | ||
imagemagick \ | ||
libmagick++-dev \ | ||
rng-tools \ | ||
libtool \ | ||
libgmp-dev \ | ||
libmpfr-dev \ | ||
build-essential \ | ||
libboost-all-dev \ | ||
libssh2-1-dev \ | ||
htop \ | ||
less \ | ||
r-cran-rjava \ | ||
bedtools \ | ||
libx11-dev \ | ||
mesa-common-dev \ | ||
libglu1-mesa-dev \ | ||
libpcre2-dev \ | ||
libpcre3-dev \ | ||
libudunits2-dev \ | ||
libv8-dev \ | ||
gdal-bin \ | ||
libgdal-dev \ | ||
libproj-dev \ | ||
libfftw3-dev \ | ||
libgsl-dev \ | ||
libsodium-dev \ | ||
cmake | ||
|
||
apt-get install -y `apt-get --assume-no install texlive-full | \ | ||
awk '/The following additional packages will be installed/{f=1;next} /Suggested packages/{f=0} f' | \ | ||
tr ' ' '\n' | \ | ||
grep -vP 'doc$' | \ | ||
grep -vP 'texlive-lang' | \ | ||
grep -vP 'latex-cjk' | \ | ||
tr '\n' ' '` | ||
|
||
apt-get install -y --no-install-recommends \ | ||
texlive-lang-german | ||
|
||
cd $HOME | ||
wget http://www.fftw.org/fftw-3.3.10.tar.gz --no-check-certificate | ||
tar xvf fftw-3.3.10.tar.gz | ||
cd fftw-3.3.10 | ||
./configure | ||
make | ||
make install | ||
|
||
cd $HOME | ||
wget https://github.com/KlugerLab/FIt-SNE/archive/refs/heads/master.zip --no-check-certificate | ||
unzip master.zip | ||
cd FIt-SNE-master | ||
g++ -std=c++11 -O3 src/sptree.cpp src/tsne.cpp src/nbodyfft.cpp -o /bin/fast_tsne -pthread -lfftw3 -lm -Wno-address-of-packed-member | ||
|
||
NPROCS=$((`grep -E "^processor" /proc/cpuinfo |tail -1 |awk '{print $3}'` + 1)) | ||
cd $HOME | ||
wget https://cran.rstudio.com/src/base/R-4/R-${R_VERSION}.tar.gz --no-check-certificate | ||
tar xvf R-${R_VERSION}.tar.gz | ||
cd R-${R_VERSION} | ||
|
||
./configure --enable-R-shlib=yes | ||
echo "Will use make with $NPROCS cores." | ||
make -j${NPROCS} | ||
make install | ||
R --version | ||
|
||
wget \ | ||
--no-verbose \ | ||
--no-check-certificate \ | ||
-O rstudio-server.deb \ | ||
"https://download2.rstudio.org/server/bionic/amd64/rstudio-server-${RSTUDIO_VERSION}-amd64.deb" | ||
gdebi -n rstudio-server.deb | ||
rm -f rstudio-server.deb | ||
|
||
cd $HOME | ||
wget --no-verbose https://download3.rstudio.org/ubuntu-14.04/x86_64/VERSION -O "version.txt" && \ | ||
VERSION=$(cat version.txt) && \ | ||
wget --no-verbose "https://download3.rstudio.org/ubuntu-14.04/x86_64/shiny-server-$VERSION-amd64.deb" -O ss-latest.deb && \ | ||
gdebi -n ss-latest.deb && \ | ||
rm -f version.txt ss-latest.deb && \ | ||
. /etc/environment && \ | ||
chown shiny:shiny /var/lib/shiny-server | ||
mkdir -p /var/log/shiny-server | ||
chown shiny.shiny /var/log/shiny-server | ||
|
||
# Clean up | ||
rm -rf /var/lib/apt/lists/* | ||
# Remove shared semaphore workaround for miniconda | ||
if [ -f /rm_run_shm ]; then | ||
rm /run/shm; | ||
rm /rm_run_shm | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
r-libs-user=~/R/x86_64-pc-linux-gnu-library/4.2.2.RStudioServer | ||
session-timeout-minutes=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Confirm username is supplied | ||
if [[ $# -lt 1 ]]; then | ||
echo "Usage: auth USERNAME" | ||
exit 1 | ||
fi | ||
USERNAME="${1}" | ||
|
||
# Confirm password environment variable exists | ||
if [[ -z "${RSTUDIO_PASSWORD}" ]]; then | ||
echo "The environment variable RSTUDIO_PASSWORD is not set" | ||
exit 1 | ||
fi | ||
|
||
# Read in the password from user | ||
read -s -p "Password: " PASSWORD | ||
echo "" | ||
|
||
# Authenticate user | ||
if [[ "${USER}" == "${USERNAME}" && "${PASSWORD}" == "${RSTUDIO_PASSWORD}" ]]; then | ||
echo "Successful authentication" | ||
exit 0 | ||
else | ||
echo "Invalid authentication" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/sh | ||
|
||
module load Singularity | ||
# or install singularity: https://docs.sylabs.io/guides/latest/user-guide/quick_start.html | ||
|
||
# You can remove the following line if there is nothing to bind | ||
export SINGULARITY_BINDPATH="/mnt/metadata/,/mnt/workdata/" | ||
|
||
# Define your port | ||
export RSTUDIO_PORT=8072 | ||
|
||
# we don't want to clutter the cluster directories, so each user sets up his own | ||
# rstudio-server-tmp for now | ||
export TMPDIR="/homes/olymp/$USER/RStudio-Server-Files/" | ||
|
||
echo "Path where RStudio Server will write run-time state, logs, etc.:" | ||
echo $TMPDIR | ||
|
||
mkdir -p "$TMPDIR/tmp/rstudio-server" | ||
uuidgen > "$TMPDIR/tmp/rstudio-server/secure-cookie-key" | ||
# the secure cookie should of course only be accessible by the owner | ||
chmod 0600 "$TMPDIR/tmp/rstudio-server/secure-cookie-key" | ||
|
||
mkdir -p "$TMPDIR/var/lib" | ||
mkdir -p "$TMPDIR/var/run" | ||
|
||
RSTUDIO_PASSWORD="password" singularity "$1" \ | ||
--bind="$TMPDIR/var/lib:/var/lib/rstudio-server" \ | ||
--bind="$TMPDIR/var/run:/var/run/rstudio-server" \ | ||
--bind="$TMPDIR/tmp:/tmp" \ | ||
"$2" \ | ||
--server-user $USER \ | ||
--www-port $RSTUDIO_PORT \ | ||
--auth-none 0 \ | ||
--auth-pam-helper ~/projects/example/singularity/rstudio_server/rstudio_auth.sh \ | ||
--rsession-config-file ~/projects/example/singularity/rstudio_server/rsession.conf \ | ||
--auth-timeout-minutes=0 \ | ||
--auth-stay-signed-in-days=7 |