From cdb00332dac3ce9b2ebc76e65afe0347a941cc15 Mon Sep 17 00:00:00 2001 From: Jake Torrance Date: Tue, 1 Nov 2022 22:11:26 +0000 Subject: [PATCH 1/2] Docker compat build api - make sure only one line appears per flush Closes #16360 Signed-off-by: Jake Torrance Signed-off-by: Jake Torrance --- pkg/api/handlers/compat/images_build.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go index d4c8c0743a..4a11065b2b 100644 --- a/pkg/api/handlers/compat/images_build.go +++ b/pkg/api/handlers/compat/images_build.go @@ -804,6 +804,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { if err := enc.Encode(m); err != nil { logrus.Warnf("failed to json encode error %v", err) } + flush() m.Aux = nil m.Stream = fmt.Sprintf("Successfully built %12.12s\n", imageID) if err := enc.Encode(m); err != nil { From 85f4d3717358e84f29e554b3e407323e0925806d Mon Sep 17 00:00:00 2001 From: Jake Torrance Date: Sat, 5 Nov 2022 15:47:31 +0000 Subject: [PATCH 2/2] Make sure we can build and read each line of docker py's api client Signed-off-by: Jake Torrance --- test/python/docker/compat/test_images.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/python/docker/compat/test_images.py b/test/python/docker/compat/test_images.py index ac9a8d671e..cb2931b3ee 100644 --- a/test/python/docker/compat/test_images.py +++ b/test/python/docker/compat/test_images.py @@ -4,6 +4,7 @@ import io import os import unittest +import json from docker import errors @@ -125,6 +126,14 @@ def test_build_image(self): self.assertEqual(image.labels["apple"], labels["apple"]) self.assertEqual(image.labels["grape"], labels["grape"]) + def test_build_image_via_api_client(self): + api_client = self.docker.api + for line in api_client.build(path="test/python/docker/build_labels"): + try: + parsed = json.loads(line.decode("utf-8")) + except json.JSONDecodeError as e: + raise IOError(f"Line '{line}' was not JSON parsable") + assert "errorDetail" not in parsed if __name__ == "__main__": # Setup temporary space