From 0d7182e16995a546a0dc4bc30b1783367f495d36 Mon Sep 17 00:00:00 2001 From: mathematicalmichael Date: Tue, 15 Jan 2019 17:19:59 -0700 Subject: [PATCH] added setup scripts. --- .env | 4 +++- jupyterhub_config.py | 6 +++++- Makefile => makefile | 1 - setup.sh | 33 +++++++++++++++++++++++++++++++++ show_login.sh | 12 ++++++++++++ 5 files changed, 53 insertions(+), 3 deletions(-) rename Makefile => makefile (98%) create mode 100755 setup.sh create mode 100755 show_login.sh diff --git a/.env b/.env index 5cc8bb6..58784ec 100755 --- a/.env +++ b/.env @@ -37,5 +37,7 @@ DOCKER_SPAWN_CMD=start-singleuser.sh # provide at least one user from `userlist` so that `make login` can show you the associated password # (useful when changing secret keys or creating hub for the first time) # afterwards, you can visit /hub/login_list (if enabled and you are an admin) to see everyone's passwords. -USERNAME=michael +# by default, hub-admin will be an admin user (defined in jupyterhub_config.py). +# you can print the password for this hub-admin user with 'bash show_login.sh' +USERNAME=hub-admin PASSWORD_LENGTH=6 diff --git a/jupyterhub_config.py b/jupyterhub_config.py index 75cdde7..72a3f17 100755 --- a/jupyterhub_config.py +++ b/jupyterhub_config.py @@ -71,7 +71,7 @@ spawn_cmd = os.environ.get('DOCKER_SPAWN_CMD', "start-singleuser.sh") c.DockerSpawner.extra_create_kwargs.update({ 'command': spawn_cmd }) # Memory limit -# c.Spawner.mem_limit = '2G' # RAM limit +c.Spawner.mem_limit = '42G' # RAM limit #c.Spawner.cpu_limit = 0.1 # Connect containers to this Docker network @@ -111,6 +111,10 @@ c.JupyterHub.base_url = u'/%s/'%hub_name # Whitlelist users and admins c.Authenticator.whitelist = whitelist = set() c.Authenticator.admin_users = admin = set() + +# add default user so that first-time log in is easy. +admin.add('hub-admin') + with open(os.path.join(pwd, 'userlist')) as f: for line in f: if not line: diff --git a/Makefile b/makefile similarity index 98% rename from Makefile rename to makefile index 278e3c8..1c9149c 100755 --- a/Makefile +++ b/makefile @@ -2,7 +2,6 @@ # Distributed under the terms of the Modified BSD License. include .env -include secrets/oauth.env .DEFAULT_GOAL=build diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..892b3a4 --- /dev/null +++ b/setup.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# this script is meant to be run only the first time a hub is being set up. + +# create a default userlist +echo "hub-admin admin shared" > userlist +mkdir secrets +make secrets/oauth.env +make secrets/postgres.env + +source .env +# show what is needed to be added to /etc/nginx/sites-enabled/hub.conf + +echo -en "\nBuilding Hub $HUB_NAME. Please be patient. This may take up to 15 minutes, depending on your hardware." +make notebook_image +make build +docker-compose up -d + +echo -en "\n\nWe create a default shared volume and set its permissions to be read/write. You may have to enter your password now:\n" +docker volume create shared-shared +sudo chmod 777 $(docker inspect shared-shared | grep "Mountpoint" | awk '{print $2}' | sed 's/"//g' | sed 's/,//g') +echo -en "Volume has been created." + +echo -en "\n\nHub has been launched. Here are the Docker processes running right now:" +docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" + + +echo -en "\n\nCONGRATS!!! Hub $HUB_NAME has been created and launched!. Please add the following to /etc/nginx/sites-enabled/hub.conf. Run\n" +echo -en "\n\tsudo vim /etc/nginx/sites-enabled/hub.conf \n\nand enter the following into the server entry:\n" +echo -en "\nlocation /$HUB_NAME { \n\t proxy_pass http://127.0.0.1:$PORT_NUM; \n\t proxy_set_header X-Real-IP \$remote_addr; \n\t proxy_set_header Host \$host; \n\t proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; \n\t # websocket headers \n\t proxy_set_header Upgrade \$http_upgrade; \n\t proxy_set_header Connection \$connection_upgrade; \n } \n\n" + +echo -en "After you add that and restart nginx with \n\tsudo service nginx restart\nyou can access your hub using\n\n" +bash show_login.sh diff --git a/show_login.sh b/show_login.sh new file mode 100755 index 0000000..3a13f9b --- /dev/null +++ b/show_login.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# load environmental variables into the bash session's namespace +source .env +source secrets/oauth.env +# run ephemeral docker container to print out password. +echo "Password for username: hub-admin is " +docker run --rm $HUB_NAME hashauthpw --length $PASSWORD_LENGTH hub-admin $HASH_SECRET_KEY + +#echo "Password for username: $USERNAME is " +#docker run --rm $HUB_NAME hashauthpw --length $PASSWORD_LENGTH $USERNAME $HASH_SECRET_KEY +