From 2a32302666145c0c519fd8e747689c0bf7e205df Mon Sep 17 00:00:00 2001 From: Jakub Chrobasik Date: Tue, 9 Apr 2019 19:29:43 +0200 Subject: [PATCH] feat: added pre-stop pod lifecycle script --- docker/base/Dockerfile | 2 ++ docker/base/lifecycle/pre-stop.sh | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100755 docker/base/lifecycle/pre-stop.sh diff --git a/docker/base/Dockerfile b/docker/base/Dockerfile index 7b963516..0ea1856b 100644 --- a/docker/base/Dockerfile +++ b/docker/base/Dockerfile @@ -64,6 +64,8 @@ RUN pipx install ${RENKU_PIP_SPEC} --pip-args="--pre" renku && \ COPY git-config.bashrc /home/$NB_USER/ RUN cat /home/$NB_USER/git-config.bashrc >> /home/$NB_USER/.bashrc && rm /home/$NB_USER/git-config.bashrc +COPY lifecycle/ /usr/local/bin/ + # Add user `jovyan` to sudoers (passwordless) USER root RUN echo "$NB_USER ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && \ diff --git a/docker/base/lifecycle/pre-stop.sh b/docker/base/lifecycle/pre-stop.sh new file mode 100755 index 00000000..c188c343 --- /dev/null +++ b/docker/base/lifecycle/pre-stop.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +GIT_STATUS=`git status -s` +if [ -z "$GIT_STATUS" ] ; then + exit 0 +fi + +CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD` +CURRENT_SHA=`git rev-parse --short HEAD` +AUTOSAVE_BRANCH="renku/autosave/$JUPYTERHUB_USER/${CURRENT_BRANCH}/${CURRENT_SHA}" +git checkout -b "$AUTOSAVE_BRANCH" +git add . +git commit -am "Auto-saving for $JUPYTERHUB_USER on branch $CURRENT_BRANCH and commit $CURRENT_SHA" +git push origin "$AUTOSAVE_BRANCH" +git checkout master +git branch -D "$AUTOSAVE_BRANCH"