docker_compose_v2: work around bug in docker compose images --format json (#1083)

* Work around ubg in docker compose images --format json.

* ContainerName is no longer in image record.
This commit is contained in:
Felix Fontein 2025-06-07 23:28:51 +02:00 committed by GitHub
parent 72d827a9e2
commit 8ecbd9a5cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 21 additions and 4 deletions

View File

@ -0,0 +1,4 @@
bugfixes:
- "docker_compose_v2 - handle a (potentially unintentional) breaking change in Docker Compose 2.37.0.
Note that ``ContainerName`` is no longer part of the return value
(https://github.com/ansible-collections/community.docker/issues/1082, https://github.com/ansible-collections/community.docker/pull/1083)."

View File

@ -818,6 +818,11 @@ class BaseComposeManager(DockerBaseClass):
rc, images, stderr = self.client.call_cli_json(*args, **kwargs)
if self.use_json_events and rc != 0:
self._handle_failed_cli_call(args, rc, images, stderr)
if isinstance(images, dict):
# Handle breaking change in Docker Compose 2.37.0; see
# https://github.com/ansible-collections/community.docker/issues/1082
# and https://github.com/docker/compose/issues/12916 for details
images = list(images.values())
return images
def parse_events(self, stderr, dry_run=False, nonzero_rc=False):

View File

@ -111,7 +111,9 @@
- present_1.containers | length == 1
- present_1.containers[0].Name == (pname ~ '-' ~ cname ~ '-1')
- present_1.images | length == 1
- present_1.images[0].ContainerName == (pname ~ '-' ~ cname ~ '-1')
- >-
docker_compose_version is version('2.37.0', '==') or
present_1.images[0].ContainerName == (pname ~ '-' ~ cname ~ '-1')
- present_1.images[0].Repository == iname
- present_1.images[0].Tag == "latest"
- present_1.warnings | default([]) | select('regex', ' Please report this at ') | length == 0

View File

@ -62,7 +62,9 @@
- present_1.containers[0].State == 'exited'
- present_1.containers[0].ExitCode == 0
- present_1.images | length == 1
- present_1.images[0].ContainerName == (pname ~ '-' ~ cname ~ '-1')
- >-
docker_compose_version is version('2.37.0', '==') or
present_1.images[0].ContainerName == (pname ~ '-' ~ cname ~ '-1')
- present_1.images[0].Repository == (docker_test_image_alpine | split(':') | first)
- present_1.images[0].Tag == (docker_test_image_alpine | split(':') | last)
- present_1.warnings | default([]) | select('regex', ' Please report this at ') | length == 0

View File

@ -83,7 +83,9 @@
- present_1.containers[0].Name == (pname ~ '-' ~ cname ~ '-1')
- present_1.containers[0].Image == docker_test_image_alpine
- present_1.images | length == 1
- present_1.images[0].ContainerName == (pname ~ '-' ~ cname ~ '-1')
- >-
docker_compose_version is version('2.37.0', '==') or
present_1.images[0].ContainerName == (pname ~ '-' ~ cname ~ '-1')
- present_1.images[0].Repository == (docker_test_image_alpine | split(':') | first)
- present_1.images[0].Tag == (docker_test_image_alpine | split(':') | last)
- present_1.warnings | default([]) | select('regex', ' Please report this at ') | length == 0

View File

@ -100,7 +100,9 @@
- present_1.containers[0].Name == (pname ~ '-' ~ cname ~ '-1')
- present_1.containers[0].Image == docker_test_image_alpine
- present_1.images | length == 1
- present_1.images[0].ContainerName == (pname ~ '-' ~ cname ~ '-1')
- >-
docker_compose_version is version('2.37.0', '==') or
present_1.images[0].ContainerName == (pname ~ '-' ~ cname ~ '-1')
- present_1.images[0].Repository == (docker_test_image_alpine | split(':') | first)
- present_1.images[0].Tag == (docker_test_image_alpine | split(':') | last)
- present_1.warnings | default([]) | select('regex', ' Please report this at ') | length == 0