Last active
July 21, 2017 13:15
-
-
Save minrk/b9103e935052a70ba00dc93e06be6636 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pwd | |
import grp | |
from dockerspawner import SystemUserSpawner | |
class SystemGroupSpawner(SystemUserSpawner): | |
# local unix groups a user might be a member of | |
groups = ['admin'] | |
def get_env(self): | |
env = super().get_env() | |
# don't set USER env, which SystemUserSpawner uses. | |
env.pop('USER', None) | |
# set notebook UID | |
env['NB_UID'] = self.user_id | |
for groupname in self.groups: | |
group = grp.getgrnam(groupname) | |
# find the first group in our group list that the user is a member of, | |
# and set the group id | |
if self.user.name in group.gr_mem: | |
env['NB_GID'] = group.gr_gid | |
return env | |
# Select our custom Spawner | |
c.JupyterHub.spawner_class = SystemGroupSpawner | |
# Select one of the docker-stacks (https://github.com/jupyter/docker-stacks) | |
c.SystemGroupSpawner.container_image = 'jupyter/base-notebook' | |
# must start container as root in order for docker-stacks to set up NB_UID / NB_GID correctly | |
c.SystemGroupSpawner.extra_create_kwargs = {'user': 'root'} | |
# This line should be redundant with above, | |
# but there's a bug in docker-stacks assuming $UID is the user id | |
# BUG: https://github.com/jupyter/docker-stacks/pull/420 | |
c.SystemGroupSpawner.environment = {'UID': '0'} | |
# networking stuff below here (yours may differ) | |
import netifaces | |
docker_ip = netifaces.ifaddresses('en0')[netifaces.AF_INET][0]['addr'] | |
c.JupyterHub.hub_ip = docker_ip | |
c.SystemGroupSpawner.hub_connect_ip = docker_ip | |
c.SystemGroupSpawner.host_homedir_format_string = '/tmp/{username}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment