Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b60ee3a

Browse files
committedJul 8, 2015
Fix can_be_scaled() to use docker-py's split_port()
... to determine if there are any external port bindings, to in-turn determine if the service is scalable. Signed-off-by: Viranch Mehta <viranch.mehta@gmail.com>
1 parent 157bbfe commit b60ee3a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed
 

‎compose/service.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import six
1010
from docker.errors import APIError
11-
from docker.utils import create_host_config, LogConfig
11+
from docker.utils import create_host_config, LogConfig, ports
1212

1313
from . import __version__
1414
from .config import DOCKER_CONFIG_KEYS, merge_environment
@@ -678,10 +678,21 @@ def labels(self, one_off=False):
678678
]
679679

680680
def can_be_scaled(self):
681-
for port in self.options.get('ports', []):
682-
if ':' in str(port):
681+
# TODO: this function should ideally move to docker.utils.ports
682+
# get rid of it once its accepted into docker-py
683+
def has_external_port(external_binding):
684+
if external_binding is None:
683685
return False
684-
return True
686+
if isinstance(external_binding, tuple) and \
687+
(len(external_binding) < 2 or external_binding[1] is None):
688+
return False
689+
return True
690+
691+
return not any(
692+
has_external_port(external_binding)
693+
for binding in self.options.get('ports', [])
694+
for external_binding in (ports.split_port(binding)[1] or [])
695+
)
685696

686697
def pull(self, insecure_registry=False):
687698
if 'image' not in self.options:

0 commit comments

Comments
 (0)
Please sign in to comment.