From 886b97e56be9c5fbde0f356d5afd31d149b26d74 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Sun, 9 May 2021 05:59:41 +0200
Subject: [PATCH] Fix directory ownership/access for user using Jupyter

---
 docker-compose/jupyter/Dockerfile | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/docker-compose/jupyter/Dockerfile b/docker-compose/jupyter/Dockerfile
index da3f1da1c..62fb73951 100644
--- a/docker-compose/jupyter/Dockerfile
+++ b/docker-compose/jupyter/Dockerfile
@@ -1,6 +1,10 @@
 ARG VERSION=latest
 FROM nexus.engageska-portugal.pt/ska-docker/tango-itango:${VERSION}
 
+# UID if the user that this container will run under. This is needed to give directories
+# that are needed for temporary storage the proper owner and access rights.
+ARG CONTAINER_EXECUTION_UID=1000
+
 RUN sudo pip3 install jupyter
 RUN sudo pip3 install ipykernel
 RUN sudo pip3 install jupyter_bokeh
@@ -13,7 +17,6 @@ RUN sudo jupyter nbextension enable jupyter_bokeh --py --sys-prefix
 
 # Install profiles for ipython & jupyter
 COPY ipython-profiles /opt/ipython-profiles/
-RUN sudo chmod a+rw -R /opt/ipython-profiles
 COPY jupyter-kernels /usr/local/share/jupyter/kernels/
 
 # Install patched jupyter executable
@@ -28,5 +31,6 @@ RUN sudo chmod +x /usr/bin/tini
 
 # Make sure Jupyter can write to the home directory
 ENV HOME=/home/user
-RUN sudo mkdir -p $HOME
-RUN sudo chmod a+rwx $HOME
+RUN sudo mkdir -p ${HOME}
+RUN sudo chown ${CONTAINER_EXECUTION_UID} -R ${HOME}
+RUN sudo chown ${CONTAINER_EXECUTION_UID} -R /opt/ipython-profiles
-- 
GitLab