Merge pull request #343 from GladysNalvarte/split-docker-image

Test that images can start notebook servers in all the builders
pull/338/head^2
Min RK 2018-07-04 15:15:53 +02:00 zatwierdzone przez GitHub
commit 8075c5bf10
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
6 zmienionych plików z 81 dodań i 7 usunięć

Wyświetl plik

@ -491,11 +491,22 @@ class Repo2Docker(Application):
last_emit_time = time.time()
def run_image(self):
"""Run docker container from built image"""
"""Run docker container from built image
and wait for it to finish.
"""
container = self.start_container()
self.wait_for_container(container)
def start_container(self):
"""Start docker container from built image
Returns running container
"""
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}
@ -506,6 +517,8 @@ class Repo2Docker(Application):
ports = self.ports
else:
ports = {}
# store ports on self so they can be retrieved in tests
self.ports = ports
container_volumes = {}
if self.volumes:
api_client = docker.APIClient(
@ -534,6 +547,14 @@ class Repo2Docker(Application):
time.sleep(0.5)
container.reload()
return container
def wait_for_container(self, container):
"""Wait for a container to finish
Displaying logs while it's running
"""
try:
for line in container.logs(stream=True):
self.log.info(line.decode('utf-8'),

Wyświetl plik

@ -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):

Wyświetl plik

@ -1,6 +1,12 @@
FROM python:3.5
ENTRYPOINT "/bin/sh"
RUN pip install --no-cache notebook
CMD "/bin/sh"
ADD sayhi.sh /usr/local/bin/sayhi.sh
ADD verify verify
ARG NB_UID
ENV HOME /tmp
USER $NB_UID

Wyświetl plik

@ -1,3 +1,3 @@
#!/bin/sh
#!/bin/bash
set -euo pipefail
/usr/local/bin/sayhi.sh

Wyświetl plik

@ -1,6 +1,12 @@
FROM python:3.5
ENTRYPOINT "/bin/sh"
RUN pip install --no-cache notebook
CMD "/bin/sh"
ADD sayhi.sh /usr/local/bin/sayhi.sh
ADD verify verify
ARG NB_UID
ENV HOME /tmp
USER $NB_UID

Wyświetl plik

@ -1,3 +1,3 @@
#!/bin/sh
#!/bin/bash
set -euo pipefail
/usr/local/bin/sayhi.sh