Skip to content

Commit

Permalink
Merge pull request #395 from eitsupi/refactoring/core-scripts
Browse files Browse the repository at this point in the history
Refactoring core Rocker scripts
  • Loading branch information
cboettig authored Apr 1, 2022
2 parents 98738ed + d968d4f commit 89d36d2
Show file tree
Hide file tree
Showing 20 changed files with 366 additions and 370 deletions.
33 changes: 17 additions & 16 deletions scripts/default_user.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
#!/bin/bash
set -e

if id -u "${user}" >/dev/null 2>&1; then
echo 'rstudio user already exists'
else
## Need to configure non-root user for RStudio
DEFAULT_USER=${1:-${DEFAULT_USER:-rstudio}}
useradd -s /bin/bash -m $DEFAULT_USER
echo "${DEFAULT_USER}:${DEFAULT_USER}" | chpasswd
addgroup ${DEFAULT_USER} staff
DEFAULT_USER=${1:-${DEFAULT_USER:-"rstudio"}}

mkdir -p /home/${DEFAULT_USER}/.rstudio/monitored/user-settings
echo "alwaysSaveHistory='0' \
\nloadRData='0' \
\nsaveAction='0'" \
> /home/${DEFAULT_USER}/.rstudio/monitored/user-settings/user-settings
if id -u "${DEFAULT_USER}" >/dev/null 2>&1; then
echo "User ${DEFAULT_USER} already exists"
else
## Need to configure non-root user for RStudio
useradd -s /bin/bash -m "$DEFAULT_USER"
echo "${DEFAULT_USER}:${DEFAULT_USER}" | chpasswd
addgroup "${DEFAULT_USER}" staff

chown -R "${DEFAULT_USER}:${DEFAULT_USER}" "/home/${DEFAULT_USER}"
## Rocker's default RStudio settings, for better reproducibility
mkdir -p "/home/${DEFAULT_USER}/.rstudio/monitored/user-settings"
cat <<EOF >"/home/${DEFAULT_USER}/.rstudio/monitored/user-settings/user-settings"
alwaysSaveHistory="0"
loadRData="0"
saveAction="0"
EOF
chown -R "${DEFAULT_USER}:${DEFAULT_USER}" "/home/${DEFAULT_USER}"
fi

# If shiny server installed, make the user part of the shiny group
if [ -x "$(command -v shiny-server)" ]; then
adduser ${DEFAULT_USER} shiny
adduser "${DEFAULT_USER}" shiny
fi

## configure git not to request password each time
git config --system credential.helper 'cache --timeout=3600'
git config --system push.default simple

9 changes: 4 additions & 5 deletions scripts/init_set_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

## Set our dynamic variables in Renviron.site to be reflected by RStudio Server or Shiny Server
exclude_vars="HOME PASSWORD RSTUDIO_VERSION BATCH_USER_CREATION"
for file in /var/run/s6/container_environment/*
do
sed -i "/^${file##*/}=/d" ${R_HOME}/etc/Renviron.site
regex="(^| )${file##*/}($| )"
[[ ! $exclude_vars =~ $regex ]] && echo "${file##*/}=$(cat $file)" >> ${R_HOME}/etc/Renviron.site || echo "skipping $file"
for file in /var/run/s6/container_environment/*; do
sed -i "/^${file##*/}=/d" "${R_HOME}/etc/Renviron.site"
regex="(^| )${file##*/}($| )"
[[ ! $exclude_vars =~ $regex ]] && echo "${file##*/}=$(cat "${file}")" >>"${R_HOME}/etc/Renviron.site" || echo "skipping ${file}"
done

## only file-owner (root) should read container_environment files:
Expand Down
87 changes: 34 additions & 53 deletions scripts/init_userconf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,14 @@ UMASK=${UMASK:=022}
LANG=${LANG:=en_US.UTF-8}
TZ=${TZ:=Etc/UTC}

bold=$(tput bold)
normal=$(tput sgr0)

if [[ ${DISABLE_AUTH,,} == "true" ]]

then
mv /etc/rstudio/disable_auth_rserver.conf /etc/rstudio/rserver.conf
echo "USER=$USER" >> /etc/environment
if [[ ${DISABLE_AUTH,,} == "true" ]]; then
mv /etc/rstudio/disable_auth_rserver.conf /etc/rstudio/rserver.conf
echo "USER=$USER" >>/etc/environment
fi

if grep --quiet "auth-none=1" /etc/rstudio/rserver.conf
then
echo "Skipping authentication as requested"
elif [ -z "$PASSWORD" ]
then
if grep --quiet "auth-none=1" /etc/rstudio/rserver.conf; then
echo "Skipping authentication as requested"
elif [ -z "$PASSWORD" ]; then
PASSWORD=$(pwgen 16 1)
printf "\n\n"
tput bold
Expand All @@ -36,76 +29,64 @@ then
printf "\n\n"
fi

if [ "$USERID" -lt 1000 ]
# Probably a macOS user, https://github.com/rocker-org/rocker/issues/205
then
if [ "$USERID" -lt 1000 ]; then # Probably a macOS user, https://github.com/rocker-org/rocker/issues/205
echo "$USERID is less than 1000"
check_user_id=$(grep -F "auth-minimum-user-id" /etc/rstudio/rserver.conf)
if [[ ! -z $check_user_id ]]
then
echo "minumum authorised user already exists in /etc/rstudio/rserver.conf: $check_user_id"
if [[ -n $check_user_id ]]; then
echo "minumum authorised user already exists in /etc/rstudio/rserver.conf: $check_user_id"
else
echo "setting minumum authorised user to 499"
echo auth-minimum-user-id=499 >> /etc/rstudio/rserver.conf
echo "setting minumum authorised user to 499"
echo auth-minimum-user-id=499 >>/etc/rstudio/rserver.conf
fi
fi

if [ "$USERID" -ne 1000 ]
## Configure user with a different USERID if requested.
then
if [ "$USERID" -ne 1000 ]; then ## Configure user with a different USERID if requested.
echo "deleting the default user"
userdel $DEFAULT_USER
userdel "$DEFAULT_USER"
echo "creating new $USER with UID $USERID"
useradd -m $USER -u $USERID
mkdir -p /home/$USER
chown -R $USER /home/$USER
usermod -a -G staff $USER
elif [ "$USER" != "$DEFAULT_USER" ]
then
useradd -m "$USER" -u $USERID
mkdir -p /home/"$USER"
chown -R "$USER" /home/"$USER"
usermod -a -G staff "$USER"
elif [ "$USER" != "$DEFAULT_USER" ]; then
## cannot move home folder when it's a shared volume, have to copy and change permissions instead
cp -r /home/$DEFAULT_USER /home/$USER
cp -r /home/"$DEFAULT_USER" /home/"$USER"
## RENAME the user
usermod -l $USER -d /home/$USER $DEFAULT_USER
groupmod -n $USER $DEFAULT_USER
usermod -a -G staff $USER
chown -R $USER:$USER /home/$USER
usermod -l "$USER" -d /home/"$USER" "$DEFAULT_USER"
groupmod -n "$USER" "$DEFAULT_USER"
usermod -a -G staff "$USER"
chown -R "$USER":"$USER" /home/"$USER"
echo "USER is now $USER"
fi

if [ "$GROUPID" -ne 1000 ]
## Configure the primary GID (whether rstudio or $USER) with a different GROUPID if requested.
then
echo "Modifying primary group $(id $USER -g -n)"
groupmod -g $GROUPID $(id $USER -g -n)
if [ "$GROUPID" -ne 1000 ]; then ## Configure the primary GID (whether rstudio or $USER) with a different GROUPID if requested.
echo "Modifying primary group $(id "${USER}" -g -n)"
groupmod -g $GROUPID "$(id "${USER}" -g -n)"
echo "Primary group ID is now custom_group $GROUPID"
fi

## Add a password to user
echo "$USER:$PASSWORD" | chpasswd

# Use Env flag to know if user should be added to sudoers
if [[ ${ROOT,,} == "true" ]]
then
adduser $USER sudo && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
if [[ ${ROOT,,} == "true" ]]; then
adduser "$USER" sudo && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >>/etc/sudoers
echo "$USER added to sudoers"
fi

## Change Umask value if desired
if [ "$UMASK" -ne 022 ]
then
echo "server-set-umask=false" >> /etc/rstudio/rserver.conf
echo "Sys.umask(mode=$UMASK)" >> /home/$USER/.Rprofile
if [ "$UMASK" -ne 022 ]; then
echo "server-set-umask=false" >>/etc/rstudio/rserver.conf
echo "Sys.umask(mode=$UMASK)" >>/home/"$USER"/.Rprofile
fi

## Next one for timezone setup
if [ "$TZ" != "Etc/UTC" ]
then
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
if [ "$TZ" != "Etc/UTC" ]; then
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ >/etc/timezone
fi

## Update Locale if needed
if [ "$LANG" != "en_US.UTF-8" ]
then
if [ "$LANG" != "en_US.UTF-8" ]; then
/usr/sbin/locale-gen --lang $LANG
/usr/sbin/update-locale --reset LANG=$LANG
fi
16 changes: 8 additions & 8 deletions scripts/install_binder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ DEFAULT_USER=${DEFAULT_USER:-rstudio}
NB_USER=${NB_USER:-${DEFAULT_USER}}
NB_UID=${NB_UID:-1000}
WORKDIR=${WORKDIR:-/home/${NB_USER}}
usermod -l ${NB_USER} ${DEFAULT_USER}
usermod -l "${NB_USER}" "${DEFAULT_USER}"
# Create a venv dir owned by unprivileged user & set up notebook in it
# This allows non-root to install python libraries if required
mkdir -p ${PYTHON_VENV_PATH} && chown -R ${NB_USER} ${PYTHON_VENV_PATH}
mkdir -p "${PYTHON_VENV_PATH}"
chown -R "${NB_USER}" "${PYTHON_VENV_PATH}"

# And set ENV for R! It doesn't read from the environment...
echo "PATH=${PATH}" >> ${R_HOME}/etc/Renviron.site
echo "export PATH=${PATH}" >> ${WORKDIR}/.profile
echo "PATH=${PATH}" >>"${R_HOME}/etc/Renviron.site"
echo "export PATH=${PATH}" >>"${WORKDIR}/.profile"

cd "${WORKDIR}"
## This gets run as user
su ${NB_USER}
cd ${WORKDIR}
python3 -m venv ${PYTHON_VENV_PATH}
pip3 install --no-cache-dir jupyter-rsession-proxy>=2.0 notebook jupyterlab
sudo -u "${NB_USER}" python3 -m venv "${PYTHON_VENV_PATH}"
pip3 install --no-cache-dir jupyter-rsession-proxy notebook jupyterlab >=2.0

R --quiet -e "devtools::install_github('IRkernel/IRkernel')"
R --quiet -e "IRkernel::installspec(prefix='${PYTHON_VENV_PATH}')"
88 changes: 42 additions & 46 deletions scripts/install_cuda-10.1.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
#!/bin/bash
set -e

apt-get update && apt-get install -y --no-install-recommends \
gnupg2 curl ca-certificates && \
curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub | apt-key add - && \
echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list && \
echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list && \
apt-get purge --autoremove -y curl && \
apt-get update
apt-get install -y --no-install-recommends \
gnupg2 curl ca-certificates
curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub | apt-key add -
echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" >/etc/apt/sources.list.d/cuda.list
echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" >/etc/apt/sources.list.d/nvidia-ml.list
apt-get purge --autoremove -y curl
rm -rf /var/lib/apt/lists/*

CUDA_VERSION=${CUDA_VERSION:-10.1.243}
CUDA_PKG_VERSION=${CUDA_PKG_VERSION:-10-1=$CUDA_VERSION-1}

# For libraries in the cuda-compat-* package: https://docs.nvidia.com/cuda/eula/index.html#attachment-a
apt-get update && apt-get install -y --no-install-recommends \
cuda-cudart-$CUDA_PKG_VERSION \
cuda-compat-10-1 && \
ln -s cuda-10.1 /usr/local/cuda && \
apt-get update
apt-get install -y --no-install-recommends \
"cuda-cudart-${CUDA_PKG_VERSION}" \
cuda-compat-10-1 &&
ln -s cuda-10.1 /usr/local/cuda &&
rm -rf /var/lib/apt/lists/*

# Required for nvidia-docker v1
echo "/usr/local/nvidia/lib" >> /etc/ld.so.conf.d/nvidia.conf && \
echo "/usr/local/nvidia/lib64" >> /etc/ld.so.conf.d/nvidia.conf

echo "/usr/local/nvidia/lib" >>/etc/ld.so.conf.d/nvidia.conf &&
echo "/usr/local/nvidia/lib64" >>/etc/ld.so.conf.d/nvidia.conf

## PATH & LD_LIBRARY_PATH are wrong?
PATH=${PATH:-/usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH}}
Expand All @@ -36,58 +37,53 @@ NVIDIA_REQUIRE_CUDA=${NVIDIA_REQUIRE_CUDA:-"cuda>=10.1 brand=tesla,driver>=384,d
## Tensorflow config for cuda runtime.
## Adapted from:

ARCH=
CUDA=10.1
CUDNN=7.6.4.38-1
CUDNN_MAJOR_VERSION=7
LIB_DIR_PREFIX=x86_64
LIBNVINFER=6.0.1-1
LIBNVINFER_MAJOR_VERSION=6

#SHELL ["/bin/bash", "-c"]
# Pick up some TF dependencies
# There appears to be a regression in libcublas10=10.2.2.89-1 which
# prevents cublas from initializing in TF. See
# https://github.com/tensorflow/tensorflow/issues/9489#issuecomment-562394257
apt-get update && apt-get install -y --no-install-recommends --allow-downgrades \
build-essential \
cuda-command-line-tools-10-1 \
libcublas10=10.2.1.243-1 \
cuda-nvrtc-10-1 \
cuda-cufft-10-1 \
cuda-curand-10-1 \
cuda-cusolver-10-1 \
cuda-cusparse-10-1 \
curl \
libcudnn7=${CUDNN}+cuda10.1 \
libfreetype6-dev \
libhdf5-serial-dev \
libzmq3-dev \
pkg-config \
software-properties-common \
unzip
# There appears to be a regression in libcublas10=10.2.2.89-1 which
# prevents cublas from initializing in TF. See
# https://github.com/tensorflow/tensorflow/issues/9489#issuecomment-562394257
apt-get update
apt-get install -y --no-install-recommends --allow-downgrades \
build-essential \
cuda-command-line-tools-10-1 \
libcublas10=10.2.1.243-1 \
cuda-nvrtc-10-1 \
cuda-cufft-10-1 \
cuda-curand-10-1 \
cuda-cusolver-10-1 \
cuda-cusparse-10-1 \
curl \
libcudnn7=${CUDNN}+cuda10.1 \
libfreetype6-dev \
libhdf5-serial-dev \
libzmq3-dev \
pkg-config \
software-properties-common \
unzip

# Install TensorRT if not building for PowerPC
apt-get update && \
apt-get install -y --no-install-recommends libnvinfer${LIBNVINFER_MAJOR_VERSION}=${LIBNVINFER}+cuda${CUDA} \
libnvinfer-plugin${LIBNVINFER_MAJOR_VERSION}=${LIBNVINFER}+cuda${CUDA} \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
apt-get update
apt-get install -y --no-install-recommends libnvinfer${LIBNVINFER_MAJOR_VERSION}=${LIBNVINFER}+cuda${CUDA} \
libnvinfer-plugin${LIBNVINFER_MAJOR_VERSION}=${LIBNVINFER}+cuda${CUDA}
apt-get clean
rm -rf /var/lib/apt/lists/*

# For CUDA profiling, TensorFlow requires CUPTI.
LD_LIBRARY_PATH==${LD_LIBRARY_PATH:-/usr/local/cuda/extras/CUPTI/lib64:/usr/local/cuda/lib64:$LD_LIBRARY_PATH}
LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-/usr/local/cuda/extras/CUPTI/lib64:/usr/local/cuda/lib64:$LD_LIBRARY_PATH}

# Link the libcuda stub to the location where tensorflow is searching for it and reconfigure
# dynamic linker run-time bindings
ln -s /usr/local/cuda/lib64/stubs/libcuda.so /usr/local/cuda/lib64/stubs/libcuda.so.1
echo "/usr/local/cuda/lib64/stubs" > /etc/ld.so.conf.d/z-cuda-stubs.conf
echo "/usr/local/cuda/lib64/stubs" >/etc/ld.so.conf.d/z-cuda-stubs.conf
ldconfig

## Add nvtop
#/rocker_scripts/install_nvtop.sh


## Add tensorflow-gpu==1.15 dependencies on the CUDA 10.0 libraries:
/rocker_scripts/install_tf1_cuda_10_0.sh


Loading

0 comments on commit 89d36d2

Please sign in to comment.