Prevent docker-compose scale to be used with a v2.2 config file

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2017-04-19 16:47:43 -07:00
parent afb2b6c51c
commit 2ba4e5e8ec
6 changed files with 61 additions and 24 deletions

View file

@ -26,6 +26,7 @@ from ..config import resolve_build_args
from ..config.environment import Environment
from ..config.serialize import serialize_config
from ..config.types import VolumeSpec
from ..const import COMPOSEFILE_V2_2 as V2_2
from ..const import IS_WINDOWS_PLATFORM
from ..errors import StreamParseError
from ..progress_stream import StreamOutputError
@ -771,6 +772,12 @@ class TopLevelCommand(object):
"""
timeout = timeout_from_opts(options)
if self.project.config_version == V2_2:
raise UserError(
'The scale command is incompatible with the v2.2 format. '
'Use the up command with the --scale flag instead.'
)
for service_name, num in parse_scale_args(options['SERVICE=NUM']).items():
self.project.get_service(service_name).scale(num, timeout=timeout)

View file

@ -57,12 +57,13 @@ class Project(object):
"""
A collection of services.
"""
def __init__(self, name, services, client, networks=None, volumes=None):
def __init__(self, name, services, client, networks=None, volumes=None, config_version=None):
self.name = name
self.services = services
self.client = client
self.volumes = volumes or ProjectVolumes({})
self.networks = networks or ProjectNetworks({}, False)
self.config_version = config_version
def labels(self, one_off=OneOffFilter.exclude):
labels = ['{0}={1}'.format(LABEL_PROJECT, self.name)]
@ -82,7 +83,7 @@ class Project(object):
networks,
use_networking)
volumes = ProjectVolumes.from_config(name, config_data, client)
project = cls(name, [], client, project_networks, volumes)
project = cls(name, [], client, project_networks, volumes, config_data.version)
for service_dict in config_data.services:
service_dict = dict(service_dict)

View file

@ -383,8 +383,8 @@ class Service(object):
lambda n: self.get_container_name(n),
"Creating"
)
if errors:
raise OperationFailedError(errors.values()[0])
for error in errors.values():
raise OperationFailedError(error)
return containers
@ -404,8 +404,9 @@ class Service(object):
lambda c: c.name,
"Recreating"
)
if errors:
raise OperationFailedError(errors.values()[0])
for error in errors.values():
raise OperationFailedError(error)
if len(containers) < scale:
containers.extend(self._execute_convergence_create(
scale - len(containers), detached, start
@ -424,8 +425,8 @@ class Service(object):
"Starting"
)
if errors:
raise OperationFailedError(errors.values()[0])
for error in errors.values():
raise OperationFailedError(error)
if len(containers) < scale:
containers.extend(self._execute_convergence_create(