Skip to content

Commit

Permalink
Fix GIE launch for cases when the published port isn't available
Browse files Browse the repository at this point in the history
immediately (seems to happen with Swarm Mode occasionally)
  • Loading branch information
natefoo committed Mar 12, 2018
1 parent 83fa18d commit d632b41
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
14 changes: 12 additions & 2 deletions lib/galaxy/containers/docker_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ def ports(self):
# }
# ]
rval = []
port_mappings = self.inspect[0]['NetworkSettings']['Ports']
try:
port_mappings = self.inspect[0]['NetworkSettings']['Ports']
except (IndexError, KeyError) as exc:
log.warning("Failed to get ports for container %s from `docker inspect` output at "
"[0]['NetworkSettings']['Ports']: %s: %s", self.id, exc.__class__.__name__, str(exc))
return None
for port_name in port_mappings:
for binding in port_mappings[port_name]:
rval.append(ContainerPort(
Expand Down Expand Up @@ -165,7 +170,12 @@ def ports(self):
# }
# ]
rval = []
port_mappings = self.inspect[0]['Endpoint']['Ports']
try:
port_mappings = self.inspect[0]['Endpoint']['Ports']
except (IndexError, KeyError) as exc:
log.warning("Failed to get ports for container %s from `docker service inspect` output at "
"[0]['Endpoint']['Ports']: %s: %s", self.id, exc.__class__.__name__, str(exc))
return None
for binding in port_mappings:
rval.append(ContainerPort(
binding['TargetPort'],
Expand Down
16 changes: 15 additions & 1 deletion lib/galaxy/visualization/plugins/interactive_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import stat
import string
import tempfile
import time
import uuid
from itertools import product
from subprocess import PIPE, Popen
Expand Down Expand Up @@ -442,7 +443,20 @@ def _launch_container_interface(self, image, env_override, volumes):
"""
run_args = self.container_run_args(image, env_override, volumes)
container = self.attr.container_interface.run_in_container(None, **run_args)
container_port = self._find_port_mapping(container.ports)
attempt = 0
container_ports = container.ports
while container_ports is None and attempt < 30:
# TODO: it would be better to do this in /interactive_environments/ready so the client doesn't block here,
# but _find_port_mapping needs certain non-persisted data (the port configured to be published) and the
# proxy manager doesn't have an update method, so that'd require bigger changes than I have the time for
# right now
attempt += 1
log.warning("Sleeping for 2 seconds while waiting for container %s ports", container.id)
time.sleep(2)
container_ports = container.ports
if container_ports is None:
raise Exception("Failed to determine ports for container '%s' after 30 attempts" % container.id)
container_port = self._find_port_mapping(container_ports)
log.debug("Container '%s' accessible at: %s:%s", container.id, container_port.hostaddr, container_port.hostport)
self.attr.proxy_request = self.trans.app.proxy_manager.setup_proxy(
self.trans,
Expand Down

0 comments on commit d632b41

Please sign in to comment.