kopia lustrzana https://github.com/jupyterhub/repo2docker
Uses jupyter/notebook option to pass explicit hostname
rodzic
e0b92796a4
commit
4c0cb69b80
|
@ -503,11 +503,26 @@ class Repo2Docker(Application):
|
||||||
Returns running container
|
Returns running container
|
||||||
"""
|
"""
|
||||||
client = docker.from_env(version='auto')
|
client = docker.from_env(version='auto')
|
||||||
|
|
||||||
|
docker_host = os.environ.get('DOCKER_HOST')
|
||||||
|
if docker_host:
|
||||||
|
host_name = urlparse(docker_host).hostname
|
||||||
|
else:
|
||||||
|
host_name = '127.0.0.1'
|
||||||
|
self.hostname = host_name
|
||||||
|
|
||||||
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
|
self.port = port
|
||||||
run_cmd = ['jupyter', 'notebook', '--ip', '0.0.0.0',
|
# To use the option --NotebookApp.custom_display_url
|
||||||
'--port', port]
|
# make sure the base-notebook image is updated:
|
||||||
|
# docker pull jupyter/base-notebook
|
||||||
|
run_cmd = [
|
||||||
|
'jupyter', 'notebook',
|
||||||
|
'--ip', '0.0.0.0',
|
||||||
|
'--port', port,
|
||||||
|
"--NotebookApp.custom_display_url=http://{}:{}".format(host_name, port),
|
||||||
|
]
|
||||||
ports = {'%s/tcp' % port: port}
|
ports = {'%s/tcp' % port: port}
|
||||||
else:
|
else:
|
||||||
# run_cmd given by user, if port is also given then pass it on
|
# run_cmd given by user, if port is also given then pass it on
|
||||||
|
@ -519,13 +534,6 @@ class Repo2Docker(Application):
|
||||||
# store ports on self so they can be retrieved in tests
|
# store ports on self so they can be retrieved in tests
|
||||||
self.ports = ports
|
self.ports = ports
|
||||||
|
|
||||||
docker_host = os.environ.get('DOCKER_HOST')
|
|
||||||
if docker_host:
|
|
||||||
host_name = urlparse(docker_host).host_name
|
|
||||||
else:
|
|
||||||
host_name = '127.0.0.1'
|
|
||||||
self.hostname = host_name
|
|
||||||
|
|
||||||
container_volumes = {}
|
container_volumes = {}
|
||||||
if self.volumes:
|
if self.volumes:
|
||||||
api_client = docker.APIClient(
|
api_client = docker.APIClient(
|
||||||
|
@ -545,7 +553,6 @@ class Repo2Docker(Application):
|
||||||
self.output_image_spec,
|
self.output_image_spec,
|
||||||
publish_all_ports=self.all_ports,
|
publish_all_ports=self.all_ports,
|
||||||
ports=ports,
|
ports=ports,
|
||||||
hostname=host_name,
|
|
||||||
detach=True,
|
detach=True,
|
||||||
command=run_cmd,
|
command=run_cmd,
|
||||||
volumes=container_volumes,
|
volumes=container_volumes,
|
||||||
|
|
|
@ -6,35 +6,40 @@ import sys
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
|
import urllib.parse
|
||||||
from repo2docker.app import Repo2Docker
|
from repo2docker.app import Repo2Docker
|
||||||
|
|
||||||
def test_env_yml(tmpdir):
|
def test_connect_url(tmpdir):
|
||||||
tmpdir.chdir()
|
tmpdir.chdir()
|
||||||
#q = tmpdir.join("environment.yml")
|
#q = tmpdir.join("environment.yml")
|
||||||
#q.write("dependencies:\n"
|
#q.write("dependencies:\n"
|
||||||
# " - notebook==5.6.0rc1")
|
# " - notebook==5.6.0")
|
||||||
p = tmpdir.join("requirements.txt")
|
p = tmpdir.join("requirements.txt")
|
||||||
p.write("notebook==5.6.0rc1")
|
p.write("notebook==5.6.0")
|
||||||
|
|
||||||
app = Repo2Docker()
|
app = Repo2Docker()
|
||||||
argv = [str(tmpdir), ]
|
argv = [str(tmpdir), ]
|
||||||
app.initialize(argv)
|
app.initialize(argv)
|
||||||
|
app.debug = True
|
||||||
app.run = False
|
app.run = False
|
||||||
app.start() # This just build the image and does not run it.
|
app.start() # This just build the image and does not run it.
|
||||||
container = app.start_container()
|
container = app.start_container()
|
||||||
port = app.port
|
container_url = 'http://{}:{}/api'.format(app.hostname, app.port)
|
||||||
hostname = app.hostname
|
expected_url = 'http://{}:{}'.format(app.hostname, app.port)
|
||||||
# wait a bit for the container to be ready
|
|
||||||
container_url = 'http://{}:{}/api'.format(hostname, port)
|
|
||||||
# wait a bit for the container to be ready
|
# wait a bit for the container to be ready
|
||||||
# give the container a chance to start
|
# give the container a chance to start
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# try a few times to connect
|
# try a few times to connect
|
||||||
success = False
|
success = False
|
||||||
for i in range(1, 4):
|
for i in range(1, 4):
|
||||||
container.reload()
|
container.reload()
|
||||||
assert container.status == 'running'
|
assert container.status == 'running'
|
||||||
|
if expected_url not in container.logs().decode("utf8"):
|
||||||
|
time.sleep(i * 3)
|
||||||
|
continue
|
||||||
try:
|
try:
|
||||||
info = requests.get(container_url).json()
|
info = requests.get(container_url).json()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Ładowanie…
Reference in New Issue