How to use the dockerspawner.DockerSpawner function in dockerspawner

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 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 jupyter-attic / jupyterhub-carina / jupyterhub_carina / CarinaSpawner.py View on Github external
import docker
from dockerspawner import DockerSpawner
import os.path
import re
import shutil
from tornado import gen
from traitlets import Dict, Integer, Unicode
from .CarinaOAuthClient import CarinaOAuthClient


class CarinaSpawner(DockerSpawner):
    """
    Spawn the user's Jupyter server on their Carina cluster
    """

    cluster_name = Unicode(
        'jupyterhub',
        help="The name of the user's Carina cluster.",
        config=True)

    # Override the default container name. Since we are running on the user's cluster, we don't
    # need the username suffix
    container_name = Unicode(
        'jupyter',
        help="The name of the Jupyter server container running on the user's cluster.",
        config=True)