Browse Source

Updated recreate_containers to attempt to base intermediate container's the previous container's image.
Added in additional functionality to reset any entrypoints for the intermediate container and pull/retry handling if the image does not exist.
Updated test coverage to check if an container is recreated with an entrypoint it is handled correctly.

Cameron Maske 12 years ago
parent
commit
62bba1684b
3 changed files with 22 additions and 11 deletions
  1. 5 1
      fig/container.py
  2. 9 7
      fig/service.py
  3. 8 3
      tests/service_test.py

+ 5 - 1
fig/container.py

@@ -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]

+ 9 - 7
fig/service.py

@@ -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)
 

+ 8 - 3
tests/service_test.py

@@ -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)