Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swarmspawner to support new-style Docker Swarm mode #216

Merged
merged 13 commits into from
May 30, 2018

Conversation

scnerd
Copy link
Contributor

@scnerd scnerd commented Jan 30, 2018

Added a new class called Swarmspawner by duplicating Dockerspawner and modifying it where needed. Removed deprecated fields instead of adapting them. My working sample hub config looks like the following:

c.JupyterHub.ip = '0.0.0.0'

c.JupyterHub.spawner_class = 'dockerspawner.SwarmSpawner'
c.SwarmSpawner.image = os.environ.get('DOCKER_NOTEBOOK_IMAGE')
c.SwarmSpawner.use_docker_client_env = True

network_name = os.environ['DOCKER_NETWORK_NAME']
c.SwarmSpawner.use_internal_ip = True
c.SwarmSpawner.network_name = network_name
c.SwarmSpawner.extra_host_config = {'network_mode': network_name}
c.SwarmSpawner.remove_services = True

notebook_dir = os.environ.get('DOCKER_NOTEBOOK_DIR') or '/home/jovyan/work'
c.SwarmSpawner.notebook_dir = notebook_dir
# c.SwarmSpawner.volumes = {'notebooks/jupyterhub-user-{username}': notebook_dir}
# c.SwarmSpawner.extra_create_kwargs.update({'volume_driver': 'local'})

c.SwarmSpawner.debug = True

c.Spawner.default_url = '/lab'
c.Spawner.args = ['--NotebookApp.allow_origin=*']

c.JupyterHub.hub_ip = '0.0.0.0'
# c.JupyterHub.hub_port = 8080

c.Spawner.cpu_limit = 0.25

c.Spawner.mem_limit = '256M'

Mounting volumes not yet tested. Not sure about other other features not explicitly tested in the above configuration.

To reduce the technical debt of this addition, it would probably be worthwhile extracting a superclass for both Dockerspawner and Swarmspawner (especially their shared attributes). Most of the major differences are isolated to a few functions (start, stop, poll, get_service/container, maybe one or two others).

@scnerd
Copy link
Contributor Author

scnerd commented Feb 20, 2018

Resolves #215

David B. Maxson and others added 2 commits March 29, 2018 17:13
…ks are proxied to from another machine inside the same network?) due to it preventing multiple notebook servers being launched
@sangramga
Copy link

Wow a really needed PR. @minrk Hope it is merged soon.

@sangramga
Copy link

@scnerd Just a doubt? Will get_ip_and_port() work with network = host (As mentioned in the docstring )

def get_ip_and_port(self):
        """Queries Docker daemon for service's IP and port.  
        If you are using network_mode=host, you will need to override  
        this method as follows::  
            @gen.coroutine  
            def get_ip_and_port(self):  
                return self.host_ip, self.port  
        You will need to make sure host_ip and port  
        are correct, which depends on the route to the service  
        and the port it `opens.`  
        """

@minrk minrk merged commit f8b7250 into jupyterhub:master May 30, 2018
@minrk
Copy link
Member

minrk commented May 30, 2018

Thanks, this is great! I think we should make SwarmSpawner inherit from DockerSpawner so as to avoid reimplementing too many things, but that can be done in a separate PR.

@scnerd
Copy link
Contributor Author

scnerd commented May 30, 2018

I think inheritance would be great, though I think there are enough little differences in the configuration and behavior of each that I'd suggest creating a shared, abstract base class, and making both DockerSpawner and SwarmSpawner inherit from it. I meant to get around to this, but wanted to get the original SwarmSpawner tested and merged first before creating a branch that modified the main DockerSpawner.

@scnerd scnerd deleted the swarmspawner branch May 30, 2018 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants