mirror of https://github.com/docker/compose.git
Reduce complexity of _get_container_create_options
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
38dd342b7b
commit
84a1822e40
|
@ -566,8 +566,7 @@ class Service(object):
|
|||
elif not container_options.get('name'):
|
||||
container_options['name'] = self.get_container_name(number, one_off)
|
||||
|
||||
if 'detach' not in container_options:
|
||||
container_options['detach'] = True
|
||||
container_options.setdefault('detach', True)
|
||||
|
||||
# If a qualified hostname was given, split it into an
|
||||
# unqualified hostname and a domainname unless domainname
|
||||
|
@ -581,16 +580,9 @@ class Service(object):
|
|||
container_options['domainname'] = parts[2]
|
||||
|
||||
if 'ports' in container_options or 'expose' in self.options:
|
||||
ports = []
|
||||
all_ports = container_options.get('ports', []) + self.options.get('expose', [])
|
||||
for port_range in all_ports:
|
||||
internal_range, _ = split_port(port_range)
|
||||
for port in internal_range:
|
||||
port = str(port)
|
||||
if '/' in port:
|
||||
port = tuple(port.split('/'))
|
||||
ports.append(port)
|
||||
container_options['ports'] = ports
|
||||
container_options['ports'] = build_container_ports(
|
||||
container_options,
|
||||
self.options)
|
||||
|
||||
container_options['environment'] = merge_environment(
|
||||
self.options.get('environment'),
|
||||
|
@ -1031,3 +1023,18 @@ def format_environment(environment):
|
|||
return key
|
||||
return '{key}={value}'.format(key=key, value=value)
|
||||
return [format_env(*item) for item in environment.items()]
|
||||
|
||||
# Ports
|
||||
|
||||
|
||||
def build_container_ports(container_options, options):
|
||||
ports = []
|
||||
all_ports = container_options.get('ports', []) + options.get('expose', [])
|
||||
for port_range in all_ports:
|
||||
internal_range, _ = split_port(port_range)
|
||||
for port in internal_range:
|
||||
port = str(port)
|
||||
if '/' in port:
|
||||
port = tuple(port.split('/'))
|
||||
ports.append(port)
|
||||
return ports
|
||||
|
|
Loading…
Reference in New Issue