mirror of
				https://github.com/docker/compose.git
				synced 2025-10-31 11:14:02 +01:00 
			
		
		
		
	Merge pull request #33 from cameronmaske/recreate_containers
Patch for #32
This commit is contained in:
		
						commit
						ce8ef7afe7
					
				| @ -3,7 +3,7 @@ from __future__ import absolute_import | ||||
| 
 | ||||
| class Container(object): | ||||
|     """ | ||||
|     Represents a Docker container, constructed from the output of  | ||||
|     Represents a Docker container, constructed from the output of | ||||
|     GET /containers/:id:/json. | ||||
|     """ | ||||
|     def __init__(self, client, dictionary, has_been_inspected=False): | ||||
| @ -38,6 +38,10 @@ class Container(object): | ||||
|     def id(self): | ||||
|         return self.dictionary['ID'] | ||||
| 
 | ||||
|     @property | ||||
|     def image(self): | ||||
|         return self.dictionary['Image'] | ||||
| 
 | ||||
|     @property | ||||
|     def short_id(self): | ||||
|         return self.id[:10] | ||||
|  | ||||
| @ -141,12 +141,14 @@ class Service(object): | ||||
|         if container.is_running: | ||||
|             container.stop(timeout=1) | ||||
| 
 | ||||
|         intermediate_container = Container.create( | ||||
|             self.client, | ||||
|             image='ubuntu', | ||||
|             command='echo', | ||||
|             volumes_from=container.id, | ||||
|         ) | ||||
|         intermediate_container_options = { | ||||
|             'image': container.image, | ||||
|             'command': 'echo', | ||||
|             'volumes_from': container.id, | ||||
|             'entrypoint': None | ||||
|         } | ||||
|         intermediate_container = self.create_container( | ||||
|             one_off=True, **intermediate_container_options) | ||||
|         intermediate_container.start() | ||||
|         intermediate_container.wait() | ||||
|         container.remove() | ||||
| @ -212,7 +214,7 @@ class Service(object): | ||||
|         return links | ||||
| 
 | ||||
|     def _get_container_options(self, override_options, one_off=False): | ||||
|         keys = ['image', 'command', 'hostname', 'user', 'detach', 'stdin_open', 'tty', 'mem_limit', 'ports', 'environment', 'dns', 'volumes', 'volumes_from'] | ||||
|         keys = ['image', 'command', 'hostname', 'user', 'detach', 'stdin_open', 'tty', 'mem_limit', 'ports', 'environment', 'dns', 'volumes', 'volumes_from', 'entrypoint'] | ||||
|         container_options = dict((k, self.options[k]) for k in keys if k in self.options) | ||||
|         container_options.update(override_options) | ||||
| 
 | ||||
|  | ||||
| @ -110,8 +110,9 @@ class ServiceTest(DockerClientTestCase): | ||||
|         self.assertIn('/var/db', container.inspect()['Volumes']) | ||||
| 
 | ||||
|     def test_recreate_containers(self): | ||||
|         service = self.create_service('db', environment={'FOO': '1'}, volumes=['/var/db']) | ||||
|         service = self.create_service('db', environment={'FOO': '1'}, volumes=['/var/db'], entrypoint=['ps']) | ||||
|         old_container = service.create_container() | ||||
|         self.assertEqual(old_container.dictionary['Config']['Entrypoint'], ['ps']) | ||||
|         self.assertEqual(old_container.dictionary['Config']['Env'], ['FOO=1']) | ||||
|         self.assertEqual(old_container.name, 'figtest_db_1') | ||||
|         service.start_container(old_container) | ||||
| @ -120,11 +121,15 @@ class ServiceTest(DockerClientTestCase): | ||||
|         num_containers_before = len(self.client.containers(all=True)) | ||||
| 
 | ||||
|         service.options['environment']['FOO'] = '2' | ||||
|         (old, new) = service.recreate_containers() | ||||
|         self.assertEqual(len(old), 1) | ||||
|         (intermediate, new) = service.recreate_containers() | ||||
|         self.assertEqual(len(intermediate), 1) | ||||
|         self.assertEqual(len(new), 1) | ||||
| 
 | ||||
|         new_container = new[0] | ||||
|         intermediate_container = intermediate[0] | ||||
|         self.assertEqual(intermediate_container.dictionary['Config']['Entrypoint'], None) | ||||
| 
 | ||||
|         self.assertEqual(new_container.dictionary['Config']['Entrypoint'], ['ps']) | ||||
|         self.assertEqual(new_container.dictionary['Config']['Env'], ['FOO=2']) | ||||
|         self.assertEqual(new_container.name, 'figtest_db_1') | ||||
|         service.start_container(new_container) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user