diff --git a/ubuntu/10.0/Dockerfile b/ubuntu/10.0/Dockerfile new file mode 100644 index 0000000..daba156 --- /dev/null +++ b/ubuntu/10.0/Dockerfile @@ -0,0 +1,61 @@ +FROM nvidia/cuda:10.0-cudnn7-devel + +LABEL org.label-schema.license="GPL-2.0" \ + org.label-schema.vcs-url="https://github.com/rocker-org/rocker-versioned" \ + org.label-schema.vendor="Rocker Project" \ + maintainer="Carl Boettiger " + +ENV TERM=xterm + +## cuda:9.0 is xenial, cuda:10.0 is bionic +ARG UBUNTU_VERSION=bionic +ARG R_HOME=/usr/lib/R +ARG DEBIAN_FRONTEND=noninteractive + + +#ENV R_VERSION=${R_VERSION:-3.6.0} +ENV LC_ALL=en_US.UTF-8 +ENV LANG=en_US.UTF-8 +COPY install_R.sh /tmp/install_R.sh +RUN . /tmp/install_R.sh + + + +COPY install_rstudio.sh /tmp/install_rstudio.sh +#RUN . /tmp/install_rstudio.sh +COPY userconf.sh /etc/cont-init.d/userconf +EXPOSE 8787 +#CMD ["/init"] + + + +COPY install_tidyverse.sh /tmp/install_tidyverse.sh +#RUN . /tmp/install_tidyverse.sh + + + +COPY install_verse.sh /tmp/install_verse.sh +#RUN . /tmp/install_verse.sh + + + +## Use Configure CUDA for R, use NVidia libs for BLAS +ENV CUDA_HOME=/usr/local/cuda +ENV PATH=$PATH:$CUDA_HOME/bin +ENV LD_LIBRARY_PATH=$CUDA_HOME/lib64/libnvblas.so:$LD_LIBRARY_PATH:$CUDA_HOME/lib64:$CUDA_HOME/extras/CUPTI/lib64 +ENV NVBLAS_CONFIG_FILE=/etc/nvblas.conf +COPY config_R_cuda.sh /tmp/config_R_cuda.sh +RUN . /tmp/config_R_cuda.sh + + +ENV PYTHON_VENV_PATH=/opt/venv +ENV RETICULATE_PYTHON_ENV=$PYTHON_VENV_PATH +ENV PATH=${PYTHON_VENV_PATH}/bin:${PATH} +COPY install_python.sh /tmp/install_python.sh +RUN . /tmp/install_python.sh + + + +COPY install_tensorflow-gpu.sh /tmp/install_tensorflow-gpu.sh +#RUN . /tmp/install_tensorflow-gpu.sh + diff --git a/ubuntu/10.0/config_R_cuda.sh b/ubuntu/10.0/config_R_cuda.sh new file mode 100644 index 0000000..ebfd742 --- /dev/null +++ b/ubuntu/10.0/config_R_cuda.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +set -e + +## CUDA environmental variables configuration for RStudio + +## cli R inherits these, but RStudio needs to have these set in as follows: +## (From https://tensorflow.rstudio.com/tools/local_gpu.html#environment-variables) +echo "\n\ + \nCUDA_HOME=$CUDA_HOME\ + \nPATH=$PATH" >> ${R_HOME}/etc/Renviron + +if test -f /etc/rstudio/rserver.conf; then + echo "rsession-ld-library-path=$LD_LIBRARY_PATH" >> /etc/rstudio/rserver.conf +fi + +touch /var/log/nvblas.log && chown :staff /var/log/nvblas.log + +## Configure R & RStudio to use drop-in CUDA blas +## Allow R to use CUDA for BLAS, with fallback on openblas +echo "\nNVBLAS_LOGFILE /var/log/nvblas.log \ + \nNVBLAS_CPU_BLAS_LIB /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3 \ + \nNVBLAS_GPU_LIST ALL" > /etc/nvblas.conf + +echo "NVBLAS_CONFIG_FILE=$NVBLAS_CONFIG_FILE" >> ${R_HOME}/etc/Renviron + + +## We don't want to set LD_PRELOAD globally +##ENV LD_PRELOAD=/usr/local/cuda/lib64/libnvblas.so +# +### Instead, we will set it before calling R, Rscript, or RStudio: +#mv /usr/bin/R /usr/bin/R_ +#mv /usr/bin/Rscript /usr/bin/Rscript_ +# +#echo '\#!/bin/sh \ +# \n LD_PRELOAD=/usr/local/cuda/lib64/libnvblas.so /usr/bin/R_ "$@"' \ +# > /usr/bin/R && \ +# chmod +x /usr/bin/R && \ +# echo '#!/bin/sh \ +# \n LD_PRELOAD=/usr/local/cuda/lib64/libnvblas.so /usr/bin/Rscript_ "$@"' \ +# > /usr/bin/Rscript && \ +# chmod +x /usr/bin/Rscript +# +#echo '#!/usr/bin/with-contenv bash \ +# \n## load /etc/environment vars first: \ +# \n for line in \$( cat /etc/environment ) ; do export $line ; done \ +# \n export LD_PRELOAD=/usr/local/cuda/lib64/libnvblas.so \ +# \n exec /usr/lib/rstudio-server/bin/rserver --server-daemonize 0' \ +# > /etc/services.d/rstudio/run +# diff --git a/ubuntu/10.0/install_R.sh b/ubuntu/10.0/install_R.sh new file mode 100644 index 0000000..9fa2a50 --- /dev/null +++ b/ubuntu/10.0/install_R.sh @@ -0,0 +1,29 @@ +#!/bin/sh +set -e + +echo "deb https://cloud.r-project.org/bin/linux/ubuntu ${UBUNTU_VERSION}-cran35/" >> /etc/apt/sources.list && \ + gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 && \ + gpg -a --export E298A3A825C0D65DFD57CBB651716619E084DAB9 | apt-key add - && \ + apt-get update && \ + apt-get -y install --no-install-recommends \ + ca-certificates \ + less \ + littler \ + libopenblas-base \ + locales \ + r-base-dev \ + vim-tiny \ + wget && \ + rm -rf /var/lib/apt/lists/* + +echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && \ + locale-gen en_US.utf8 && \ + /usr/sbin/update-locale LANG=${LANG} + +Rscript -e "install.packages(c('littler', 'docopt'))" +ln -s /usr/lib/R/site-library/littler/examples/install.r /usr/local/bin/install.r \ + && ln -s /usr/lib/R/site-library/littler/examples/install2.r /usr/local/bin/install2.r \ + && ln -s /usr/lib/R/site-library/littler/examples/installGithub.r /usr/local/bin/installGithub.r \ + && ln -s /usr/local/lib/R/site-library/littler/bin/r /usr/local/bin/r + + diff --git a/ubuntu/10.0/install_nvtop.sh b/ubuntu/10.0/install_nvtop.sh new file mode 100644 index 0000000..67f174d --- /dev/null +++ b/ubuntu/10.0/install_nvtop.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e + +apt-get update && apt-get -y install cmake libncurses5-dev libncursesw5-dev git +git clone https://github.com/Syllo/nvtop.git +mkdir -p nvtop/build && cd nvtop/build +cmake .. -DNVML_RETRIEVE_HEADER_ONLINE=True +make +make install + diff --git a/ubuntu/10.0/install_python.sh b/ubuntu/10.0/install_python.sh new file mode 100644 index 0000000..c84123f --- /dev/null +++ b/ubuntu/10.0/install_python.sh @@ -0,0 +1,20 @@ +#/bin/sh +set -e + +apt-get update && apt-get install -y --no-install-recommends \ + libpython3-dev \ + python3-pip \ + python3-venv && \ + rm -rf /var/lib/apt/lists/* +python3 -m venv ${PYTHON_VENV_PATH} +pip3 install --no-cache-dir virtualenv + +## Ensure RStudio inherits this env var +echo "\nRETICULATE_PYTHON_ENV=${RETICULATE_PYTHON_ENV}" >> ${R_HOME}/etc/Renviron + +## symlink these because reticulate hardwires these PATHs... +ln -s ${PYTHON_VENV_PATH}/bin/pip /usr/local/bin/pip +ln -s ${PYTHON_VENV_PATH}/bin/virtualenv /usr/local/bin/virtualenv + +chown :staff ${PYTHON_VENV_PATH} + diff --git a/ubuntu/10.0/install_rstudio.sh b/ubuntu/10.0/install_rstudio.sh new file mode 100644 index 0000000..ff2d602 --- /dev/null +++ b/ubuntu/10.0/install_rstudio.sh @@ -0,0 +1,104 @@ +#!/bin/sh + +S6_VERSION=${S6_VERSION:-v1.21.7.0} +S6_BEHAVIOUR_IF_STAGE2_FAILS=2 +export PATH=/usr/lib/rstudio-server/bin:$PATH +PANDOC_TEMPLATES_VERSION=${PANDOC_TEMPLATES_VERSION:-2.6} + +## Download and install RStudio server & dependencies +## Attempts to get detect latest version, otherwise falls back to version given in $VER +## Symlink pandoc, pandoc-citeproc so they are available system-wide +apt-get update \ + && apt-get install -y --no-install-recommends \ + file \ + git \ + libapparmor1 \ + libcurl4-openssl-dev \ + libedit2 \ + libssl-dev \ + lsb-release \ + psmisc \ + procps \ + python-setuptools \ + sudo \ + wget \ + libclang-dev \ + libobjc-6-dev \ + libobjc4 \ + libgc1c2 \ + && rm -rf /var/lib/apt/lists/* + + +if [ -z "$RSTUDIO_VERSION" ]; + then RSTUDIO_URL="https://www.rstudio.org/download/latest/stable/server/${UBUNTU_VERSION}/rstudio-server-latest-amd64.deb"; + else RSTUDIO_URL="http://download2.rstudio.org/server/${UBUNTU_VERSION}/amd64/rstudio-server-${RSTUDIO_VERSION}-amd64.deb"; +fi +wget -q $RSTUDIO_URL \ + && dpkg -i rstudio-server-*-amd64.deb \ + && rm rstudio-server-*-amd64.deb + +## Symlink pandoc & standard pandoc templates for use system-wide +ln -s /usr/lib/rstudio-server/bin/pandoc/pandoc /usr/local/bin \ + && ln -s /usr/lib/rstudio-server/bin/pandoc/pandoc-citeproc /usr/local/bin \ + && git clone --recursive --branch ${PANDOC_TEMPLATES_VERSION} https://github.com/jgm/pandoc-templates \ + && mkdir -p /opt/pandoc/templates \ + && cp -r pandoc-templates*/* /opt/pandoc/templates && rm -rf pandoc-templates* \ + && mkdir /root/.pandoc && ln -s /opt/pandoc/templates /root/.pandoc/templates + + +## RStudio wants an /etc/R, will populate from $R_HOME/etc +mkdir -p /etc/R \ + && echo "\n\ + \n# Configure httr to perform out-of-band authentication if HTTR_LOCALHOST \ + \n# is not set since a redirect to localhost may not work depending upon \ + \n# where this Docker container is running. \ + \nif(is.na(Sys.getenv('HTTR_LOCALHOST', unset=NA))) { \ + \n options(httr_oob_default = TRUE) \ + \n}" >> ${R_HOME}/etc/Rprofile.site \ + && echo "PATH=${PATH}" >> ${R_HOME}/etc/Renviron + + +## Need to configure non-root user for RStudio +useradd rstudio \ + && echo "rstudio:rstudio" | chpasswd \ + && mkdir /home/rstudio \ + && chown rstudio:rstudio /home/rstudio \ + && addgroup rstudio staff + ## Prevent rstudio from deciding to use /usr/bin/R if a user apt-get installs a package + +R_BIN=`which R` +echo "rsession-which-r=${R_BIN}" >> /etc/rstudio/rserver.conf +## use more robust file locking to avoid errors when using shared volumes: +echo "lock-type=advisory" >> /etc/rstudio/file-locks + +## Optional configuration file to disable authentication +cp /etc/rstudio/rserver.conf /etc/rstudio/disable_auth_rserver.conf +echo "auth-none=1" >> /etc/rstudio/disable_auth_rserver.conf + +## configure git not to request password each time +git config --system credential.helper 'cache --timeout=3600' \ + && git config --system push.default simple + +## Set up S6 init system +wget -P /tmp/ https://github.com/just-containers/s6-overlay/releases/download/${S6_VERSION}/s6-overlay-amd64.tar.gz \ + && tar xzf /tmp/s6-overlay-amd64.tar.gz -C / \ + && mkdir -p /etc/services.d/rstudio \ + && echo "#!/usr/bin/with-contenv bash \ + \n## load /etc/environment vars first: \ + \n for line in $( cat /etc/environment ) ; do export $line > /dev/null; done \ + \n exec /usr/lib/rstudio-server/bin/rserver --server-daemonize 0" \ + > /etc/services.d/rstudio/run \ + && echo "#!/bin/bash \ + \n rstudio-server stop" \ + > /etc/services.d/rstudio/finish \ + && mkdir -p /home/rstudio/.rstudio/monitored/user-settings \ + && echo "alwaysSaveHistory='0' \ + \nloadRData='0' \ + \nsaveAction='0'" \ + > /home/rstudio/.rstudio/monitored/user-settings/user-settings \ + && chown -R rstudio:rstudio /home/rstudio/.rstudio + + +#COPY userconf.sh /etc/cont-init.d/userconf +# EXPOSE 8787 +# CMD ["/init"] diff --git a/ubuntu/10.0/install_tensorflow-gpu.sh b/ubuntu/10.0/install_tensorflow-gpu.sh new file mode 100644 index 0000000..123c274 --- /dev/null +++ b/ubuntu/10.0/install_tensorflow-gpu.sh @@ -0,0 +1,21 @@ +#!/bin/sh +set -e + +apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + curl \ + libfreetype6-dev \ + libhdf5-serial-dev \ + libzmq3-dev \ + pkg-config \ + software-properties-common \ + unzip + +## FIXME set versions Consider renv +#R -e "renv::restore()" +pip3 install --no-cache-dir tensorflow-gpu tensorflow-probability keras h5py pyyaml requests Pillow +chown -R rstudio:rstudio ${PYTHON_VENV_PATH} + +R -e "install.packages('keras')" +R -e "install.packages('remotes'); remotes::install_github('greta-dev/greta')" + diff --git a/ubuntu/10.0/install_tidyverse.sh b/ubuntu/10.0/install_tidyverse.sh new file mode 100644 index 0000000..49bce4e --- /dev/null +++ b/ubuntu/10.0/install_tidyverse.sh @@ -0,0 +1,26 @@ +#!/bin/sh +set -e + +apt-get update -qq && apt-get -y --no-install-recommends install \ + libxml2-dev \ + libcairo2-dev \ + libsqlite3-dev \ + libmariadbd-dev \ + libmariadb-client-lgpl-dev \ + libpq-dev \ + libssh2-1-dev \ + unixodbc-dev \ + libsasl2-dev && \ + rm -rf /var/lib/apt/lists/* + +install2.r --error \ + --deps TRUE \ + tidyverse \ + dplyr \ + devtools \ + formatR \ + remotes \ + selectr \ + caTools \ + BiocManager + diff --git a/ubuntu/10.0/install_verse.sh b/ubuntu/10.0/install_verse.sh new file mode 100644 index 0000000..5e520b5 --- /dev/null +++ b/ubuntu/10.0/install_verse.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +set -e + +export PATH=$PATH:/opt/TinyTeX/bin/x86_64-linux/ + +## Add LaTeX, rticles and bookdown support +wget "https://travis-bin.yihui.name/texlive-local.deb" \ + && dpkg -i texlive-local.deb \ + && rm texlive-local.deb \ + && apt-get update \ + && apt-get install -y --no-install-recommends \ + cmake \ + default-jdk \ + fonts-roboto \ + ghostscript \ + libbz2-dev \ + libicu-dev \ + liblzma-dev \ + libhunspell-dev \ + libmagick++-dev \ + librdf0-dev \ + libv8-dev \ + qpdf \ + texinfo \ + ssh \ + less \ + vim \ + libzmq3-dev \ + libopenmpi-dev \ + && rm -rf /var/lib/apt/lists/* + +install2.r --error tinytex + +## Admin-based install of TinyTeX: +wget -qO- \ + "https://github.com/yihui/tinytex/raw/master/tools/install-unx.sh" | \ + sh -s - --admin --no-path \ + && mv ~/.TinyTeX /opt/TinyTeX \ + && /opt/TinyTeX/bin/*/tlmgr path add \ + && tlmgr install metafont mfware inconsolata tex ae parskip listings \ + && tlmgr path add \ + && Rscript -e "tinytex::r_texmf()" \ + && chown -R root:staff /opt/TinyTeX \ + && chown -R root:staff ${R_HOME}/site-library \ + && chmod -R g+w /opt/TinyTeX \ + && chmod -R g+wx /opt/TinyTeX/bin \ + && echo "PATH=${PATH}" >> ${R_HOME}/etc/Renviron + + +install2.r --error --deps TRUE \ + bookdown rticles rmdshower rJava + + diff --git a/ubuntu/10.0/source_R.sh b/ubuntu/10.0/source_R.sh new file mode 100644 index 0000000..d5bfa88 --- /dev/null +++ b/ubuntu/10.0/source_R.sh @@ -0,0 +1,124 @@ +apt-get update \ + && apt-get install -y --no-install-recommends \ + bash-completion \ + ca-certificates \ + file \ + fonts-texgyre \ + g++ \ + gfortran \ + gsfonts \ + libblas-dev \ + libbz2-1.0 \ + libcurl3 \ + libicu57 \ + libjpeg62-turbo \ + libopenblas-dev \ + libpangocairo-1.0-0 \ + libpcre3 \ + libpng16-16 \ + libreadline7 \ + libtiff5 \ + liblzma5 \ + locales \ + make \ + unzip \ + zip \ + zlib1g \ + && echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \ + && locale-gen en_US.utf8 \ + && /usr/sbin/update-locale LANG=en_US.UTF-8 \ + && BUILDDEPS="curl \ + default-jdk \ + libbz2-dev \ + libcairo2-dev \ + libcurl4-openssl-dev \ + libpango1.0-dev \ + libjpeg-dev \ + libicu-dev \ + libpcre3-dev \ + libpng-dev \ + libreadline-dev \ + libtiff5-dev \ + liblzma-dev \ + libx11-dev \ + libxt-dev \ + perl \ + tcl8.6-dev \ + tk8.6-dev \ + texinfo \ + texlive-extra-utils \ + texlive-fonts-recommended \ + texlive-fonts-extra \ + texlive-latex-recommended \ + x11proto-core-dev \ + xauth \ + xfonts-base \ + xvfb \ + zlib1g-dev" + +apt-get install -y --no-install-recommends $BUILDDEPS + +cd tmp/ \ + && curl -O https://cran.r-project.org/src/base/R-3/R-${R_VERSION}.tar.gz \ + && tar -xf R-${R_VERSION}.tar.gz \ + && cd R-${R_VERSION} \ + && R_PAPERSIZE=letter \ + R_BATCHSAVE="--no-save --no-restore" \ + R_BROWSER=xdg-open \ + PAGER=/usr/bin/pager \ + PERL=/usr/bin/perl \ + R_UNZIPCMD=/usr/bin/unzip \ + R_ZIPCMD=/usr/bin/zip \ + R_PRINTCMD=/usr/bin/lpr \ + LIBnn=lib \ + AWK=/usr/bin/awk \ + CFLAGS="-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g" \ + CXXFLAGS="-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g" \ + ./configure --enable-R-shlib \ + --enable-memory-profiling \ + --with-readline \ + --with-blas \ + --with-tcltk \ + --disable-nls \ + --with-recommended-packages \ + && make \ + && make install + +## Add a default CRAN mirror +# && echo "options(repos = c(CRAN = 'https://cran.rstudio.com/'), download.file.method = 'libcurl')" >> /usr/local/lib/R/etc/Rprofile.site \ + + +## Add a library directory (for user-installed packages) +mkdir -p /usr/local/lib/R/site-library \ + && chown root:staff /usr/local/lib/R/site-library \ + && chmod g+wx /usr/local/lib/R/site-library \ + +## Fix library path + echo "R_LIBS_USER='/usr/local/lib/R/site-library'" >> /usr/local/lib/R/etc/Renviron \ + && echo "R_LIBS=\${R_LIBS-'/usr/local/lib/R/site-library:/usr/local/lib/R/library:/usr/lib/R/library'}" >> /usr/local/lib/R/etc/Renviron + + +## install packages from date-locked MRAN snapshot of CRAN + [ -z "$BUILD_DATE" ] && BUILD_DATE=$(TZ="America/Los_Angeles" date -I) || true \ + && MRAN=https://mran.microsoft.com/snapshot/${BUILD_DATE} \ + && echo MRAN=$MRAN >> /etc/environment \ + && export MRAN=$MRAN \ + && echo "options(repos = c(CRAN='$MRAN'), download.file.method = 'libcurl')" >> /usr/local/lib/R/etc/Rprofile.site + +## Use littler installation scripts +Rscript -e "install.packages(c('littler', 'docopt'), repo = '$MRAN')" \ + && ln -s /usr/local/lib/R/site-library/littler/examples/install2.r /usr/local/bin/install2.r \ + && ln -s /usr/local/lib/R/site-library/littler/examples/installGithub.r /usr/local/bin/installGithub.r \ + && ln -s /usr/local/lib/R/site-library/littler/bin/r /usr/local/bin/r + + +## Clean up from R source install +cd / \ + && rm -rf /tmp/* \ + && apt-get remove --purge -y $BUILDDEPS \ + && apt-get autoremove -y \ + && apt-get autoclean -y \ + && rm -rf /var/lib/apt/lists/* + +#CMD ["R"] + diff --git a/ubuntu/10.0/userconf.sh b/ubuntu/10.0/userconf.sh new file mode 100644 index 0000000..d74a2f4 --- /dev/null +++ b/ubuntu/10.0/userconf.sh @@ -0,0 +1,103 @@ +#!/usr/bin/with-contenv bash + +## Set defaults for environmental variables in case they are undefined +USER=${USER:=rstudio} +PASSWORD=${PASSWORD:=rstudio} +USERID=${USERID:=1000} +GROUPID=${GROUPID:=1000} +ROOT=${ROOT:=FALSE} +UMASK=${UMASK:=022} + +## Make sure RStudio inherits the full path +echo "PATH=${PATH}" >> ${R_HOME}/etc/Renviron + +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 +fi + + + +if grep --quiet "auth-none=1" /etc/rstudio/rserver.conf +then + echo "Skipping authentication as requested" +elif [ "$PASSWORD" == "rstudio" ] +then + printf "\n\n" + tput bold + printf "\e[31mERROR\e[39m: You must set a unique PASSWORD (not 'rstudio') first! e.g. run with:\n" + printf "docker run -e PASSWORD=\e[92m\e[39m -p 8787:8787 rocker/rstudio\n" + tput sgr0 + printf "\n\n" + exit 1 +fi + +if [ "$USERID" -lt 1000 ] +# Probably a macOS user, https://github.com/rocker-org/rocker/issues/205 + then + 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" + else + 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 + echo "deleting user rstudio" + userdel rstudio + echo "creating new $USER with UID $USERID" + useradd -m $USER -u $USERID + mkdir /home/$USER + chown -R $USER /home/$USER + usermod -a -G staff $USER +elif [ "$USER" != "rstudio" ] + then + ## cannot move home folder when it's a shared volume, have to copy and change permissions instead + cp -r /home/rstudio /home/$USER + ## RENAME the user + usermod -l $USER -d /home/$USER rstudio + groupmod -n $USER rstudio + 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) + 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 + 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 +fi + +## add these to the global environment so they are avialable to the RStudio user +echo "HTTR_LOCALHOST=$HTTR_LOCALHOST" >> /etc/R/Renviron.site +echo "HTTR_PORT=$HTTR_PORT" >> /etc/R/Renviron.site diff --git a/ubuntu/9.0/Dockerfile b/ubuntu/9.0/Dockerfile new file mode 100644 index 0000000..39d6bc6 --- /dev/null +++ b/ubuntu/9.0/Dockerfile @@ -0,0 +1,47 @@ +FROM nvidia/cuda:9.0-cudnn7-devel + +## cuda:9.0 is xenial, cuda:10.0 is bionic +ARG UBUNTU_VERSION=xenial +ARG R_HOME=/usr/lib/R +ARG DEBIAN_FRONTEND=noninteractive + + +ENV LC_ALL=en_US.UTF-8 +ENV LANG=en_US.UTF-8 +COPY install_R.sh /tmp/install_R.sh +RUN . /tmp/install_R.sh + + + +COPY install_rstudio.sh /tmp/install_rstudio.sh +RUN . /tmp/install_rstudio.sh +COPY userconf.sh /etc/cont-init.d/userconf +EXPOSE 8787 +CMD ["/init"] + + + +# CUDA environmental variables for R & RSTUDIO +## FROM https://tensorflow.rstudio.com/tools/local_gpu.html#environment-variables +ENV CUDA_HOME=/usr/local/cuda +ENV PATH=$PATH:$CUDA_HOME/bin +ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDA_HOME/lib64:$CUDA_HOME/extras/CUPTI/lib64 +RUN echo "\n\ + \nCUDA_HOME=$CUDA_HOME\ + \nPATH=$PATH" >> ${R_HOME}/etc/Renviron +RUN echo "rsession-ld-library-path=$LD_LIBRARY_PATH" >> /etc/rstudio/rserver.conf + + + +ENV PYTHON_VENV_PATH=/opt/venv +ENV RETICULATE_PYTHON_ENV=$PYTHON_VENV_PATH +ENV PATH=${PYTHON_VENV_PATH}/bin:${PATH} +COPY install_python.sh /tmp/install_python.sh +RUN . /tmp/install_python.sh + + + +COPY install_tensorflow-gpu.sh /tmp/install_tensorflow-gpu.sh +RUN . /tmp/install_tensorflow-gpu.sh + + diff --git a/ubuntu/9.0/install_R.sh b/ubuntu/9.0/install_R.sh new file mode 100644 index 0000000..76559c8 --- /dev/null +++ b/ubuntu/9.0/install_R.sh @@ -0,0 +1,28 @@ +#!/bin/sh +set -e + +echo "deb https://cloud.r-project.org/bin/linux/ubuntu ${UBUNTU_VERSION}-cran35/" >> /etc/apt/sources.list && \ + gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 && \ + gpg -a --export E298A3A825C0D65DFD57CBB651716619E084DAB9 | apt-key add - && \ + apt-get update && \ + apt-get -y install --no-install-recommends \ + ca-certificates \ + less \ + libopenblas-base \ + locales \ + r-base-dev \ + vim-tiny \ + wget && \ + rm -rf /var/lib/apt/lists/* + +echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && \ + locale-gen en_US.utf8 && \ + /usr/sbin/update-locale LANG=${LANG} + +## littler configuration +Rscript -e "install.packages(c('littler', 'docopt'))" +ln -s /usr/lib/R/site-library/littler/examples/install.r /usr/local/bin/install.r \ + && ln -s /usr/lib/R/site-library/littler/examples/install2.r /usr/local/bin/install2.r \ + && ln -s /usr/lib/R/site-library/littler/examples/installGithub.r /usr/local/bin/installGithub.r \ + && ln -s /usr/local/lib/R/site-library/littler/bin/r /usr/local/bin/r + diff --git a/ubuntu/9.0/install_python.sh b/ubuntu/9.0/install_python.sh new file mode 100644 index 0000000..937d757 --- /dev/null +++ b/ubuntu/9.0/install_python.sh @@ -0,0 +1,19 @@ +#/bin/sh +set -e + +apt-get update && apt-get install -y --no-install-recommends \ + libpython3-dev \ + python3-pip \ + python3-venv && \ + rm -rf /var/lib/apt/lists/* +python3 -m venv ${PYTHON_VENV_PATH} +pip3 install --no-cache-dir virtualenv + +## Ensure RStudio inherits this env var +echo "\nRETICULATE_PYTHON_ENV=${RETICULATE_PYTHON_ENV}" >> ${R_HOME}/etc/Renviron + +## symlink these because reticulate hardwires these PATHs... +ln -s ${PYTHON_VENV_PATH}/bin/pip /usr/local/bin/pip +ln -s ${PYTHON_VENV_PATH}/bin/virtualenv /usr/local/bin/virtualenv +chown -R rstudio:rstudio ${PYTHON_VENV_PATH} + diff --git a/ubuntu/9.0/install_rstudio.sh b/ubuntu/9.0/install_rstudio.sh new file mode 100644 index 0000000..a818a60 --- /dev/null +++ b/ubuntu/9.0/install_rstudio.sh @@ -0,0 +1,104 @@ +#!/bin/sh +set -e + +RSTUDIO_VERSION=1.2.1335 +S6_VERSION=${S6_VERSION:-v1.21.7.0} +S6_BEHAVIOUR_IF_STAGE2_FAILS=2 +PANDOC_TEMPLATES_VERSION=${PANDOC_TEMPLATES_VERSION:-2.6} +export PATH=/usr/lib/rstudio-server/bin:$PATH + + +## Download and install RStudio server & dependencies +## Attempts to get detect latest version, otherwise falls back to version given in $VER +## Symlink pandoc, pandoc-citeproc so they are available system-wide +apt-get update \ + && apt-get install -y --no-install-recommends \ + file \ + git \ + libapparmor1 \ + libcurl4-openssl-dev \ + libedit2 \ + libssl-dev \ + lsb-release \ + psmisc \ + procps \ + python-setuptools \ + sudo \ + wget \ + libclang-dev \ + libobjc-5-dev \ + libgc1c2 \ + && rm -rf /var/lib/apt/lists/* + +## NOTE: xenial also uses 'trusty' URL here for latest version. +RSTUDIO_URL="https://download2.rstudio.org/server/trusty/amd64/rstudio-server-${RSTUDIO_VERSION}-amd64.deb" + +wget -q $RSTUDIO_URL \ + && dpkg -i rstudio-server-*-amd64.deb \ + && rm rstudio-server-*-amd64.deb + +## Symlink pandoc & standard pandoc templates for use system-wide +ln -s /usr/lib/rstudio-server/bin/pandoc/pandoc /usr/local/bin \ + && ln -s /usr/lib/rstudio-server/bin/pandoc/pandoc-citeproc /usr/local/bin \ + && git clone --recursive --branch ${PANDOC_TEMPLATES_VERSION} https://github.com/jgm/pandoc-templates \ + && mkdir -p /opt/pandoc/templates \ + && cp -r pandoc-templates*/* /opt/pandoc/templates && rm -rf pandoc-templates* \ + && mkdir /root/.pandoc && ln -s /opt/pandoc/templates /root/.pandoc/templates + + +## RStudio wants an /etc/R, will populate from $R_HOME/etc +mkdir -p /etc/R \ + && echo "\n\ + \n# Configure httr to perform out-of-band authentication if HTTR_LOCALHOST \ + \n# is not set since a redirect to localhost may not work depending upon \ + \n# where this Docker container is running. \ + \nif(is.na(Sys.getenv('HTTR_LOCALHOST', unset=NA))) { \ + \n options(httr_oob_default = TRUE) \ + \n}" >> ${R_HOME}/etc/Rprofile.site \ + && echo "PATH=${PATH}" >> ${R_HOME}/etc/Renviron + + +## Need to configure non-root user for RStudio +useradd rstudio \ + && echo "rstudio:rstudio" | chpasswd \ + && mkdir /home/rstudio \ + && chown rstudio:rstudio /home/rstudio \ + && addgroup rstudio staff + ## Prevent rstudio from deciding to use /usr/bin/R if a user apt-get installs a package + +R_BIN=`which R` +echo "rsession-which-r=${R_BIN}" >> /etc/rstudio/rserver.conf +## use more robust file locking to avoid errors when using shared volumes: +echo "lock-type=advisory" >> /etc/rstudio/file-locks + +## Optional configuration file to disable authentication +cp /etc/rstudio/rserver.conf /etc/rstudio/disable_auth_rserver.conf +echo "auth-none=1" >> /etc/rstudio/disable_auth_rserver.conf + +## configure git not to request password each time +git config --system credential.helper 'cache --timeout=3600' \ + && git config --system push.default simple + +## Set up S6 init system +wget -P /tmp/ https://github.com/just-containers/s6-overlay/releases/download/${S6_VERSION}/s6-overlay-amd64.tar.gz \ + && tar xzf /tmp/s6-overlay-amd64.tar.gz -C / \ + && mkdir -p /etc/services.d/rstudio \ + && echo "#!/usr/bin/with-contenv bash \ + \n## load /etc/environment vars first: \ + \n for line in $( cat /etc/environment ) ; do export $line > /dev/null; done \ + \n exec /usr/lib/rstudio-server/bin/rserver --server-daemonize 0" \ + > /etc/services.d/rstudio/run \ + && echo "#!/bin/bash \ + \n rstudio-server stop" \ + > /etc/services.d/rstudio/finish \ + && mkdir -p /home/rstudio/.rstudio/monitored/user-settings \ + && echo "alwaysSaveHistory='0' \ + \nloadRData='0' \ + \nsaveAction='0'" \ + > /home/rstudio/.rstudio/monitored/user-settings/user-settings \ + && chown -R rstudio:rstudio /home/rstudio/.rstudio + + +#COPY userconf.sh /etc/cont-init.d/userconf +# EXPOSE 8787 +# CMD ["/init"] diff --git a/ubuntu/9.0/install_tensorflow-gpu.sh b/ubuntu/9.0/install_tensorflow-gpu.sh new file mode 100644 index 0000000..26af2a6 --- /dev/null +++ b/ubuntu/9.0/install_tensorflow-gpu.sh @@ -0,0 +1,22 @@ +#!/bin/sh +set -e + +apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + curl \ + libfreetype6-dev \ + libhdf5-serial-dev \ + libzmq3-dev \ + pkg-config \ + software-properties-common \ + unzip + + +## FIXME set versions Consider renv +#R -e "renv::restore()" +pip3 install --no-cache-dir tensorflow-gpu==1.12.0 tensorflow-probability==0.5.0 +chown -R rstudio:rstudio ${PYTHON_VENV_PATH} + +## greta==0.3.0 +R -e "install.packages(c('keras', 'greta'))" + diff --git a/ubuntu/9.0/userconf.sh b/ubuntu/9.0/userconf.sh new file mode 100644 index 0000000..d74a2f4 --- /dev/null +++ b/ubuntu/9.0/userconf.sh @@ -0,0 +1,103 @@ +#!/usr/bin/with-contenv bash + +## Set defaults for environmental variables in case they are undefined +USER=${USER:=rstudio} +PASSWORD=${PASSWORD:=rstudio} +USERID=${USERID:=1000} +GROUPID=${GROUPID:=1000} +ROOT=${ROOT:=FALSE} +UMASK=${UMASK:=022} + +## Make sure RStudio inherits the full path +echo "PATH=${PATH}" >> ${R_HOME}/etc/Renviron + +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 +fi + + + +if grep --quiet "auth-none=1" /etc/rstudio/rserver.conf +then + echo "Skipping authentication as requested" +elif [ "$PASSWORD" == "rstudio" ] +then + printf "\n\n" + tput bold + printf "\e[31mERROR\e[39m: You must set a unique PASSWORD (not 'rstudio') first! e.g. run with:\n" + printf "docker run -e PASSWORD=\e[92m\e[39m -p 8787:8787 rocker/rstudio\n" + tput sgr0 + printf "\n\n" + exit 1 +fi + +if [ "$USERID" -lt 1000 ] +# Probably a macOS user, https://github.com/rocker-org/rocker/issues/205 + then + 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" + else + 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 + echo "deleting user rstudio" + userdel rstudio + echo "creating new $USER with UID $USERID" + useradd -m $USER -u $USERID + mkdir /home/$USER + chown -R $USER /home/$USER + usermod -a -G staff $USER +elif [ "$USER" != "rstudio" ] + then + ## cannot move home folder when it's a shared volume, have to copy and change permissions instead + cp -r /home/rstudio /home/$USER + ## RENAME the user + usermod -l $USER -d /home/$USER rstudio + groupmod -n $USER rstudio + 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) + 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 + 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 +fi + +## add these to the global environment so they are avialable to the RStudio user +echo "HTTR_LOCALHOST=$HTTR_LOCALHOST" >> /etc/R/Renviron.site +echo "HTTR_PORT=$HTTR_PORT" >> /etc/R/Renviron.site diff --git a/ubuntu/Makefile b/ubuntu/Makefile new file mode 100644 index 0000000..90fda63 --- /dev/null +++ b/ubuntu/Makefile @@ -0,0 +1,10 @@ +all: + make cuda-9.0 + make cuda-10.0 + +cuda-10.0: 10.0/Dockerfile + docker build -t rocker/cuda-10.0 10.0 +cuda-9.0: 9.0/Dockerfile + docker build -t rocker/cuda-9.0 9.0 + + diff --git a/ubuntu/README.md b/ubuntu/README.md new file mode 100644 index 0000000..fe907f4 --- /dev/null +++ b/ubuntu/README.md @@ -0,0 +1,24 @@ +## Developer notes + + +- CUDA 9.0 is built on ubuntu:16.04, with tensorflow 1.12.0 +- CUDA 10.0 is built on ubuntu:18.04 with tensorflow 1.13.1 + + +Note that one cannot easily mix and match versions of CUDA, tensorflow, and the R packages. Pre-compiled tensorflow binaries work only with CUDA 9.0 and 10.0. + +For example, the current dev version of `greta` (0.3.0.9002) needs `tensorflow-gpu==1.13.1`, CUDA 10.0 (and probably python 3.6). More recent or older versions will likely break things. The current stable version, (0.3.0) cannot run in this environment, and needs CUDA 9.0 and tensorflow==`1.12.0`. + + +## Managing the Python Virtualenv + +Currently, we set global env var `PYTHON_RETICULATE_ENV`, which forces `reticulate` and friends to use the virtualenv we set up at that location (`opt/venv`). This may make it dificult to provide alternative venvs (since running `Sys.unsetenv()` from the R console is not sufficient). + +Setting `WORKON_HOME` is more flexible, e.g.: + +``` +ENV WORKON_HOME /opt/virtualenvs +ENV PYTHON_VENV_PATH $WORKON_HOME/r-tensorflow +``` + +which allows `reticulate` to still find `python` in the venv out-of-the-box, but can create additional virtualenvs in `WORKON_HOME` (users should be given write permissions to this).