Skip to content

Commit

Permalink
introduce a config option to not auto-up services
Browse files Browse the repository at this point in the history
This is a PoC implementation of solution 2) from docker#1896:
It adds the config option "auto_up" as boolean to mark a service to not
start by default when calling "docker-compose up" but instead only when
given explicitly or pulled in as a dependency of another service.

TODO: update tests and comments for changed functions

Signed-off-by: Roman Anasal <roman.anasal@academyconsult.de>
  • Loading branch information
acran committed Sep 18, 2016
1 parent 1d03baa commit 514cad9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions compose/config/config_schema_v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"type": "object",

"properties": {
"auto_up": {"type": "boolean"},
"build": {"type": "string"},
"cap_add": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"cap_drop": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
Expand Down
1 change: 1 addition & 0 deletions compose/config/config_schema_v2.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"type": "object",

"properties": {
"auto_up": {"type": "boolean"},
"build": {
"oneOf": [
{"type": "string"},
Expand Down
19 changes: 13 additions & 6 deletions compose/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def validate_service_names(self, service_names):
if name not in valid_names:
raise NoSuchService(name)

def get_services(self, service_names=None, include_deps=False):
def get_services(self, service_names=None, include_deps=False, auto_up_only=False):
"""
Returns a list of this project's services filtered
by the provided list of names, or all services if service_names is None
Expand All @@ -161,9 +161,15 @@ def get_services(self, service_names=None, include_deps=False):
"""
if service_names is None or len(service_names) == 0:
service_names = self.service_names
else:
auto_up_only = False

unsorted = [self.get_service(name) for name in service_names]
services = [s for s in self.services if s in unsorted]
services = [
s
for s in self.services
if s in unsorted and (not auto_up_only or s.options.get('auto_up', True))
]

if include_deps:
services = reduce(self._inject_deps, services, [])
Expand All @@ -173,8 +179,8 @@ def get_services(self, service_names=None, include_deps=False):

return uniques

def get_services_without_duplicate(self, service_names=None, include_deps=False):
services = self.get_services(service_names, include_deps)
def get_services_without_duplicate(self, service_names=None, include_deps=False, auto_up_only=False):
services = self.get_services(service_names, include_deps, auto_up_only)
for service in services:
service.remove_duplicate_containers()
return services
Expand Down Expand Up @@ -307,7 +313,7 @@ def create(
strategy=ConvergenceStrategy.changed,
do_build=BuildAction.none,
):
services = self.get_services_without_duplicate(service_names, include_deps=True)
services = self.get_services_without_duplicate(service_names, include_deps=True, auto_up_only=True)

for svc in services:
svc.ensure_image_exists(do_build=do_build)
Expand Down Expand Up @@ -376,7 +382,8 @@ def up(self,

services = self.get_services_without_duplicate(
service_names,
include_deps=start_deps)
include_deps=start_deps,
auto_up_only=True)

for svc in services:
svc.ensure_image_exists(do_build=do_build)
Expand Down
9 changes: 9 additions & 0 deletions docs/compose-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ full details.
This section contains a list of all configuration options supported by a service
definition.

### auto_up

Specify whether a service should be started by `docker-compose up` by default.

When set to `false` the service is only started when pulled in as a dependency by
another service or explicitly given on the command line. Otherwise the service is
also started when simply executing `docker-compose up`.
When not given this option defaults to `true`.

### build

Configuration options that are applied at build time.
Expand Down

0 comments on commit 514cad9

Please sign in to comment.