mirror of
https://github.com/docker/compose.git
synced 2025-07-06 13:24:25 +02:00
Remove unused intermediate_container from return value.
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
parent
4827e60641
commit
26f45efea2
@ -176,18 +176,14 @@ class Project(object):
|
|||||||
do_build=True):
|
do_build=True):
|
||||||
running_containers = []
|
running_containers = []
|
||||||
for service in self.get_services(service_names, include_links=start_links):
|
for service in self.get_services(service_names, include_links=start_links):
|
||||||
if recreate:
|
create_func = (service.recreate_containers if recreate
|
||||||
for (_, container) in service.recreate_containers(
|
else service.start_or_create_containers)
|
||||||
insecure_registry=insecure_registry,
|
|
||||||
|
for container in create_func(
|
||||||
|
insecure_registry=insecure_registry,
|
||||||
detach=detach,
|
detach=detach,
|
||||||
do_build=do_build):
|
do_build=do_build):
|
||||||
running_containers.append(container)
|
running_containers.append(container)
|
||||||
else:
|
|
||||||
for container in service.start_or_create_containers(
|
|
||||||
insecure_registry=insecure_registry,
|
|
||||||
detach=detach,
|
|
||||||
do_build=do_build):
|
|
||||||
running_containers.append(container)
|
|
||||||
|
|
||||||
return running_containers
|
return running_containers
|
||||||
|
|
||||||
|
@ -242,8 +242,9 @@ class Service(object):
|
|||||||
|
|
||||||
def recreate_containers(self, insecure_registry=False, do_build=True, **override_options):
|
def recreate_containers(self, insecure_registry=False, do_build=True, **override_options):
|
||||||
"""
|
"""
|
||||||
If a container for this service doesn't exist, create and start one. If there are
|
If a container for this service doesn't exist, create and start one. If
|
||||||
any, stop them, create+start new ones, and remove the old containers.
|
there are any, stop them, create+start new ones, and remove the old
|
||||||
|
containers.
|
||||||
"""
|
"""
|
||||||
containers = self.containers(stopped=True)
|
containers = self.containers(stopped=True)
|
||||||
if not containers:
|
if not containers:
|
||||||
@ -253,21 +254,22 @@ class Service(object):
|
|||||||
do_build=do_build,
|
do_build=do_build,
|
||||||
**override_options)
|
**override_options)
|
||||||
self.start_container(container)
|
self.start_container(container)
|
||||||
return [(None, container)]
|
return [container]
|
||||||
else:
|
else:
|
||||||
tuples = []
|
return [
|
||||||
|
self.recreate_container(
|
||||||
for c in containers:
|
container,
|
||||||
log.info("Recreating %s..." % c.name)
|
insecure_registry=insecure_registry,
|
||||||
tuples.append(self.recreate_container(c, insecure_registry=insecure_registry, **override_options))
|
**override_options)
|
||||||
|
for container in containers
|
||||||
return tuples
|
]
|
||||||
|
|
||||||
def recreate_container(self, container, **override_options):
|
def recreate_container(self, container, **override_options):
|
||||||
"""Recreate a container. An intermediate container is created so that
|
"""Recreate a container. An intermediate container is created so that
|
||||||
the new container has the same name, while still supporting
|
the new container has the same name, while still supporting
|
||||||
`volumes-from` the original container.
|
`volumes-from` the original container.
|
||||||
"""
|
"""
|
||||||
|
log.info("Recreating %s..." % container.name)
|
||||||
try:
|
try:
|
||||||
container.stop()
|
container.stop()
|
||||||
except APIError as e:
|
except APIError as e:
|
||||||
@ -295,7 +297,7 @@ class Service(object):
|
|||||||
|
|
||||||
intermediate_container.remove()
|
intermediate_container.remove()
|
||||||
|
|
||||||
return (intermediate_container, new_container)
|
return new_container
|
||||||
|
|
||||||
def start_container_if_stopped(self, container, **options):
|
def start_container_if_stopped(self, container, **options):
|
||||||
if container.is_running:
|
if container.is_running:
|
||||||
|
@ -148,30 +148,23 @@ class ServiceTest(DockerClientTestCase):
|
|||||||
self.assertIn('FOO=1', old_container.dictionary['Config']['Env'])
|
self.assertIn('FOO=1', old_container.dictionary['Config']['Env'])
|
||||||
self.assertEqual(old_container.name, 'figtest_db_1')
|
self.assertEqual(old_container.name, 'figtest_db_1')
|
||||||
service.start_container(old_container)
|
service.start_container(old_container)
|
||||||
volume_path = old_container.inspect()['Volumes']['/etc']
|
volume_path = old_container.get('Volumes')['/etc']
|
||||||
|
|
||||||
num_containers_before = len(self.client.containers(all=True))
|
num_containers_before = len(self.client.containers(all=True))
|
||||||
|
|
||||||
service.options['environment']['FOO'] = '2'
|
service.options['environment']['FOO'] = '2'
|
||||||
tuples = service.recreate_containers()
|
containers = service.recreate_containers()
|
||||||
self.assertEqual(len(tuples), 1)
|
self.assertEqual(len(containers), 1)
|
||||||
|
|
||||||
intermediate_container = tuples[0][0]
|
new_container = containers[0]
|
||||||
new_container = tuples[0][1]
|
self.assertEqual(new_container.get('Config.Entrypoint'), ['sleep'])
|
||||||
self.assertEqual(intermediate_container.dictionary['Config']['Entrypoint'], ['/bin/echo'])
|
self.assertEqual(new_container.get('Config.Cmd'), ['300'])
|
||||||
|
self.assertIn('FOO=2', new_container.get('Config.Env'))
|
||||||
self.assertEqual(new_container.dictionary['Config']['Entrypoint'], ['sleep'])
|
|
||||||
self.assertEqual(new_container.dictionary['Config']['Cmd'], ['300'])
|
|
||||||
self.assertIn('FOO=2', new_container.dictionary['Config']['Env'])
|
|
||||||
self.assertEqual(new_container.name, 'figtest_db_1')
|
self.assertEqual(new_container.name, 'figtest_db_1')
|
||||||
self.assertEqual(new_container.inspect()['Volumes']['/etc'], volume_path)
|
self.assertEqual(new_container.get('Volumes')['/etc'], volume_path)
|
||||||
self.assertIn(intermediate_container.id, new_container.dictionary['HostConfig']['VolumesFrom'])
|
|
||||||
|
|
||||||
self.assertEqual(len(self.client.containers(all=True)), num_containers_before)
|
self.assertEqual(len(self.client.containers(all=True)), num_containers_before)
|
||||||
self.assertNotEqual(old_container.id, new_container.id)
|
self.assertNotEqual(old_container.id, new_container.id)
|
||||||
self.assertRaises(APIError,
|
|
||||||
self.client.inspect_container,
|
|
||||||
intermediate_container.id)
|
|
||||||
|
|
||||||
def test_recreate_containers_when_containers_are_stopped(self):
|
def test_recreate_containers_when_containers_are_stopped(self):
|
||||||
service = self.create_service(
|
service = self.create_service(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user