mirror of https://github.com/docker/compose.git
Merge pull request #1437 from dnephin/fix_project_containers
Project.containers with service_names
This commit is contained in:
commit
b183a66db1
|
@ -6,7 +6,7 @@ from functools import reduce
|
|||
from docker.errors import APIError
|
||||
|
||||
from .config import get_service_name_from_net, ConfigurationError
|
||||
from .const import LABEL_PROJECT, LABEL_ONE_OFF
|
||||
from .const import LABEL_PROJECT, LABEL_SERVICE, LABEL_ONE_OFF
|
||||
from .service import Service, check_for_legacy_containers
|
||||
from .container import Container
|
||||
|
||||
|
@ -276,6 +276,11 @@ class Project(object):
|
|||
all=stopped,
|
||||
filters={'label': self.labels(one_off=one_off)})]
|
||||
|
||||
def matches_service_names(container):
|
||||
if not service_names:
|
||||
return True
|
||||
return container.labels.get(LABEL_SERVICE) in service_names
|
||||
|
||||
if not containers:
|
||||
check_for_legacy_containers(
|
||||
self.client,
|
||||
|
@ -284,7 +289,7 @@ class Project(object):
|
|||
stopped=stopped,
|
||||
one_off=one_off)
|
||||
|
||||
return containers
|
||||
return filter(matches_service_names, containers)
|
||||
|
||||
def _inject_deps(self, acc, service):
|
||||
dep_names = service.get_dependency_names()
|
||||
|
|
|
@ -6,6 +6,29 @@ from .testcases import DockerClientTestCase
|
|||
|
||||
|
||||
class ProjectTest(DockerClientTestCase):
|
||||
|
||||
def test_containers(self):
|
||||
web = self.create_service('web')
|
||||
db = self.create_service('db')
|
||||
project = Project('composetest', [web, db], self.client)
|
||||
|
||||
project.up()
|
||||
|
||||
containers = project.containers()
|
||||
self.assertEqual(len(containers), 2)
|
||||
|
||||
def test_containers_with_service_names(self):
|
||||
web = self.create_service('web')
|
||||
db = self.create_service('db')
|
||||
project = Project('composetest', [web, db], self.client)
|
||||
|
||||
project.up()
|
||||
|
||||
containers = project.containers(['web'])
|
||||
self.assertEqual(
|
||||
[c.name for c in containers],
|
||||
['composetest_web_1'])
|
||||
|
||||
def test_volumes_from_service(self):
|
||||
service_dicts = config.from_dictionary({
|
||||
'data': {
|
||||
|
|
Loading…
Reference in New Issue