From 1dd8154b2c1c066e9aa37691ea6f03ae3e504300 Mon Sep 17 00:00:00 2001 From: Andreas Bleuler Date: Thu, 26 Aug 2021 20:59:35 +0200 Subject: [PATCH] feat: make images fully amalthea ready The goal of this is to move maintain as much of the current bahaviour with Amalthea-based sessions, while also keeping the images backwards compatible for now. --- docker/julia/post-init.sh | 11 +++++++++ docker/py/entrypoint.sh | 47 ++++++++++++++----------------------- docker/py/git-config.bashrc | 4 ++-- docker/r/post-init.sh | 31 +++++++++++++++++------- docker/vnc/post-init.sh | 9 ++++++- 5 files changed, 62 insertions(+), 40 deletions(-) diff --git a/docker/julia/post-init.sh b/docker/julia/post-init.sh index 36cd7af4..167ff354 100755 --- a/docker/julia/post-init.sh +++ b/docker/julia/post-init.sh @@ -2,6 +2,8 @@ # Slip in a replacement for the julia command that sets uses the project # environment rather than the root environment + +# Pre amalthea if [[ -v CI_PROJECT ]]; then ln -sf /work/${CI_PROJECT} ~/work @@ -9,3 +11,12 @@ then printf '/usr/local/bin/julia --project=/work/%s/ "$@"\n' ${CI_PROJECT} >> ~/.local/bin/julia chmod u+x ~/.local/bin/julia fi + +# With amalthea +if [[ -v PROJECT_NAME && -v NOTEBOOK_DIR ]]; +then + echo '#!/usr/bin/env bash' > ~/.local/bin/julia + printf '/usr/local/bin/julia --project=%s/ "$@"\n' ${NOTEBOOK_DIR} >> ~/.local/bin/julia + chmod u+x ~/.local/bin/julia +fi + diff --git a/docker/py/entrypoint.sh b/docker/py/entrypoint.sh index c63835a4..f5adddca 100755 --- a/docker/py/entrypoint.sh +++ b/docker/py/entrypoint.sh @@ -1,37 +1,26 @@ #!/bin/bash -# 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 - -# configure global git credentials -if [[ -v CI_PROJECT ]]; +if [[ -v GIT_AUTHOR_NAME && -v EMAIL && -v CI_PROJECT ]]; then - # set the global git credentials - git config --global credential.helper "store --file=/work/${CI_PROJECT}/.git/credentials" - - # link to the home work directory - ln -sf /work/${CI_PROJECT} ~/work + # 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 + + # configure global git credentials + if [[ -v CI_PROJECT ]]; + then + # set the global git credentials + git config --global credential.helper "store --file=/work/${CI_PROJECT}/.git/credentials" + + # link to the home work directory + ln -sf /work/${CI_PROJECT} ~/work + fi fi -# -# 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 ${GITLAB_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 - # install git hooks ~/.local/bin/renku githooks install || true diff --git a/docker/py/git-config.bashrc b/docker/py/git-config.bashrc index a92e0d74..9a571698 100644 --- a/docker/py/git-config.bashrc +++ b/docker/py/git-config.bashrc @@ -1,8 +1,8 @@ # Setup git user -if [ -z "$(git config --global --get user.name)" ]; then +if [[ -z "$(git config --global --get user.name)" && -v GIT_AUTHOR_NAME ]]; then git config --global user.name "$GIT_AUTHOR_NAME" fi -if [ -z "$(git config --global --get user.email)" ]; then +if [[ -z "$(git config --global --get user.email)" && -v EMAIL ]]; then git config --global user.email "$EMAIL" fi diff --git a/docker/r/post-init.sh b/docker/r/post-init.sh index 4c710e77..91a01f37 100755 --- a/docker/r/post-init.sh +++ b/docker/r/post-init.sh @@ -1,6 +1,9 @@ #!/bin/bash # Copy the relevant system environment variables to the R-specific locations +# Note: In the case of Amalthea-based sessions none of these env variables are +# defined and nothing will happen. This is ok as we can deal without global +# git config. VariableArray=("GIT_COMMITTER_NAME" "GIT_AUTHOR_NAME" "EMAIL") for var in ${VariableArray[*]}; do if [ -n "${!var}" ]; then @@ -8,13 +11,22 @@ for var in ${VariableArray[*]}; do fi done -# add a symlink to the project directory in /home/rstudio -[ -n "$CI_PROJECT" ] && ln -s /work/${CI_PROJECT} /home/rstudio +if [[ -v NOTEBOOK_DIR && -v PROJECT_NAME ]]; +then + RPROJ_FILE_PATH=${NOTEBOOK_DIR}/${PROJECT_NAME}.Rproj +fi +if [[ -v CI_PROJECT ]]; +then + # add a symlink to the project directory in /home/rstudio + [ -n "$CI_PROJECT" ] && ln -s /work/${CI_PROJECT} /home/rstudio + RPROJ_FILE_PATH=${HOME}/${CI_PROJECT}/${CI_PROJECT}.Rproj +fi # 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 +if [[ -v RPROJ_FILE_PATH && ( ! -f $RPROJ_FILE_PATH ) ]]; +then +cat > $RPROJ_FILE_PATH <<- EOF Version: 1.0 RestoreWorkspace: Default @@ -28,8 +40,11 @@ Encoding: UTF-8 RnwWeave: Sweave LaTeX: pdfLaTeX -EOM +EOF +fi + +mkdir -p ${HOME}/.rstudio/projects_settings +if [[ -v RPROJ_FILE_PATH ]]; +then + echo $RPROJ_FILE_PATH >> ${HOME}/.rstudio/projects_settings/next-session-project 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 diff --git a/docker/vnc/post-init.sh b/docker/vnc/post-init.sh index 68403ec8..3f219f6d 100644 --- a/docker/vnc/post-init.sh +++ b/docker/vnc/post-init.sh @@ -1,6 +1,13 @@ #!/bin/bash # Make the default terminal folder the project folder in the vnc -echo "cd /work/${CI_PROJECT}" >> ~/.bashrc +if [[ -v CI_PROJECT ]] +then + echo "cd /work/${CI_PROJECT}" >> ~/.bashrc +fi +if [[ -v NOTEBOOK_DIR ]] +then + echo "cd ${NOTEBOOK_DIR}" >> ~/.bashrc +fi # Turn the bell off echo "bind 'set bell-style none'" >> ~/.bashrc