Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "Gateway" from docker inspect as default docker_hostname #1770

Merged
merged 4 commits into from
Feb 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/galaxy/visualization/plugins/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class InteractiveEnvironmentPlugin( VisualizationPlugin ):
"""
Serves web-based REPLs such as IPython and RStudio.
"""
INTENV_REQUEST_FACTORY = interactive_environments.InteractiveEnviornmentRequest
INTENV_REQUEST_FACTORY = interactive_environments.InteractiveEnvironmentRequest

def __init__( self, app, path, name, config, context=None, **kwargs ):
# TODO: this is a hack until we can get int envs seperated from the vis reg and into their own framework
Expand Down
45 changes: 33 additions & 12 deletions lib/galaxy/web/base/interactive_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
log = logging.getLogger(__name__)


class InteractiveEnviornmentRequest(object):
class InteractiveEnvironmentRequest(object):

def __init__(self, trans, plugin):
self.trans = trans
Expand Down Expand Up @@ -218,8 +218,12 @@ def launch(self, raw_cmd=None, env_override={}, volumes=[]):
log.error( "%s\n%s" % (stdout, stderr) )
return None
else:
log.debug( "Container id: %s" % stdout)
port_mappings = self.get_proxied_ports(stdout)
container_id = stdout
log.debug( "Container id: %s" % container_id)
inspect_data = self.inspect_container(container_id)
port_mappings = self.get_container_port_mapping(inspect_data)
if self.attr.docker_hostname == 'localhost':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm ok with this, since it only affects situations in which docker_hostname is localhost, so none of the ones that @bgruening or @natefoo encounter where docker is isolated on another host, but I'd rather they chime in since it affects them as well.

self.attr.docker_hostname = self.get_container_gateway_ip(inspect_data)
if len(port_mappings) > 1:
log.warning("Don't know how to handle proxies to containers with multiple exposed ports. Arbitrarily choosing first")
elif len(port_mappings) == 0:
Expand Down Expand Up @@ -247,19 +251,13 @@ def launch(self, raw_cmd=None, env_override={}, volumes=[]):
# go through the proxy we ship.
# self.attr.PORT = self.attr.proxy_request[ 'proxied_port' ]

def get_proxied_ports(self, container_id):
"""Run docker inspect on a container to figure out which ports were
mapped where.
def inspect_container(self, container_id):
"""Runs docker inspect on a container and returns json response as python dictionary inspect_data.

:type container_id: str
:param container_id: a docker container ID

:returns: a list of triples containing (internal_port, external_ip,
external_port), of which the ports are probably the only
useful information.

Someday code that calls this should be refactored whenever we get
containers with multiple ports working.
:returns: inspect_data, a dict of docker inspect output
"""
command = self.attr.viz_config.get("docker", "command")
command = command.format(docker_args="inspect %s" % container_id)
Expand All @@ -284,6 +282,29 @@ def get_proxied_ports(self, container_id):
# "HostPort" : "3306"
# }
# ]
return inspect_data

def get_container_gateway_ip(self, inspect_data):
"""
Returns gateway ip from inspect_data
:type inspect_data: dict
:param inspect_data: output of docker inspect
:returns: gateway_ip
"""
gateway_ip = inspect_data[0]['NetworkSettings']['Gateway']
return gateway_ip

def get_container_port_mapping(self, inspect_data):
"""
:type inspect_data: dict
:param inspect_data: output of docker inspect
:returns: a list of triples containing (internal_port, external_ip,
external_port), of which the ports are probably the only
useful information.

Someday code that calls this should be refactored whenever we get
containers with multiple ports working.
"""
mappings = []
port_mappings = inspect_data[0]['NetworkSettings']['Ports']
for port_name in port_mappings:
Expand Down