diff --git a/plugins/module_utils/_compose_v2.py b/plugins/module_utils/_compose_v2.py index 6b61ebaf..8714eeba 100644 --- a/plugins/module_utils/_compose_v2.py +++ b/plugins/module_utils/_compose_v2.py @@ -494,7 +494,17 @@ def parse_json_events( # {"dry-run":true,"id":"ansible-docker-test-dc713f1f-container ==> ==>","text":"naming to ansible-docker-test-dc713f1f-image"} # (The longer form happens since Docker Compose 2.39.0) continue - if isinstance(resource_id, str) and " " in resource_id: + if ( + status in ("Working", "Done") + and isinstance(line_data.get("parent_id"), str) + and line_data["parent_id"].startswith("Image ") + ): + # Compose 5.0.0+: + # {"id":"63a26ae4e8a8","parent_id":"Image ghcr.io/ansible-collections/simple-1:tag","status":"Working"} + # {"id":"63a26ae4e8a8","parent_id":"Image ghcr.io/ansible-collections/simple-1:tag","status":"Done","percent":100} + resource_type = ResourceType.IMAGE_LAYER + resource_id = line_data["parent_id"][len("Image ") :] + elif isinstance(resource_id, str) and " " in resource_id: resource_type_str, resource_id = resource_id.split(" ", 1) try: resource_type = ResourceType.from_docker_compose_event( diff --git a/tests/unit/plugins/module_utils/test__compose_v2.py b/tests/unit/plugins/module_utils/test__compose_v2.py index 2fa01edc..46c267f9 100644 --- a/tests/unit/plugins/module_utils/test__compose_v2.py +++ b/tests/unit/plugins/module_utils/test__compose_v2.py @@ -494,64 +494,55 @@ JSON_TEST_CASES: list[tuple[str, str, str, list[Event], list[str]]] = [ "Working", ), Event( - "unknown", - "63a26ae4e8a8", + "image-layer", + "ghcr.io/ansible-collections/simple-1:tag", "Working", None, ), Event( - "unknown", - "63a26ae4e8a8", + "image-layer", + "ghcr.io/ansible-collections/simple-1:tag", "Working", "[> ] 6.89kB/599.9kB", ), Event( - "unknown", - "63a26ae4e8a8", + "image-layer", + "ghcr.io/ansible-collections/simple-1:tag", "Working", "[==================================================>] 599.9kB/599.9kB", ), Event( - "unknown", - "63a26ae4e8a8", + "image-layer", + "ghcr.io/ansible-collections/simple-1:tag", "Working", None, ), Event( - "unknown", - "63a26ae4e8a8", - "Done", - None, + "image-layer", "ghcr.io/ansible-collections/simple-1:tag", "Done", None ), Event( - "unknown", - "63a26ae4e8a8", + "image-layer", + "ghcr.io/ansible-collections/simple-1:tag", "Working", "[==> ] 32.77kB/599.9kB", ), Event( - "unknown", - "63a26ae4e8a8", - "Working", - "[==================================================>] 599.9kB/599.9kB", - ), - Event( - "unknown", - "63a26ae4e8a8", - "Working", - "[==================================================>] 599.9kB/599.9kB", - ), - Event( - "unknown", - "63a26ae4e8a8", - "Done", - None, - ), - Event( - "image", + "image-layer", "ghcr.io/ansible-collections/simple-1:tag", - "Pulled", - "Done", + "Working", + "[==================================================>] 599.9kB/599.9kB", + ), + Event( + "image-layer", + "ghcr.io/ansible-collections/simple-1:tag", + "Working", + "[==================================================>] 599.9kB/599.9kB", + ), + Event( + "image-layer", "ghcr.io/ansible-collections/simple-1:tag", "Done", None + ), + Event( + "image", "ghcr.io/ansible-collections/simple-1:tag", "Pulled", "Done" ), ], [],