From bad4f6860891898f2d7697ab49edeba9184920be Mon Sep 17 00:00:00 2001 From: Graham Dumpleton Date: Sun, 18 Feb 2018 20:58:32 +1100 Subject: [PATCH] Add example Source-to-Image scripts for building custom notebook images. --- examples/source-to-image/assemble | 37 +++++++++++++++++++++++++++++++ examples/source-to-image/run | 5 +++++ 2 files changed, 42 insertions(+) create mode 100755 examples/source-to-image/assemble create mode 100755 examples/source-to-image/run diff --git a/examples/source-to-image/assemble b/examples/source-to-image/assemble new file mode 100755 index 00000000..f3484bfe --- /dev/null +++ b/examples/source-to-image/assemble @@ -0,0 +1,37 @@ +#!/bin/bash + +set -eo pipefail + +# Copy injected files to correct place in 'work' directory. + +cp -Rf /tmp/src/. /home/$NB_USER/work + +rm -rf /tmp/src + +# Install any Python modules. If we find an 'environment.yml' file we +# assume we should use 'conda' to install packages. If 'requirements.txt' +# use 'pip' instead. Ensure we are in the 'work' directory so relative +# directory paths in these files resolve okay if installing packages +# from subdirectories. + +if [ -f /home/$NB_USER/work/environment.yml ]; then + (cd /home/$NB_USER/work && conda env update --name root --file environment.yml) + conda clean -tipsy +else + if [ -f /home/$NB_USER/work/requirements.txt ]; then + (cd /home/$NB_USER/work && pip --no-cache-dir install -r requirements.txt) + fi +fi + +# Remove any 'environment.yml' or 'requirements.txt' file when done in +# case we are producing an image which will in turn be used as an S2I +# builder image. + +rm -f /home/$NB_USER/work/environment.yml +rm -f /home/$NB_USER/work/requirements.txt + +# Fix up permissions on home directory and Python installation so that +# everything is still writable by 'users' group. + +fix-permissions $CONDA_DIR +fix-permissions /home/$NB_USER diff --git a/examples/source-to-image/run b/examples/source-to-image/run new file mode 100755 index 00000000..b5b641b8 --- /dev/null +++ b/examples/source-to-image/run @@ -0,0 +1,5 @@ +#!/bin/bash + +# Start up the notebook instance. + +exec start-notebook.sh "$@"