another try

This commit is contained in:
Jan Kieseler
2024-07-24 10:23:58 +02:00
parent f1635306a0
commit ee622c57ba
3 changed files with 51 additions and 7 deletions
+15 -5
View File
@@ -78,7 +78,7 @@ RUN python3 -m pip install ipython
RUN apt-get install -y tk # for dawn
# add jupyter packages for UC2 on top so they don't need to be installed every time
RUN python3 -m pip install jupyterlab jupyterhub==3.1.1 batchspawner
RUN python3 -m pip install jupyterlab jupyterhub==4.1.5 batchspawner
RUN ln -s /usr/bin/python3 /usr/bin/python
@@ -98,19 +98,29 @@ RUN cd /root/minicalosim && git checkout $COMMIT && \
cp minicalo* ../bind/G4Calo.py /usr/local/lib/python3.8/dist-packages/
CMD ["start-notebook.py"]
RUN cp /root/minicalosim/docker/start-notebook.py /usr/local/bin/
RUN cp /root/minicalosim/docker/start-notebook.sh /usr/local/bin/
RUN cp /root/minicalosim/docker/start-singleuser.py /usr/local/bin/
RUN cp /root/minicalosim/docker/start-singleuser.sh /usr/local/bin/
RUN cp /root/minicalosim/docker/fix-permissions /usr/local/bin/
#USER root
##RUN fix-permissions /etc/jupyter/
ARG NB_USER="jovyan"
ARG NB_UID="1000"
ARG NB_GID="100"
USER root
#RUN groupadd -g ${NB_GID} ${NB_USER} && \
RUN useradd -m -s /bin/bash -N -u ${NB_UID} -g ${NB_GID} ${NB_USER}
RUN mkdir /etc/jupyter
RUN fix-permissions /etc/jupyter/
# clean up
RUN rm -rf /root/minicalosim
#USER ${NB_UID}
USER ${NB_UID}
CMD ["start-notebook.sh"]
+4
View File
@@ -67,3 +67,7 @@ echo "Current working directory: $(pwd)"
docker build $FORCE_NO_CACHE -t jkiesele/minicalosim:$COMMIT --build-arg USER=$USER --build-arg BUILD_DATE="$(date)" --build-arg COMMIT=$COMMIT -f minicalosim/docker/Dockerfile .
echo "sucessfully built container jkiesele/minicalosim:${COMMIT}"
docker tag jkiesele/minicalosim:$COMMIT jkiesele/minicalosim:latest
echo "also tagged as jkiesele/minicalosim:latest"
+31 -1
View File
@@ -2,4 +2,34 @@
# Shim to emit warning and call start-notebook.py
echo "WARNING: Use start-notebook.py instead"
exec /usr/local/bin/start-notebook.py "$@"
if id jovyan &> /dev/null; then
if ! usermod --home "/home/${NB_USER}" --login "${NB_USER}" jovyan 2>&1 | grep "no changes" > /dev/null; then
echo "Updated the jovyan user:"
echo "- username: jovyan -> ${NB_USER}"
echo "- home dir: /home/jovyan -> /home/${NB_USER}"
fi
elif ! id -u "${NB_USER}" &> /dev/null; then
echo "ERROR: Neither the jovyan user nor '${NB_USER}' exists. This could be the result of stopping and starting, the container with a different NB_USER environment variable."
exit 1
fi
# Ensure the desired user (NB_USER) gets its desired user id (NB_UID) and is
# a member of the desired group (NB_GROUP, NB_GID)
if [ "${NB_UID}" != "$(id -u "${NB_USER}")" ] || [ "${NB_GID}" != "$(id -g "${NB_USER}")" ]; then
echo "Update ${NB_USER}'s UID:GID to ${NB_UID}:${NB_GID}"
# Ensure the desired group's existence
if [ "${NB_GID}" != "$(id -g "${NB_USER}")" ]; then
groupadd --force --gid "${NB_GID}" --non-unique "${NB_GROUP:-${NB_USER}}"
fi
# Recreate the desired user as we want it
userdel "${NB_USER}"
useradd --no-log-init --home "/home/${NB_USER}" --shell /bin/bash --uid "${NB_UID}" --gid "${NB_GID}" --groups 100 "${NB_USER}"
fi
# if root change user to jovyan
if [ "$EUID" -eq 0 ]; then
echo "WARNING: Running as root. Use start-notebook.py to run as ${NB_USER} user"
exec su ${NB_USER} -c "exec /usr/local/bin/start-notebook.py $@"
else
exec /usr/local/bin/start-notebook.py "$@"
fi