kopia lustrzana https://github.com/jupyterhub/repo2docker
Merge pull request #343 from GladysNalvarte/split-docker-image
Test that images can start notebook servers in all the builderspull/338/head^2
commit
8075c5bf10
|
@ -491,11 +491,22 @@ class Repo2Docker(Application):
|
||||||
last_emit_time = time.time()
|
last_emit_time = time.time()
|
||||||
|
|
||||||
def run_image(self):
|
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')
|
client = docker.from_env(version='auto')
|
||||||
if not self.run_cmd:
|
if not self.run_cmd:
|
||||||
port = str(self._get_free_port())
|
port = str(self._get_free_port())
|
||||||
|
self.port = port
|
||||||
run_cmd = ['jupyter', 'notebook', '--ip', '0.0.0.0',
|
run_cmd = ['jupyter', 'notebook', '--ip', '0.0.0.0',
|
||||||
'--port', port]
|
'--port', port]
|
||||||
ports = {'%s/tcp' % port: port}
|
ports = {'%s/tcp' % port: port}
|
||||||
|
@ -506,6 +517,8 @@ class Repo2Docker(Application):
|
||||||
ports = self.ports
|
ports = self.ports
|
||||||
else:
|
else:
|
||||||
ports = {}
|
ports = {}
|
||||||
|
# store ports on self so they can be retrieved in tests
|
||||||
|
self.ports = ports
|
||||||
container_volumes = {}
|
container_volumes = {}
|
||||||
if self.volumes:
|
if self.volumes:
|
||||||
api_client = docker.APIClient(
|
api_client = docker.APIClient(
|
||||||
|
@ -534,6 +547,14 @@ class Repo2Docker(Application):
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
container.reload()
|
container.reload()
|
||||||
|
|
||||||
|
return container
|
||||||
|
|
||||||
|
def wait_for_container(self, container):
|
||||||
|
"""Wait for a container to finish
|
||||||
|
|
||||||
|
Displaying logs while it's running
|
||||||
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for line in container.logs(stream=True):
|
for line in container.logs(stream=True):
|
||||||
self.log.info(line.decode('utf-8'),
|
self.log.info(line.decode('utf-8'),
|
||||||
|
|
|
@ -11,6 +11,8 @@ success.
|
||||||
import os
|
import os
|
||||||
import pipes
|
import pipes
|
||||||
import shlex
|
import shlex
|
||||||
|
import requests
|
||||||
|
import time
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -30,7 +32,39 @@ def make_test_func(args):
|
||||||
def test():
|
def test():
|
||||||
app = Repo2Docker()
|
app = Repo2Docker()
|
||||||
app.initialize(args)
|
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
|
return test
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,6 +102,13 @@ class LocalRepo(pytest.File):
|
||||||
'./verify',
|
'./verify',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
yield Repo2DockerTest(
|
||||||
|
self.fspath.basename, self,
|
||||||
|
args=[
|
||||||
|
'--appendix', 'RUN echo "appendix" > /tmp/appendix',
|
||||||
|
self.fspath.dirname,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RemoteRepoList(pytest.File):
|
class RemoteRepoList(pytest.File):
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
FROM python:3.5
|
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 sayhi.sh /usr/local/bin/sayhi.sh
|
||||||
ADD verify verify
|
ADD verify verify
|
||||||
|
|
||||||
|
ARG NB_UID
|
||||||
|
ENV HOME /tmp
|
||||||
|
USER $NB_UID
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
/usr/local/bin/sayhi.sh
|
/usr/local/bin/sayhi.sh
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
FROM python:3.5
|
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 sayhi.sh /usr/local/bin/sayhi.sh
|
||||||
ADD verify verify
|
ADD verify verify
|
||||||
|
|
||||||
|
ARG NB_UID
|
||||||
|
ENV HOME /tmp
|
||||||
|
USER $NB_UID
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
/usr/local/bin/sayhi.sh
|
/usr/local/bin/sayhi.sh
|
||||||
|
|
Ładowanie…
Reference in New Issue