From b2a4c0ec516e0d7fdfcdecc34a237ea3359fec95 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Fri, 1 Apr 2022 23:45:43 +0200 Subject: [PATCH] Initial support to workspace mount. --- 06-fuse-logback.xml | 24 ++++++++++++++++++++++++ 06_workspace_mount.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 11 ++++++++--- 3 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 06-fuse-logback.xml create mode 100644 06_workspace_mount.sh diff --git a/06-fuse-logback.xml b/06-fuse-logback.xml new file mode 100644 index 0000000..dd761e2 --- /dev/null +++ b/06-fuse-logback.xml @@ -0,0 +1,24 @@ + + + + /var/log/workspace-lib/fuse-workspace.log + true + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n + + + + ./var/log/workspace-lib/fuse-workspace.log%d{yyyy-MM-dd}.log + 30 + 10MB + 100MB + + + + + + + + + + diff --git a/06_workspace_mount.sh b/06_workspace_mount.sh new file mode 100644 index 0000000..c112ba9 --- /dev/null +++ b/06_workspace_mount.sh @@ -0,0 +1,43 @@ +#!/usr/bin/with-contenv bash + +echo "Manage the user's workspace" +workspace_dir='/workspace' +workspace_logdir='/var/log/workspace-lib' +workspace_libdir='/opt/workspace-lib' +workspace_fuse_jar="$workspace_libdir/fuse-workspace.jar" + +_decode_base64_url() { + local len=$((${#1} % 4)) + local result="$1" + if [ $len -eq 2 ]; then result="$1"'==' + elif [ $len -eq 3 ]; then result="$1"'=' + fi + echo "$result" | tr '_-' '/+' | base64 -d +} + +# $1 => JWT to decode +# $2 => either 1 for header or 2 for body (default is 2) +decode_jwt() { _decode_base64_url $(echo -n $1 | cut -d "." -f ${2:-2}) | jq .; } + + +[[ ! -d "$workspace_dir" ]] || [[ -z `ls -A "$workspace_dir"` ]] || mv $workspace_dir ${workspace_dir}.old + +mkdir -p $workspace_dir +chown ${USER}:${USER} $workspace_dir +chown -R ${USER}:${USER} $workspace_logdir + +_retval= +/bin/rm /home/${USER}/workspace +_retval=$? +if [ $_retval -ne 0 ]; then + echo "The user has a directory named 'workspace' inside their home directory" + echo "Not starting the workspace mount" + exit +else + ln -s /home/${USER}/workspace $workspace_dir +fi + +echo "Mount the workspace" +su - "$USER" -c "/usr/bin/java -cp .:${workspace_dir}:${workspace_logdir}/ -Dlogback.configurationFile=${workspace_logdir}/logback.xml -jar $workspace_fuse_jar $SHINYPROXY_OIDC_ACCESS_TOKEN $workspace_dir" >/dev/null 2>&1 & + +exit ?$ diff --git a/Dockerfile b/Dockerfile index 1082088..dc1460b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,12 +12,10 @@ ENV DEFAULT_USER=rstudio ENV PANDOC_VERSION=default ENV PATH=/usr/lib/rstudio-server/bin:$PATH - RUN /rocker_scripts/install_rstudio.sh RUN /rocker_scripts/install_pandoc.sh -# Add the mountpoint for the workspace -RUN mkdir /workspace +RUN apt-get update && apt-get install -y fuse zip jq # This part comes from https://github.com/openanalytics/shinyproxy-rstudio-ide-demo/blob/master/Dockerfile RUN echo "www-frame-origin=same" >> /etc/rstudio/disable_auth_rserver.conf @@ -32,6 +30,13 @@ ADD 03_setup_root_path.sh /etc/cont-init.d/03_setup_root_path #ADD 04_copy_env.sh /etc/cont-init.d/04_copy_env ADD 05_setup_rsession_parameters.sh /etc/cont-init.d/05_setup_rsession_parameters +# Prepare the workspace environment +RUN mkdir -p /opt/workspace-lib +RUN mkdir /var/log/workspace-lib +ADD https://maven.d4science.org/nexus/content/repositories/gcube-snapshots/org/gcube/data-access/sh-fuse-integration/2.0.0-SNAPSHOT/sh-fuse-integration-2.0.0-20211005.090627-1-jar-with-dependencies.jar /workspace-lib/fuse-workspace.jar +ADD 06_workspace_mount.sh /etc/cont-init.d/06_workspace_mount +ADD 06-fuse-logback.xml /workspace-lib/logback.xml + EXPOSE 8787 CMD ["/init"] -- 2.17.1