Docker Compose 5+: improve image layer event parsing (#1219)

* Remove long deprecated version fields.

* Add first JSON event parsing tests.

* Improve image layer event parsing for Compose 5+.

* Add 'Working' to image working actions.

* Add changelog fragment.

* Shorten lines.

* Adjust docker_compose_v2_run tests.
This commit is contained in:
Felix Fontein
2025-12-06 17:48:17 +01:00
committed by GitHub
parent 2efcd6b2ec
commit 174c0c8058
5 changed files with 225 additions and 7 deletions
+15 -4
View File
@@ -132,7 +132,7 @@ DOCKER_PULL_PROGRESS_DONE = frozenset(
"Pull complete",
)
)
DOCKER_PULL_PROGRESS_WORKING = frozenset(
DOCKER_PULL_PROGRESS_WORKING_OLD = frozenset(
(
"Pulling fs layer",
"Waiting",
@@ -141,6 +141,7 @@ DOCKER_PULL_PROGRESS_WORKING = frozenset(
"Extracting",
)
)
DOCKER_PULL_PROGRESS_WORKING = frozenset(DOCKER_PULL_PROGRESS_WORKING_OLD | {"Working"})
class ResourceType:
@@ -191,7 +192,7 @@ _RE_PULL_EVENT = re.compile(
)
_DOCKER_PULL_PROGRESS_WD = sorted(
DOCKER_PULL_PROGRESS_DONE | DOCKER_PULL_PROGRESS_WORKING
DOCKER_PULL_PROGRESS_DONE | DOCKER_PULL_PROGRESS_WORKING_OLD
)
_RE_PULL_PROGRESS = re.compile(
@@ -494,7 +495,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(
@@ -513,7 +524,7 @@ def parse_json_events(
status, text = text, status
elif (
text in DOCKER_PULL_PROGRESS_DONE
or line_data.get("text") in DOCKER_PULL_PROGRESS_WORKING
or line_data.get("text") in DOCKER_PULL_PROGRESS_WORKING_OLD
):
resource_type = ResourceType.IMAGE_LAYER
status, text = text, status