From 7e24a0c751198f8d174487fac402a9778c590bc2 Mon Sep 17 00:00:00 2001 From: William Petit Date: Mon, 7 Nov 2016 19:38:54 +0100 Subject: [PATCH] Initial commit --- .gitignore | 1 + containers/hub/Dockerfile | 40 ++++++++++++++++++++++++++++ containers/hub/create-hub-student.sh | 26 ++++++++++++++++++ docker-compose.yml | 18 +++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 .gitignore create mode 100644 containers/hub/Dockerfile create mode 100644 containers/hub/create-hub-student.sh create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3af0ccb --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/data diff --git a/containers/hub/Dockerfile b/containers/hub/Dockerfile new file mode 100644 index 0000000..1dd576c --- /dev/null +++ b/containers/hub/Dockerfile @@ -0,0 +1,40 @@ +FROM jupyterhub/jupyterhub + +ARG HTTP_PROXY= +ARG HTTPS_PROXY= +ARG http_proxy= +ARG https_proxy= + +ARG TUTOR_USERNAME=tutor +ARG TUTOR_PASSWORD=tutor + +RUN apt-get update -y \ + && apt-get install -y curl ca-certificates \ + && curl -sL https://deb.nodesource.com/setup_6.x | bash - \ + && apt-get install -y nodejs libzmq3-dev mcrypt + +RUN pip install jupyter + +RUN npm install -g ijavascript \ + && ijs --ijs-install=global + +RUN useradd -m $TUTOR_USERNAME \ + && echo "$TUTOR_USERNAME:$TUTOR_PASSWORD" | chpasswd + +RUN mkdir -p /home/$TUTOR_USERNAME/lessons \ + && mkdir -p /home/$TUTOR_USERNAME/students \ + && chown -R $TUTOR_USERNAME: /home/$TUTOR_USERNAME + +RUN echo "TUTOR_USERNAME=$TUTOR_USERNAME" > /srv/jupyterhub/tutor.conf + +ADD create-hub-student.sh /usr/local/bin/create-hub-student +RUN chmod +x /usr/local/bin/create-hub-student + +RUN mkdir -p /etc/jupyterhub \ + && cd /etc/jupyterhub \ + && jupyterhub --generate-config \ + && sed -i "s/^#c.Authenticator.admin_users = set()$/c.Authenticator.admin_users = set(['$TUTOR_USERNAME'])/" jupyterhub_config.py \ + && sed -i "s/^#c.LocalAuthenticator.create_system_users = False$/c.LocalAuthenticator.create_system_users = True/" jupyterhub_config.py \ + && sed -i "s/^#c.LocalAuthenticator.add_user_cmd = \[\]$/c.LocalAuthenticator.add_user_cmd = ['\/usr\/local\/bin\/create-hub-student']/" jupyterhub_config.py + +CMD ["jupyterhub", "--config", "/etc/jupyterhub/jupyterhub_config.py"] diff --git a/containers/hub/create-hub-student.sh b/containers/hub/create-hub-student.sh new file mode 100644 index 0000000..3e3869d --- /dev/null +++ b/containers/hub/create-hub-student.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -e + +USERNAME=$1 + +source /srv/jupyterhub/tutor.conf + +if [ -z "$USERNAME" ]; then + echo "You must provide a valid username as first argument !" 1>&2 + exit 1 +fi + +echo -e "$USERNAME\n$USERNAME\n" | adduser -q --gecos "" $USERNAME + +# Expose student work to tutor +mkdir -p /home/$TUTOR_USERNAME/students +ln -s /home/$USERNAME /home/$TUTOR_USERNAME/students/$USERNAME +chown $TUTOR_USERNAME: /home/$TUTOR_USERNAME/students/$USERNAME + +#Expose tutor's lessons to student +mkdir -p /home/$TUTOR_USERNAME/lessons +chown $TUTOR_USERNAME: /home/$TUTOR_USERNAME/lessons +ln -s /home/$TUTOR_USERNAME/lessons /home/$USERNAME/lessons + +chown $USERNAME: /home/$USERNAME diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..38a91d2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +version: "2" +services: + hub: + build: + context: containers/hub + dockerfile: Dockerfile + args: + - HTTP_PROXY=${HTTP_PROXY} + - HTTPS_PROXY=${HTTPS_PROXY} + - http_proxy=${http_proxy} + - https_proxy=${https_proxy} + - TUTOR_USERNAME=tutor + - TUTOR_PASSWORD=tutor + ports: + - 8000:8000 + volumes: + - ./data/lessons:/home/tutor/lessons + - ./data/students:/home/tutor/students