How to use dockerspawner - 10 common examples

To help you get started, we’ve selected a few dockerspawner examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github compmodels / jupyterhub / swarmspawner.py View on Github external
from tornado import gen
from dockerspawner import DockerSpawner, SystemUserSpawner

# urllib3 complains that we're making unverified HTTPS connections to swarm,
# but this is ok because we're connecting to swarm via 127.0.0.1. I don't
# actually want swarm listening on a public port, so I don't want to connect
# to swarm via the host's FQDN, which means we can't do fully verified HTTPS
# connections. To prevent the warning from appearing over and over and over
# again, I'm just disabling it for now.
import requests
requests.packages.urllib3.disable_warnings()


class SwarmSpawner(SystemUserSpawner):

    container_ip = '0.0.0.0'

    @gen.coroutine
    def lookup_node_name(self):
        """Find the name of the swarm node that the container is running on."""
        containers = yield self.docker('containers', all=True)
        for container in containers:
            if container['Id'] == self.container_id:
                name, = container['Names']
                node, container_name = name.lstrip("/").split("/")
                raise gen.Return(node)

    @gen.coroutine
    def start(self, image=None, extra_create_kwargs=None, extra_host_config=None):
        # look up mapping of node names to ip addresses
github rgbkrk / jupyterhub-compmodels-deploy / roles / jupyterhub / files / swarmspawner.py View on Github external
from tornado import gen
from dockerspawner import DockerSpawner, SystemUserSpawner

# urllib3 complains that we're making unverified HTTPS connections to swarm,
# but this is ok because we're connecting to swarm via 127.0.0.1. I don't
# actually want swarm listening on a public port, so I don't want to connect
# to swarm via the host's FQDN, which means we can't do fully verified HTTPS
# connections. To prevent the warning from appearing over and over and over
# again, I'm just disabling it for now.
import requests
requests.packages.urllib3.disable_warnings()


class SwarmSpawner(SystemUserSpawner):

    container_ip = '0.0.0.0'

    def _user_id_default(self):
        return 2000

    @gen.coroutine
    def lookup_node_name(self):
        """Find the name of the swarm node that the container is running on."""
        containers = yield self.docker('containers', all=True)
        for container in containers:
            if container['Id'] == self.container_id:
                name, = container['Names']
                node, container_name = name.lstrip("/").split("/")
                raise gen.Return(node)
github everware / everware / everware / spawner.py View on Github external
def get_state(self):
        state = DockerSpawner.get_state(self)
        state.update(GitMixin.get_state(self))
        state.update(dict(
            name=self.user.name,
        ))
        if hasattr(self.user, 'token'):
            state.update(dict(token=self.user.token))
        if hasattr(self.user, 'login_service'):
            state.update(dict(login_service=self.user.login_service))
        return state
github genepattern / genepattern-notebook / jupyterhub / jupyterhub_config.py View on Github external
c.JupyterHub.hub_ip = '0.0.0.0'

# The IP address (or hostname) the single-user server should listen on
c.Spawner.ip = '0.0.0.0'

# Add gpauthenticator.py to the Python path, if necessary
# import sys
# sys.path.append('/home/genepattern/')

# Set GenePatternAuthenticator as the authenticator
import gpauthenticator
c.JupyterHub.authenticator_class = gpauthenticator.GenePatternAuthenticator

# Set DockerSpawner as the spawner
import dockerspawner
c.JupyterHub.spawner_class = dockerspawner.DockerSpawner

# The docker instances need access to the Hub, so the default loopback port doesn't work:
from IPython.utils.localinterfaces import public_ips
c.JupyterHub.hub_ip = public_ips()[0]
github jupyterhub / oauthenticator / dockerspawner.py View on Github external
def _env_default(self):
        env = super(DockerSpawner, self)._env_default()
        env.update(dict(
            JPY_USER=self.user.name,
            JPY_COOKIE_NAME=self.user.server.cookie_name,
            JPY_BASE_URL=self.user.server.base_url,
            JPY_HUB_PREFIX=self.hub.server.base_url,
            JPY_HUB_API_URL=self.hub.api_url,
        ))
        return env
github SwissDataScienceCenter / renku / services / jupyterhub / spawners.py View on Github external
    @staticmethod
    def _get_job_status(pipeline, job_name):
        """Helper method to retrieve job status based on the job name."""
        status = [
            job.attributes['status'] for job in pipeline.jobs.list()
            if job.attributes['name'] == job_name
        ]
        return status.pop() if status else None


try:
    import docker
    from dockerspawner import DockerSpawner

    class RepoVolume(DockerSpawner):
        """Create and configure repo volume."""

        @gen.coroutine
        def start(self):
            """Create init container."""
            auth_state = yield self.user.get_auth_state()
            options = self.user_options
            name = self.name + '-git-repo'
            safe_username = escapism.escape(
                self.user.name,
                safe=set(string.ascii_lowercase + string.digits + '-'),
                escape_char='-'
            )
            container_name = 'init-' + safe_username + '-' + self.name
            volume_name = 'repo-' + safe_username + '-' + container_name
            volume_path = '/home/jovyan/work'
github everware / everware / everware / container_handler.py View on Github external
return ShellCommand([
        'jupyterhub-singleuser --port=8888 --ip=0.0.0.0 --allow-root --user={} --cookie-name={} --base-url={} '.format(
            env['JPY_USER'],
            env['JPY_COOKIE_NAME'],
            env['JPY_BASE_URL']
        ) + '--hub-prefix={} --hub-api-url={} --notebook-dir=/notebooks'.format(
            env['JPY_HUB_PREFIX'],
            env['JPY_HUB_API_URL']
        )
    ])

def make_custom_start_command(command):
    return ShellCommand([command])


class ContainerHandler(DockerSpawner):
    def parse_config(self, directory):
        self.everware_config = {
            'everware_based': True
        }
        try:
            with open(os.path.join(directory, 'everware.yml')) as fin:
                try:
                    self.everware_config = yaml.load(fin)
                except yaml.YAMLError as exc:
                    self.log.warn('Fail reading everware.yml: {}'.format(exc))
        except IOError:
            self.log.info('No everware.yaml in repo')

    @gen.coroutine
    def prepare_container(self):
        if self.everware_config.get('everware_based', True):
github SwissDataScienceCenter / renku / services / jupyterhub / spawners.py View on Github external
extra_host_config = {
                'binds': {
                    volume_name: {
                        'bind': volume_path,
                        'mode': 'rw',
                    },
                },
            }

            result = yield super().start(
                extra_create_kwargs=extra_create_kwargs,
                extra_host_config=extra_host_config,
            )
            return result

    class RenkuDockerSpawner(SpawnerMixin, RepoVolume, DockerSpawner):
        """A class for spawning notebooks on Renku-JupyterHub using Docker."""

except ImportError:
    pass

try:
    from kubernetes import client
    from kubespawner import KubeSpawner

    class RenkuKubeSpawner(SpawnerMixin, KubeSpawner):
        """A class for spawning notebooks on Renku-JupyterHub using K8S."""

        @gen.coroutine
        def get_pod_manifest(self):
            """Include volume with the git repository."""
            auth_state = yield self.user.get_auth_state()
github danielballan / jupyterhub-share-link / example_config_dockerspawner.py View on Github external
{
        'name': 'share-link',
        'admin': True,
        'url': 'http://127.0.0.1:21211',
        'command': [sys.executable, '-m', 'jupyterhub_share_link.run'],
    }
]
c.JupyterHub.admin_access = True  # Service needs to access user servers.

c.JupyterHub.allow_named_servers = True
c.Spawner.cmd = ['jupyter-labhub']

c.JupyterHub.authenticator_class = 'jupyterhub.auth.DummyAuthenticator'


c.JupyterHub.spawner_class = dockerspawner.DockerSpawner
c.DockerSpawner.remove_containers = True
c.DockerSpawner.image_whitelist = [
    'danielballan/base-notebook-with-jupyterhub-share-labextension',
    'danielballan/scipy-notebook-with-jupyterhub-share-labextension',
]

# This is only needed until
# https://github.com/jupyterhub/dockerspawner/pull/315
# is merged and released.
c.DockerSpawner.name_template = "{prefix}-{username}-{servername}"

c.Spawner.default_url = '/lab'

# The docker instances need access to the Hub,
# so the default loopback port doesn't work:
c.JupyterHub.hub_ip = public_ips()[0]
github everware / everware / everware / spawner.py View on Github external
def load_state(self, state):
        DockerSpawner.load_state(self, state)
        GitMixin.load_state(self, state)
        for key in ('name', 'token', 'login_service'):
            if key in state:
                setattr(self.user, key, state[key])
        self.user.stop_pending = False
        self.user.spawn_pending = False