Skip to content

Instantly share code, notes, and snippets.

@jtfogarty
Last active October 25, 2018 20:51
Show Gist options
  • Save jtfogarty/0d643119e98d44bb354d5443e00a12df to your computer and use it in GitHub Desktop.
Save jtfogarty/0d643119e98d44bb354d5443e00a12df to your computer and use it in GitHub Desktop.
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
FROM jupyter/scipy-notebook
LABEL maintainer="Jupyter Project <jupyter@googlegroups.com>"
# Set when building on Travis so that certain long-running build steps can
# be skipped to shorten build time.
ARG TEST_ONLY_BUILD
USER root
ENV NB_USER jovyan
ENV NB_UID 1000
ENV HOME /home/$NB_USER
# We prefer to have a global conda install
# to minimize the amount of content in $HOME
ENV CONDA_DIR=/opt/conda
ENV PATH $CONDA_DIR/bin:$PATH
# Use bash instead of sh
SHELL ["/bin/bash", "-c"]
# R pre-requisites
RUN apt-get update && \
apt-get install -y --no-install-recommends \
fonts-dejavu \
tzdata \
gfortran \
gcc && apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Julia dependencies
# install Julia packages in /opt/julia instead of $HOME
ENV JULIA_PKGDIR=/opt/julia
ENV JULIA_VERSION=1.0.1
#echo "bea4570d7358016d8ed29d2c15787dbefaea3e746c570763e7ad6040f17831f3 *julia-${JULIA_VERSION}-linux-x86_64.tar.gz" | sha256sum -c - && \
RUN mkdir /opt/julia-${JULIA_VERSION} && \
cd /tmp && \
wget -q https://julialang-s3.julialang.org/bin/linux/x64/`echo ${JULIA_VERSION} | cut -d. -f 1,2`/julia-${JULIA_VERSION}-linux-x86_64.tar.gz && \
echo "9ffbcf7f4a111e13415954caccdd1ce90b5c835cee9f62d6ac708f5b752c87dd *julia-${JULIA_VERSION}-linux-x86_64.tar.gz" | sha256sum -c - && \
tar xzf julia-${JULIA_VERSION}-linux-x86_64.tar.gz -C /opt/julia-${JULIA_VERSION} --strip-components=1 && \
rm /tmp/julia-${JULIA_VERSION}-linux-x86_64.tar.gz
RUN ln -fs /opt/julia-*/bin/julia /usr/local/bin/julia
# Show Julia where conda libraries are \
RUN mkdir /etc/julia && \
echo "push!(Libdl.DL_LOAD_PATH, \"$CONDA_DIR/lib\")" >> /etc/julia/juliarc.jl && \
# Create JULIA_PKGDIR \
mkdir $JULIA_PKGDIR && \
chown $NB_USER $JULIA_PKGDIR && \
fix-permissions $JULIA_PKGDIR
# R packages including IRKernel which gets installed globally.
RUN conda install --quiet --yes \
'rpy2=2.8*' \
'r-base=3.4.1' \
'r-irkernel=0.8*' \
'r-plyr=1.8*' \
'r-devtools=1.13*' \
'r-tidyverse=1.1*' \
'r-shiny=1.0*' \
'r-rmarkdown=1.8*' \
'r-forecast=8.2*' \
'r-rsqlite=2.0*' \
'r-reshape2=1.4*' \
'r-nycflights13=0.2*' \
'r-caret=6.0*' \
'r-rcurl=1.95*' \
'r-crayon=1.3*' \
'r-randomforest=4.6*' \
'r-htmltools=0.3*' \
'r-sparklyr=0.7*' \
'r-htmlwidgets=1.0*' \
'r-hexbin=1.27*' && \
conda clean -tipsy && \
fix-permissions $CONDA_DIR && \
fix-permissions /home/$NB_USER
# Add Julia packages. Only add HDF5 if this is not a test-only build since
# it takes roughly half the entire build time of all of the images on Travis
# to add this one package and often causes Travis to timeout.
#
# Install IJulia as jovyan and then move the kernelspec out
# to the system share location. Avoids problems with runtime UID change not
# taking effect properly on the .local folder in the jovyan home dir.
RUN julia -e 'import Pkg; Pkg.update()' && \
(test $TEST_ONLY_BUILD || julia -e 'import Pkg; Pkg.add("HDF5")') && \
julia -e 'import Pkg; Pkg.add("Gadfly")' && \
julia -e 'import Pkg; Pkg.add("RDatasets")' && \
julia -e 'import Pkg; Pkg.add("IJulia")' && \
# Precompile Julia packages \
julia -e 'using IJulia' && \
# move kernelspec out of home \
mv $HOME/.local/share/jupyter/kernels/julia* $CONDA_DIR/share/jupyter/kernels/ && \
chmod -R go+rx $CONDA_DIR/share/jupyter && \
rm -rf $HOME/.local && \
fix-permissions $JULIA_PKGDIR $CONDA_DIR/share/jupyter
ENV LC_ALL en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
# jovyan user exists
# $HOME provided by the contents of a PV
RUN chown -R ${NB_USER}:users /usr/local/bin && \
mkdir -p $HOME
# Install Tini - used as entrypoint for container
RUN cd /tmp && \
wget --quiet https://github.com/krallin/tini/releases/download/v0.10.0/tini && \
echo "1361527f39190a7338a0b434bd8c88ff7233ce7b9a4876f3315c22fce7eca1b0 *tini" | sha256sum -c - && \
mv tini /usr/local/bin/tini && \
chmod +x /usr/local/bin/tini
RUN chown -R ${NB_USER}:users $HOME
ENV GITHUB_REF https://raw.githubusercontent.com/kubeflow/kubeflow/master/components/tensorflow-notebook-image
ADD --chown=jovyan:users $GITHUB_REF/jupyter_notebook_config.py /tmp
# Wipe $HOME for PVC detection later
WORKDIR $HOME
RUN rm -fr $(ls -A $HOME)
# Get init scripts from kubeflow
ADD --chown=jovyan:users \
$GITHUB_REF/start-singleuser.sh \
$GITHUB_REF/start-notebook.sh \
$GITHUB_REF/start.sh \
$GITHUB_REF/pvc-check.sh \
/usr/local/bin/
RUN chmod a+rx /usr/local/bin/*
# Configure container startup
EXPOSE 8888
ENTRYPOINT ["tini", "--"]
CMD ["start-notebook.sh"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment