kopia lustrzana https://github.com/jupyterhub/repo2docker
Explicit hostname supplied to the container
rodzic
0709c0a656
commit
1512a6835a
|
@ -18,6 +18,7 @@ import tempfile
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import docker
|
import docker
|
||||||
|
from urllib.parse import urlparse
|
||||||
from docker.utils import kwargs_from_env
|
from docker.utils import kwargs_from_env
|
||||||
from docker.errors import DockerException
|
from docker.errors import DockerException
|
||||||
import escapism
|
import escapism
|
||||||
|
@ -517,6 +518,14 @@ class Repo2Docker(Application):
|
||||||
ports = {}
|
ports = {}
|
||||||
# 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(
|
||||||
|
@ -536,6 +545,7 @@ 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,
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
"""
|
||||||
|
Test if the environment.yml is empty or it constains other data structure than a dictionary
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import pytest
|
||||||
|
import requests
|
||||||
|
import time
|
||||||
|
from repo2docker.app import Repo2Docker
|
||||||
|
|
||||||
|
def test_env_yml(tmpdir):
|
||||||
|
tmpdir.chdir()
|
||||||
|
#q = tmpdir.join("environment.yml")
|
||||||
|
#q.write("dependencies:\n"
|
||||||
|
# " - notebook==5.6.0rc1")
|
||||||
|
p = tmpdir.join("requirements.txt")
|
||||||
|
p.write("notebook==5.6.0rc1")
|
||||||
|
|
||||||
|
app = Repo2Docker()
|
||||||
|
argv = [str(tmpdir), ]
|
||||||
|
app.initialize(argv)
|
||||||
|
app.run = False
|
||||||
|
app.start() # This just build the image and does not run it.
|
||||||
|
detect = app.build
|
||||||
|
print("app.build",detect)
|
||||||
|
container = app.start_container()
|
||||||
|
port = app.port
|
||||||
|
print("port in test", port)
|
||||||
|
hostname = app.hostname
|
||||||
|
# wait a bit for the container to be ready
|
||||||
|
container_url = 'http://{}:{}/api'.format(hostname, port)
|
||||||
|
print("print container url",container_url)
|
||||||
|
# wait a bit for the container to be ready
|
||||||
|
# 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)
|
Ładowanie…
Reference in New Issue