Procházet zdrojové kódy

Handle missing (not built) service image in config --hash

Signed-off-by: Joffrey F <[email protected]>
Joffrey F před 7 roky
rodič
revize
ee878aee4c
3 změnil soubory, kde provedl 10 přidání a 5 odebrání
  1. 3 3
      compose/cli/main.py
  2. 7 1
      compose/service.py
  3. 0 1
      tests/acceptance/cli_test.py

+ 3 - 3
compose/cli/main.py

@@ -356,9 +356,9 @@ class TopLevelCommand(object):
             h = options['--hash']
             self.project = project_from_options('.', self.toplevel_options)
             services = [svc for svc in options['--hash'].split(',')] if h != '*' else None
-
-            for service in self.project.get_services(services):
-                print('{} {}'.format(service.name, service.config_hash))
+            with errors.handle_connection_errors(self.project.client):
+                for service in self.project.get_services(services):
+                    print('{} {}'.format(service.name, service.config_hash))
             return
 
         print(serialize_config(compose_config, image_digests))

+ 7 - 1
compose/service.py

@@ -656,9 +656,15 @@ class Service(object):
         return json_hash(self.config_dict())
 
     def config_dict(self):
+        def image_id():
+            try:
+                return self.image()['Id']
+            except NoSuchImageError:
+                return None
+
         return {
             'options': self.options,
-            'image_id': self.image()['Id'],
+            'image_id': image_id(),
             'links': self.get_link_names(),
             'net': self.network_mode.id,
             'networks': self.networks,

+ 0 - 1
tests/acceptance/cli_test.py

@@ -224,7 +224,6 @@ class CLITestCase(DockerClientTestCase):
 
     def test_config_with_hash_option(self):
         self.base_dir = 'tests/fixtures/v2-full'
-        self.project.build()
         result = self.dispatch(['config', '--hash=*'])
         for service in self.project.get_services():
             assert '{} {}\n'.format(service.name, service.config_hash) in result.stdout