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 docs, tests and comments for changed functions
  • Loading branch information
acran committed Feb 29, 2016
1 parent 1502c5a commit 329bf36
Show file tree
Hide file tree
Showing 3 changed files with 11 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
15 changes: 9 additions & 6 deletions compose/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,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 @@ -140,9 +140,11 @@ 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 @@ -152,8 +154,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 @@ -250,7 +252,7 @@ def build(self, service_names=None, no_cache=False, pull=False, force_rm=False):
log.info('%s uses an image, skipping' % service.name)

def create(self, service_names=None, strategy=ConvergenceStrategy.changed, do_build=True):
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)

plans = self._get_convergence_plans(services, strategy)

Expand Down Expand Up @@ -305,7 +307,8 @@ def up(self,
self.initialize()
services = self.get_services_without_duplicate(
service_names,
include_deps=start_deps)
include_deps=start_deps,
auto_up_only=True)

plans = self._get_convergence_plans(services, strategy)
return [
Expand Down

0 comments on commit 329bf36

Please sign in to comment.