Skip to content

Commit

Permalink
feat: make images fully amalthea ready
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Andreas Bleuler authored and ableuler committed Sep 1, 2021
1 parent bcd1484 commit 1dd8154
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 40 deletions.
11 changes: 11 additions & 0 deletions docker/julia/post-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@

# 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
echo '#!/usr/bin/env bash' > ~/.local/bin/julia
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

47 changes: 18 additions & 29 deletions docker/py/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions docker/py/git-config.bashrc
Original file line number Diff line number Diff line change
@@ -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
31 changes: 23 additions & 8 deletions docker/r/post-init.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
#!/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
echo $var=${!var} >> ${HOME}/.Renviron
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
Expand All @@ -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
9 changes: 8 additions & 1 deletion docker/vnc/post-init.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1dd8154

Please sign in to comment.