Permalink
Browse files

use default docker image, increase poll rate

  • Loading branch information...
1 parent 79c3896 commit 2834bb81a8084686fa94d31b944ec7af2a6649f7 @astiunov astiunov committed Dec 31, 2016
Showing with 49 additions and 4 deletions.
  1. +1 −0 etc/base_config.py
  2. +17 −0 everware/git_processor.py
  3. +31 −4 everware/spawner.py
View
@@ -10,6 +10,7 @@
c.Spawner.debug = True
c.Spawner.start_timeout = 1000
c.Spawner.http_timeout = 60
+c.Spawner.poll_interval = 5
c.Spawner.remove_containers = True
c.Spawner.tls_assert_hostname = False
c.Spawner.use_docker_client_env = True
View
@@ -2,6 +2,7 @@
import git
from concurrent.futures import ThreadPoolExecutor
from tornado import gen
+import os
class GitMixin:
@@ -92,13 +93,29 @@ def git(self, method, *args, **kwargs):
@gen.coroutine
def prepare_local_repo(self):
+ """Returns False if there is no Dockerfile in repo
+
+ True otherwise
+ """
clone_url = self.repo_url_with_token
yield self.git('clone', clone_url, self._repo_dir)
repo = git.Repo(self._repo_dir)
repo.git.reset('--hard', self._repo_pointer)
self._repo_sha = repo.rev_parse('HEAD').hexsha
self._branch_name = repo.active_branch.name
+ dockerfile_path = os.join(self._repo_dir, 'Dockerfile')
+ if not os.path.isfile(dockerfile_path):
+ with open(dockerfile_path, 'w') as fout:
+ fout.writelines([
+ 'FROM everware/datascience-jupyter:latest\n',
+ 'MAINTAINER Alexander Tiunov <astiunov@yandex-team.ru>'
+ ])
+ return False
+ else:
+ return True
+
+
@property
def escaped_repo_url(self):
repo_url = re.sub(r'^.+?://', '', self._processed_repo_url)
View
@@ -145,7 +145,7 @@ def options_from_form(self, formdata):
def form_repo_url(self):
"""Repository URL as submitted by the user."""
return self.user_options.get('repo_url', '')
-
+
@property
def container_name(self):
return "{}-{}".format(self.container_prefix,
@@ -166,15 +166,15 @@ def is_up(self):
@gen.coroutine
def get_container(self):
- self.log.debug("Getting container: %s", self.container_name)
+ # self.log.debug("Getting container: %s", self.container_name)
try:
container = yield self.docker(
'inspect_container', self.container_name
)
self.container_id = container['Id']
except APIError as e:
if e.response.status_code == 404:
- self.log.info("Container '%s' is gone", self.container_name)
+ # self.log.info("Container '%s' is gone", self.container_name)
container = None
# my container is gone, forget my id
self.container_id = ''
@@ -238,7 +238,9 @@ def build_image(self):
self.repo_url
))
self.log.info('Cloning repo %s' % self.repo_url)
- yield self.prepare_local_repo()
+ dockerfile_exists = yield self.prepare_local_repo()
+ if not dockerfile_exists:
+ self._add_to_log('No dockerfile. Use the default one')
# use git repo URL and HEAD commit sha to derive
# the image name
@@ -291,6 +293,31 @@ def remove_old_container(self):
except APIError as e:
self.log.info("Can't erase container %s due to %s" % (self.container_name, e))
+ @gen.coroutine
+ def wait_up(self):
+ # copied from jupyterhub, because if user's server didn't appear, it
+ # means that spawn was unsuccessful, need to set is_failed
+ try:
+ yield self.user.server.wait_up(http=True, timeout=self.http_timeout)
+ ip, port = yield from self.get_ip_and_port()
+ self.user.server.ip = ip
+ self.user.server.port = port
+ except TimeoutError:
+ self._is_failed = True
+ self._add_to_log('Server never showed up after {} seconds'.format(self.http_timeout))
+ self.log.info("{user}'s server never showed up after {timeout} seconds".format(
+ user=self.user.name,
+ timeout=self.http_timeout
+ ))
+ yield self.notify_about_fail("Http timeout limit %.3f exceeded" % self.http_timeout)
+ raise
+ except Exception as e:
+ self._is_failed = True
+ message = str(e)
+ self._add_to_log('Something went wrong during waiting for server. Error: %s' % message)
+ yield self.notify_about_fail(message)
+ raise e
+
@gen.coroutine
def start(self, image=None):

0 comments on commit 2834bb8

Please sign in to comment.