added setup scripts.

This commit is contained in:
mathematicalmichael 2019-01-15 17:19:59 -07:00
parent c01aa8af68
commit 0d7182e169
5 changed files with 53 additions and 3 deletions

4
.env
View File

@ -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 # 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) # (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. # 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 PASSWORD_LENGTH=6

View File

@ -71,7 +71,7 @@ spawn_cmd = os.environ.get('DOCKER_SPAWN_CMD', "start-singleuser.sh")
c.DockerSpawner.extra_create_kwargs.update({ 'command': spawn_cmd }) c.DockerSpawner.extra_create_kwargs.update({ 'command': spawn_cmd })
# Memory limit # Memory limit
# c.Spawner.mem_limit = '2G' # RAM limit c.Spawner.mem_limit = '42G' # RAM limit
#c.Spawner.cpu_limit = 0.1 #c.Spawner.cpu_limit = 0.1
# Connect containers to this Docker network # Connect containers to this Docker network
@ -111,6 +111,10 @@ c.JupyterHub.base_url = u'/%s/'%hub_name
# Whitlelist users and admins # Whitlelist users and admins
c.Authenticator.whitelist = whitelist = set() c.Authenticator.whitelist = whitelist = set()
c.Authenticator.admin_users = admin = 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: with open(os.path.join(pwd, 'userlist')) as f:
for line in f: for line in f:
if not line: if not line:

View File

@ -2,7 +2,6 @@
# Distributed under the terms of the Modified BSD License. # Distributed under the terms of the Modified BSD License.
include .env include .env
include secrets/oauth.env
.DEFAULT_GOAL=build .DEFAULT_GOAL=build

33
setup.sh Executable file
View File

@ -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

12
show_login.sh Executable file
View File

@ -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