From 89686833c0cd8a692da76f55d7d1144d3d164b5c Mon Sep 17 00:00:00 2001 From: Gladys Nalvarte Date: Tue, 3 Jul 2018 10:55:31 +0200 Subject: [PATCH] Updated app.py to make sure that images can start notebook servers Includes an update of conftest.py file to check that the container is running with jupyter notebook in all the builders. --- repo2docker/app.py | 8 ++++---- tests/conftest.py | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/repo2docker/app.py b/repo2docker/app.py index d1fb5383..d98b9226 100644 --- a/repo2docker/app.py +++ b/repo2docker/app.py @@ -103,10 +103,10 @@ class Repo2Docker(Application): Use a key-value pair, with the key being the volume source & value being the destination volume. - - Both source and destination can be relative. Source is resolved + + Both source and destination can be relative. Source is resolved relative to the current working directory on the host, and - destination is resolved relative to the working directory of the + destination is resolved relative to the working directory of the image - ($HOME by default) """, config=True @@ -504,7 +504,7 @@ class Repo2Docker(Application): client = docker.from_env(version='auto') if not self.run_cmd: port = str(self._get_free_port()) - + self.port = port run_cmd = ['jupyter', 'notebook', '--ip', '0.0.0.0', '--port', port] ports = {'%s/tcp' % port: port} diff --git a/tests/conftest.py b/tests/conftest.py index 0ac14028..f4031efe 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,6 +11,8 @@ success. import os import pipes import shlex +import requests +import time import pytest import yaml @@ -30,7 +32,39 @@ def make_test_func(args): def test(): app = Repo2Docker() app.initialize(args) - app.start() + if app.run_cmd: + # verify test, run it + app.start() + return + # no run_cmd given, starting notebook server + app.run = False + app.start() # This just build the image and does not run it. + container = app.start_container() + port = app.port + # wait a bit for the container to be ready + container_url = 'http://localhost:%s/api' % port + # give the container a chance to start + time.sleep(1) + try: + # try a few times to connect + success = False + for i in range(1, 4): + container.reload() + assert container.status == 'running' + try: + info = requests.get(container_url).json() + except Exception as e: + print("Error: %s" % e) + time.sleep(i * 3) + else: + print(info) + success = True + break + assert success, "Notebook never started in %s" % container + finally: + # stop the container + container.stop() + app.wait_for_container(container) return test @@ -68,6 +102,13 @@ class LocalRepo(pytest.File): './verify', ], ) + yield Repo2DockerTest( + self.fspath.basename, self, + args=[ + '--appendix', 'RUN echo "appendix" > /tmp/appendix', + self.fspath.dirname, + ], + ) class RemoteRepoList(pytest.File):