From e37ecb7ada35142dababee1ae08b1b4c11d700ce Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 12 Feb 2024 17:33:34 -0500 Subject: [PATCH] docker: fix missing image_id when using containerd-snapshotter (#20533) fixes: https://github.com/pantsbuild/pants/issues/20520 --- .../backend/docker/goals/package_image.py | 8 +++- .../docker/goals/package_image_test.py | 41 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/python/pants/backend/docker/goals/package_image.py b/src/python/pants/backend/docker/goals/package_image.py index 2520b008e39..1d797199a3c 100644 --- a/src/python/pants/backend/docker/goals/package_image.py +++ b/src/python/pants/backend/docker/goals/package_image.py @@ -521,6 +521,8 @@ def parse_image_id_from_docker_build_output(docker: DockerBinary, *outputs: byte ( # BuildKit output. r"(writing image (?Psha256:\S+) done)", + # BuildKit with containerd-snapshotter output. + r"(exporting manifest list (?Psha256:\S+) done)", # Docker output. r"(Successfully built (?P\S+))", ), @@ -539,7 +541,11 @@ def parse_image_id_from_docker_build_output(docker: DockerBinary, *outputs: byte None, ) if image_id_match: - image_id = image_id_match.group("digest") or image_id_match.group("short_id") + image_id = ( + image_id_match.group("digest") + or image_id_match.group("short_id") + or image_id_match.group("manifest_list") + ) return image_id return "" diff --git a/src/python/pants/backend/docker/goals/package_image_test.py b/src/python/pants/backend/docker/goals/package_image_test.py index 008577a853c..96ac5407952 100644 --- a/src/python/pants/backend/docker/goals/package_image_test.py +++ b/src/python/pants/backend/docker/goals/package_image_test.py @@ -1636,6 +1636,47 @@ def test_get_context_root( ), "", ), + # Buildkit with containerd-snapshotter + ( + DockerBinary("/bin/docker", "1234", is_podman=False), + "sha256:b2b51838586286a9e544ddb31b3dbf7f6a99654d275b6e56b5f69f90138b4c0e", + dedent( + """\ + #9 exporting to image + #9 exporting layers done + #9 exporting manifest sha256:7802087e8e0801f6451d862a00a6ce8af3e4829b09bc890dea0dd2659c11b25a done + #9 exporting config sha256:c83bed954709ba0c546d66d8f29afaac87c597f01b03fec158f3b21977c3e143 done + #9 exporting attestation manifest sha256:399891f9628cfafaba9e034599bdd55675ac0a3bad38151ed1ebf03993669545 done + #9 exporting manifest list sha256:b2b51838586286a9e544ddb31b3dbf7f6a99654d275b6e56b5f69f90138b4c0e done + #9 naming to myhost.com/my_app:latest done + #9 unpacking to myhost.com/my_app:latest done + #9 DONE 0.0s + """ + ), + "", + ), + # Buildkit with containerd-snapshotter and cross platform + ( + DockerBinary("/bin/docker", "1234", is_podman=False), + "sha256:3c72de0e05bb75247e68e124e6500700f6e0597425db2ee9f08fd59ef28cea0f", + dedent( + """\ + #12 exporting to image + #12 exporting layers done + #12 exporting manifest sha256:452598369b55c27d752c45736cf26c0339612077f17df31fb0cdd79c5145d081 done + #12 exporting config sha256:6fbcebfde0ec24b487045516c3b5ffd3f0633e756a6d5808c2e5ad75809e0ca6 done + #12 exporting attestation manifest sha256:32fcf615e85bc9c2f606f863e8db3ca16dd77613a1e175e5972f39267e106dfb done + #12 exporting manifest sha256:bcb911a3efbec48e3c58c2acfd38fe92321eed731c53253f0b5c883918420187 done + #12 exporting config sha256:86e7fd0c4fa2356430d4ca188ed9e86497b8d03996ccba426d92c7e145e69990 done + #12 exporting attestation manifest sha256:66f9e7af29dd04e6264b8e113571f7b653f1681ba124a386530145fb39ff0102 done + #12 exporting manifest list sha256:3c72de0e05bb75247e68e124e6500700f6e0597425db2ee9f08fd59ef28cea0f done + #12 naming to myhost.com/my_app:latest done + #12 unpacking to myhost.com/my_app:latest done + #12 DONE 0.0s + """ + ), + "", + ), # Podman ( DockerBinary("/bin/podman", "abcd", is_podman=True),