Skip to content

Commit

Permalink
feat: adding a bioconductor base (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmjab authored Feb 12, 2020
1 parent 5ba1677 commit 085b7e7
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# limitations under the License.

extensions = \
r \
r-bioconductor_3_10 r \
cuda-9.2 cuda-10.0-tensorflow-1.14

DOCKER_PREFIX?=renku/singleuser
Expand Down
2 changes: 1 addition & 1 deletion docker/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ RUN conda install gxx_linux-64
ENV RENKU_DISABLE_VERSION_CHECK 1

RUN python3 -m pip install pipx>=0.15.0.0
ARG RENKU_PIP_SPEC=""
ARG RENKU_PIP_SPEC="renku"
RUN pipx install ${RENKU_PIP_SPEC} --pip-args="--pre" && \
pipx inject renku sentry-sdk && \
pipx ensurepath
Expand Down
117 changes: 117 additions & 0 deletions docker/r-bioconductor_3_10/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
ARG RELEASE=RELEASE_3_10
FROM bioconductor/bioconductor_docker:${RELEASE}
LABEL maintainer="Swiss Data Science Center <[email protected]>"

USER root

ENV NB_USER rstudio
ENV NB_UID 1000
ENV NB_GID 1000
ENV VENV_DIR /srv/venv
ENV HOME /home/${NB_USER}
ENV SHELL bash
ENV CONDA_PATH /opt/conda

# prepend conda to PATH
ENV PATH ${CONDA_PATH}/bin:$PATH
# And set PATH for R! It doesn't read from the environment...
RUN echo "PATH=${PATH}" >> /usr/local/lib/R/etc/Renviron && \
echo "PATH=${PATH}" >> /etc/profile.d/set_path.sh

# The `rsession` binary that is called by nbrsessionproxy to start R doesn't seem to start
# without this being explicitly set
ENV LD_LIBRARY_PATH /usr/local/lib/R/lib

# Add Tini
ENV TINI_VERSION v0.18.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini

# install miniconda (https://github.com/ContinuumIO/docker-images/blob/master/miniconda3/debian/Dockerfile)
RUN apt-get update --fix-missing && \
apt-get install -yq --no-install-recommends \
bzip2 \
ca-certificates \
curl \
gnupg \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender1 \
wget \
vim && \
apt-get purge && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# install git-lfs
RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash && \
apt-get install git-lfs

WORKDIR /tmp
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-4.6.14-Linux-x86_64.sh -O ~/miniconda.sh && \
/bin/bash ~/miniconda.sh -b -p ${CONDA_PATH} && \
rm ~/miniconda.sh && \
${CONDA_PATH}/bin/conda clean -tipsy && \
ln -s ${CONDA_PATH}/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
${CONDA_PATH}/bin/conda config --system --append channels conda-forge && \
${CONDA_PATH}/bin/conda config --system --set auto_update_conda false && \
find ${CONDA_PATH}/ -follow -type f -name '*.a' -delete && \
find ${CONDA_PATH}/ -follow -type f -name '*.js.map' -delete && \
${CONDA_PATH}/bin/conda clean -afy

# set permissions in the conda directory to be editable by NB_USER
ADD fix-permissions.sh /usr/local/bin
RUN fix-permissions.sh ${CONDA_PATH}

USER ${NB_USER}

# set up conda in the NB_USER environment
RUN echo ". ${CONDA_PATH}/etc/profile.d/conda.sh" >> ~/.bashrc && \
echo "conda activate base" >> ~/.bashrc

# install the jupyter stack
ARG JUPYTERHUB_VERSION=0.9.6

RUN ${CONDA_PATH}/bin/conda install --quiet --yes \
'notebook=6.0.0' \
"jupyterhub=${JUPYTERHUB_VERSION}" \
'jupyterlab=1.2.1' && \
${CONDA_PATH}/bin/conda install -c conda-forge 'nodejs>=6.11.5' && \
${CONDA_PATH}/bin/conda install --quiet --yes conda-build && \
${CONDA_PATH}/bin/conda build purge-all && \
npm cache clean --force

RUN jupyter notebook --generate-config && \
rm -rf ${CONDA_PATH}/share/jupyter/lab/staging && \
rm -rf /home/$NB_USER/.cache/yarn && \
pip install -U --no-cache-dir pip wheel


# install jupyterlab, git extension
RUN python3 -m pip install -U pip && \
jupyter labextension update @jupyterlab/hub-extension --no-build && \
jupyter labextension install @jupyterlab/git --no-build && \
jupyter labextension list && \
pip install jupyter-rsession-proxy && \
pip install jupyterlab-git && \
jupyter serverextension enable --py jupyterlab_git && \
jupyter lab build

# install IRKernel
RUN R --quiet -e "install.packages('IRkernel')" && \
R --quiet -e "IRkernel::installspec(prefix='${CONDA_PATH}')"

# install renku
# the RENKU_PIP_SPEC should be e.g. "renku==0.5.2"
ARG RENKU_PIP_SPEC="renku"
RUN python3 -m pip install pipx>=0.15.0.0 && \
pipx install ${RENKU_PIP_SPEC} --pip-args="--pre" && \
pipx inject renku sentry-sdk && \
pipx ensurepath

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT [ "/tini", "--", "/entrypoint.sh" ]
CMD [ "jupyterhub-singleuser" ]

WORKDIR ${HOME}
60 changes: 60 additions & 0 deletions docker/r-bioconductor_3_10/LICENSE-fix-permissions
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Licensing terms

`fix-permissions.sh` is licensed under the terms of the Modified BSD License
(also known as New or Revised or 3-Clause BSD), as follows:

- Copyright (c) 2001-2015, IPython Development Team
- Copyright (c) 2015-, Jupyter Development Team

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

Neither the name of the Jupyter Development Team nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

## About the Jupyter Development Team

The Jupyter Development Team is the set of all contributors to the Jupyter project.
This includes all of the Jupyter subprojects.

The core team that coordinates development on GitHub can be found here:
https://github.com/jupyter/.

## Our Copyright Policy

Jupyter uses a shared copyright model. Each contributor maintains copyright
over their contributions to Jupyter. But, it is important to note that these
contributions are typically only changes to the repositories. Thus, the Jupyter
source code, in its entirety is not the copyright of any single person or
institution. Instead, it is the collective copyright of the entire Jupyter
Development Team. If individual contributors want to maintain a record of what
changes/contributions they have specific copyright on, they should indicate
their copyright in the commit message of the change, when they commit the
change to one of the Jupyter repositories.

With this in mind, the following banner should be used in any source code file
to indicate the copyright and license terms:

# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
59 changes: 59 additions & 0 deletions docker/r-bioconductor_3_10/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

# Copy the relevant system environment variables to the R-specific locations
VariableArray=("GIT_COMMITTER_NAME" "GIT_AUTHOR_NAME" "EMAIL")
for var in ${VariableArray[*]}; do
if [ -n "${!var}" ]; then
echo $var=${!var} >> ${HOME}/.Renviron
fi
done

# Setup git user
if [ -z "$(git config --global --get user.name)" ]; then
git config --global user.name "$GIT_AUTHOR_NAME"
fi
if [ -z "$(git config --global --get user.email)" ]; then
git config --global user.email "$EMAIL"
fi

# add a symlink to the project directory in /home/rstudio
[ -n "$CI_PROJECT" ] && ln -s /work/${CI_PROJECT} /home/rstudio

# configure rstudio to open the rpath project
if [[ ! -f /home/rstudio/${CI_PROJECT}/${CI_PROJECT}.Rproj ]]; then
cat > /home/rstudio/${CI_PROJECT}/${CI_PROJECT}.Rproj <<- EOM
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
EOM
fi
mkdir -p /home/rstudio/.rstudio/projects_settings
echo /home/rstudio/${CI_PROJECT}/${CI_PROJECT}.Rproj | tee /home/rstudio/.rstudio/projects_settings/next-session-project
chown -R rstudio:root /home/rstudio/.rstudio/projects_settings

#
# copy the environment from renku-env repo
#

# clone the repo
proto=$(echo $GITLAB_URL | sed -e's,^\(.*://\).*,\1,g')
url=$(echo ${GITLAB_URL/$proto/})
user=$(echo ${CI_REPOSITORY_URL/$proto/} | grep @ | cut -d@ -f1)

git clone --depth 1 ${proto}${user}@${url}/${JUPYTERHUB_USER}/renku-env.git /tmp/renku-env || true

# append the contents of all the files to same files in ${HOME}
find /tmp/renku-env -not -path '*.git*' -type f -print0 | xargs --null -I{} sh -c 'cat {} >> ${HOME}/$(basename "{}")' || true

# run the command
$@
35 changes: 35 additions & 0 deletions docker/r-bioconductor_3_10/fix-permissions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
# set permissions on a directory
# after any installation, if a directory needs to be (human) user-writable,
# run this script on it.
# It will make everything in the directory owned by the group $NB_GID
# and writable by that group.
# Deployments that want to set a specific user id can preserve permissions
# by adding the `--group-add users` line to `docker run`.

# uses find to avoid touching files that already have the right permissions,
# which would cause massive image explosion

# right permissions are:
# group=$NB_GID
# AND permissions include group rwX (directory-execute)
# AND directories have setuid,setgid bits set

set -e

for d in "$@"; do
find "$d" \
! \( \
-group $NB_GID \
-a -perm -g+rwX \
\) \
-exec chgrp $NB_GID {} \; \
-exec chmod g+rwX {} \;
# setuid,setgid *on directories only*
find "$d" \
\( \
-type d \
-a ! -perm -6000 \
\) \
-exec chmod +6000 {} \;
done
2 changes: 1 addition & 1 deletion docker/r/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ RUN R --quiet -e "install.packages('IRkernel')" && \

# install renku
# the RENKU_PIP_SPEC should be e.g. "renku==0.5.2"
ARG RENKU_PIP_SPEC=""
ARG RENKU_PIP_SPEC="renku"
RUN python3 -m pip install pipx>=0.15.0.0 && \
pipx install ${RENKU_PIP_SPEC} --pip-args="--pre" && \
pipx inject renku sentry-sdk && \
Expand Down
23 changes: 23 additions & 0 deletions docker/r/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ fi
# add a symlink to the project directory in /home/rstudio
[ -n "$CI_PROJECT" ] && ln -s /work/${CI_PROJECT} /home/rstudio


# configure rstudio to open the rpath project
if [[ ! -f /home/rstudio/${CI_PROJECT}/${CI_PROJECT}.Rproj ]]; then
cat > /home/rstudio/${CI_PROJECT}/${CI_PROJECT}.Rproj <<- EOM
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
EOM
fi
mkdir -p /home/rstudio/.rstudio/projects_settings
echo /home/rstudio/${CI_PROJECT}/${CI_PROJECT}.Rproj | tee /home/rstudio/.rstudio/projects_settings/next-session-project
chown -R rstudio:root /home/rstudio/.rstudio/projects_settings

#
# copy the environment from renku-env repo
#
Expand Down

0 comments on commit 085b7e7

Please sign in to comment.