From 376389d7a5fdc29da56e79125728a6b4b071df67 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Mon, 28 Aug 2017 17:35:55 -0700 Subject: [PATCH] Add --no-start flag to up command. Deprecate create command. Signed-off-by: Joffrey F --- compose/cli/main.py | 18 ++++++++++++++++-- compose/project.py | 6 ++++-- tests/acceptance/cli_test.py | 25 +++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/compose/cli/main.py b/compose/cli/main.py index 83bc7d58c..21bf1f308 100644 --- a/compose/cli/main.py +++ b/compose/cli/main.py @@ -319,6 +319,7 @@ class TopLevelCommand(object): def create(self, options): """ Creates containers for a service. + This command is deprecated. Use the `up` command with `--no-start` instead. Usage: create [options] [SERVICE...] @@ -332,6 +333,11 @@ class TopLevelCommand(object): """ service_names = options['SERVICE'] + log.warn( + 'The create command is deprecated. ' + 'Use the up command with the --no-start flag instead.' + ) + self.project.create( service_names=service_names, strategy=convergence_strategy_from_opts(options), @@ -902,6 +908,7 @@ class TopLevelCommand(object): --no-recreate If containers already exist, don't recreate them. Incompatible with --force-recreate. --no-build Don't build an image, even if it's missing. + --no-start Don't start the services after creating them. --build Build images before starting containers. --abort-on-container-exit Stops all containers if any container was stopped. Incompatible with -d. @@ -922,10 +929,16 @@ class TopLevelCommand(object): timeout = timeout_from_opts(options) remove_orphans = options['--remove-orphans'] detached = options.get('-d') + no_start = options.get('--no-start') - if detached and cascade_stop: + if detached and (cascade_stop or exit_value_from): raise UserError("--abort-on-container-exit and -d cannot be combined.") + if no_start: + for excluded in ['-d', '--abort-on-container-exit', '--exit-code-from']: + if options.get(excluded): + raise UserError('--no-start and {} cannot be combined.'.format(excluded)) + with up_shutdown_context(self.project, service_names, timeout, detached): to_attach = self.project.up( service_names=service_names, @@ -936,9 +949,10 @@ class TopLevelCommand(object): detached=detached, remove_orphans=remove_orphans, scale_override=parse_scale_args(options['--scale']), + start=not no_start ) - if detached: + if detached or no_start: return attached_containers = filter_containers_to_service_names(to_attach, service_names) diff --git a/compose/project.py b/compose/project.py index 2310a2fcc..c8b57edd2 100644 --- a/compose/project.py +++ b/compose/project.py @@ -412,7 +412,8 @@ class Project(object): detached=False, remove_orphans=False, scale_override=None, - rescale=True): + rescale=True, + start=True): warn_for_swarm_mode(self.client) @@ -436,7 +437,8 @@ class Project(object): timeout=timeout, detached=detached, scale_override=scale_override.get(service.name), - rescale=rescale + rescale=rescale, + start=start ) def get_deps(service): diff --git a/tests/acceptance/cli_test.py b/tests/acceptance/cli_test.py index e721b940f..3a5e17ad8 100644 --- a/tests/acceptance/cli_test.py +++ b/tests/acceptance/cli_test.py @@ -776,6 +776,31 @@ class CLITestCase(DockerClientTestCase): for service in services: assert self.lookup(container, service.name) + @v2_only() + def test_up_no_start(self): + self.base_dir = 'tests/fixtures/v2-full' + self.dispatch(['up', '--no-start'], None) + + services = self.project.get_services() + + default_network = self.project.networks.networks['default'].full_name + front_network = self.project.networks.networks['front'].full_name + networks = self.client.networks(names=[default_network, front_network]) + assert len(networks) == 2 + + for service in services: + containers = service.containers(stopped=True) + assert len(containers) == 1 + + container = containers[0] + assert not container.is_running + assert container.get('State.Status') == 'created' + + volumes = self.project.volumes.volumes + assert 'data' in volumes + volume = volumes['data'] + assert volume.exists() + @v2_only() def test_up_no_ansi(self): self.base_dir = 'tests/fixtures/v2-simple'