Browse code

api/types/image: move LoadResponse to client

It's not the response coming from the API, but a wrapper for a response
reader. We should ultimately remove it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/09/05 22:15:42
Showing 6 changed files
... ...
@@ -1,7 +1,6 @@
1 1
 package image
2 2
 
3 3
 import (
4
-	"io"
5 4
 	"time"
6 5
 )
7 6
 
... ...
@@ -17,31 +16,3 @@ type PruneReport struct {
17 17
 	ImagesDeleted  []DeleteResponse
18 18
 	SpaceReclaimed uint64
19 19
 }
20
-
21
-// LoadResponse returns information to the client about a load process.
22
-//
23
-// TODO(thaJeztah): remove this type, and just use an io.ReadCloser
24
-//
25
-// This type was added in https://github.com/moby/moby/pull/18878, related
26
-// to https://github.com/moby/moby/issues/19177;
27
-//
28
-// Make docker load to output json when the response content type is json
29
-// Swarm hijacks the response from docker load and returns JSON rather
30
-// than plain text like the Engine does. This makes the API library to return
31
-// information to figure that out.
32
-//
33
-// However the "load" endpoint unconditionally returns JSON;
34
-// https://github.com/moby/moby/blob/7b9d2ef6e5518a3d3f3cc418459f8df786cfbbd1/api/server/router/image/image_routes.go#L248-L255
35
-//
36
-// PR https://github.com/moby/moby/pull/21959 made the response-type depend
37
-// on whether "quiet" was set, but this logic got changed in a follow-up
38
-// https://github.com/moby/moby/pull/25557, which made the JSON response-type
39
-// unconditionally, but the output produced depend on whether"quiet" was set.
40
-//
41
-// We should deprecated the "quiet" option, as it's really a client
42
-// responsibility.
43
-type LoadResponse struct {
44
-	// Body must be closed to avoid a resource leak
45
-	Body io.ReadCloser
46
-	JSON bool
47
-}
... ...
@@ -122,7 +122,7 @@ type ImageAPIClient interface {
122 122
 
123 123
 	ImageInspect(ctx context.Context, image string, _ ...ImageInspectOption) (image.InspectResponse, error)
124 124
 	ImageHistory(ctx context.Context, image string, _ ...ImageHistoryOption) ([]image.HistoryResponseItem, error)
125
-	ImageLoad(ctx context.Context, input io.Reader, _ ...ImageLoadOption) (image.LoadResponse, error)
125
+	ImageLoad(ctx context.Context, input io.Reader, _ ...ImageLoadOption) (LoadResponse, error)
126 126
 	ImageSave(ctx context.Context, images []string, _ ...ImageSaveOption) (io.ReadCloser, error)
127 127
 }
128 128
 
... ...
@@ -5,8 +5,6 @@ import (
5 5
 	"io"
6 6
 	"net/http"
7 7
 	"net/url"
8
-
9
-	"github.com/moby/moby/api/types/image"
10 8
 )
11 9
 
12 10
 // ImageLoad loads an image in the docker host from the client host.
... ...
@@ -16,11 +14,11 @@ import (
16 16
 // Platform is an optional parameter that specifies the platform to load from
17 17
 // the provided multi-platform image. Passing a platform only has an effect
18 18
 // if the input image is a multi-platform image.
19
-func (cli *Client) ImageLoad(ctx context.Context, input io.Reader, loadOpts ...ImageLoadOption) (image.LoadResponse, error) {
19
+func (cli *Client) ImageLoad(ctx context.Context, input io.Reader, loadOpts ...ImageLoadOption) (LoadResponse, error) {
20 20
 	var opts imageLoadOpts
21 21
 	for _, opt := range loadOpts {
22 22
 		if err := opt.Apply(&opts); err != nil {
23
-			return image.LoadResponse{}, err
23
+			return LoadResponse{}, err
24 24
 		}
25 25
 	}
26 26
 
... ...
@@ -31,12 +29,12 @@ func (cli *Client) ImageLoad(ctx context.Context, input io.Reader, loadOpts ...I
31 31
 	}
32 32
 	if len(opts.apiOptions.Platforms) > 0 {
33 33
 		if err := cli.NewVersionError(ctx, "1.48", "platform"); err != nil {
34
-			return image.LoadResponse{}, err
34
+			return LoadResponse{}, err
35 35
 		}
36 36
 
37 37
 		p, err := encodePlatforms(opts.apiOptions.Platforms...)
38 38
 		if err != nil {
39
-			return image.LoadResponse{}, err
39
+			return LoadResponse{}, err
40 40
 		}
41 41
 		query["platform"] = p
42 42
 	}
... ...
@@ -45,10 +43,38 @@ func (cli *Client) ImageLoad(ctx context.Context, input io.Reader, loadOpts ...I
45 45
 		"Content-Type": {"application/x-tar"},
46 46
 	})
47 47
 	if err != nil {
48
-		return image.LoadResponse{}, err
48
+		return LoadResponse{}, err
49 49
 	}
50
-	return image.LoadResponse{
50
+	return LoadResponse{
51 51
 		Body: resp.Body,
52 52
 		JSON: resp.Header.Get("Content-Type") == "application/json",
53 53
 	}, nil
54 54
 }
55
+
56
+// LoadResponse returns information to the client about a load process.
57
+//
58
+// TODO(thaJeztah): remove this type, and just use an io.ReadCloser
59
+//
60
+// This type was added in https://github.com/moby/moby/pull/18878, related
61
+// to https://github.com/moby/moby/issues/19177;
62
+//
63
+// Make docker load to output json when the response content type is json
64
+// Swarm hijacks the response from docker load and returns JSON rather
65
+// than plain text like the Engine does. This makes the API library to return
66
+// information to figure that out.
67
+//
68
+// However the "load" endpoint unconditionally returns JSON;
69
+// https://github.com/moby/moby/blob/7b9d2ef6e5518a3d3f3cc418459f8df786cfbbd1/api/server/router/image/image_routes.go#L248-L255
70
+//
71
+// PR https://github.com/moby/moby/pull/21959 made the response-type depend
72
+// on whether "quiet" was set, but this logic got changed in a follow-up
73
+// https://github.com/moby/moby/pull/25557, which made the JSON response-type
74
+// unconditionally, but the output produced depend on whether"quiet" was set.
75
+//
76
+// We should deprecated the "quiet" option, as it's really a client
77
+// responsibility.
78
+type LoadResponse struct {
79
+	// Body must be closed to avoid a resource leak
80
+	Body io.ReadCloser
81
+	JSON bool
82
+}
... ...
@@ -1,7 +1,6 @@
1 1
 package image
2 2
 
3 3
 import (
4
-	"io"
5 4
 	"time"
6 5
 )
7 6
 
... ...
@@ -17,31 +16,3 @@ type PruneReport struct {
17 17
 	ImagesDeleted  []DeleteResponse
18 18
 	SpaceReclaimed uint64
19 19
 }
20
-
21
-// LoadResponse returns information to the client about a load process.
22
-//
23
-// TODO(thaJeztah): remove this type, and just use an io.ReadCloser
24
-//
25
-// This type was added in https://github.com/moby/moby/pull/18878, related
26
-// to https://github.com/moby/moby/issues/19177;
27
-//
28
-// Make docker load to output json when the response content type is json
29
-// Swarm hijacks the response from docker load and returns JSON rather
30
-// than plain text like the Engine does. This makes the API library to return
31
-// information to figure that out.
32
-//
33
-// However the "load" endpoint unconditionally returns JSON;
34
-// https://github.com/moby/moby/blob/7b9d2ef6e5518a3d3f3cc418459f8df786cfbbd1/api/server/router/image/image_routes.go#L248-L255
35
-//
36
-// PR https://github.com/moby/moby/pull/21959 made the response-type depend
37
-// on whether "quiet" was set, but this logic got changed in a follow-up
38
-// https://github.com/moby/moby/pull/25557, which made the JSON response-type
39
-// unconditionally, but the output produced depend on whether"quiet" was set.
40
-//
41
-// We should deprecated the "quiet" option, as it's really a client
42
-// responsibility.
43
-type LoadResponse struct {
44
-	// Body must be closed to avoid a resource leak
45
-	Body io.ReadCloser
46
-	JSON bool
47
-}
... ...
@@ -122,7 +122,7 @@ type ImageAPIClient interface {
122 122
 
123 123
 	ImageInspect(ctx context.Context, image string, _ ...ImageInspectOption) (image.InspectResponse, error)
124 124
 	ImageHistory(ctx context.Context, image string, _ ...ImageHistoryOption) ([]image.HistoryResponseItem, error)
125
-	ImageLoad(ctx context.Context, input io.Reader, _ ...ImageLoadOption) (image.LoadResponse, error)
125
+	ImageLoad(ctx context.Context, input io.Reader, _ ...ImageLoadOption) (LoadResponse, error)
126 126
 	ImageSave(ctx context.Context, images []string, _ ...ImageSaveOption) (io.ReadCloser, error)
127 127
 }
128 128
 
... ...
@@ -5,8 +5,6 @@ import (
5 5
 	"io"
6 6
 	"net/http"
7 7
 	"net/url"
8
-
9
-	"github.com/moby/moby/api/types/image"
10 8
 )
11 9
 
12 10
 // ImageLoad loads an image in the docker host from the client host.
... ...
@@ -16,11 +14,11 @@ import (
16 16
 // Platform is an optional parameter that specifies the platform to load from
17 17
 // the provided multi-platform image. Passing a platform only has an effect
18 18
 // if the input image is a multi-platform image.
19
-func (cli *Client) ImageLoad(ctx context.Context, input io.Reader, loadOpts ...ImageLoadOption) (image.LoadResponse, error) {
19
+func (cli *Client) ImageLoad(ctx context.Context, input io.Reader, loadOpts ...ImageLoadOption) (LoadResponse, error) {
20 20
 	var opts imageLoadOpts
21 21
 	for _, opt := range loadOpts {
22 22
 		if err := opt.Apply(&opts); err != nil {
23
-			return image.LoadResponse{}, err
23
+			return LoadResponse{}, err
24 24
 		}
25 25
 	}
26 26
 
... ...
@@ -31,12 +29,12 @@ func (cli *Client) ImageLoad(ctx context.Context, input io.Reader, loadOpts ...I
31 31
 	}
32 32
 	if len(opts.apiOptions.Platforms) > 0 {
33 33
 		if err := cli.NewVersionError(ctx, "1.48", "platform"); err != nil {
34
-			return image.LoadResponse{}, err
34
+			return LoadResponse{}, err
35 35
 		}
36 36
 
37 37
 		p, err := encodePlatforms(opts.apiOptions.Platforms...)
38 38
 		if err != nil {
39
-			return image.LoadResponse{}, err
39
+			return LoadResponse{}, err
40 40
 		}
41 41
 		query["platform"] = p
42 42
 	}
... ...
@@ -45,10 +43,38 @@ func (cli *Client) ImageLoad(ctx context.Context, input io.Reader, loadOpts ...I
45 45
 		"Content-Type": {"application/x-tar"},
46 46
 	})
47 47
 	if err != nil {
48
-		return image.LoadResponse{}, err
48
+		return LoadResponse{}, err
49 49
 	}
50
-	return image.LoadResponse{
50
+	return LoadResponse{
51 51
 		Body: resp.Body,
52 52
 		JSON: resp.Header.Get("Content-Type") == "application/json",
53 53
 	}, nil
54 54
 }
55
+
56
+// LoadResponse returns information to the client about a load process.
57
+//
58
+// TODO(thaJeztah): remove this type, and just use an io.ReadCloser
59
+//
60
+// This type was added in https://github.com/moby/moby/pull/18878, related
61
+// to https://github.com/moby/moby/issues/19177;
62
+//
63
+// Make docker load to output json when the response content type is json
64
+// Swarm hijacks the response from docker load and returns JSON rather
65
+// than plain text like the Engine does. This makes the API library to return
66
+// information to figure that out.
67
+//
68
+// However the "load" endpoint unconditionally returns JSON;
69
+// https://github.com/moby/moby/blob/7b9d2ef6e5518a3d3f3cc418459f8df786cfbbd1/api/server/router/image/image_routes.go#L248-L255
70
+//
71
+// PR https://github.com/moby/moby/pull/21959 made the response-type depend
72
+// on whether "quiet" was set, but this logic got changed in a follow-up
73
+// https://github.com/moby/moby/pull/25557, which made the JSON response-type
74
+// unconditionally, but the output produced depend on whether"quiet" was set.
75
+//
76
+// We should deprecated the "quiet" option, as it's really a client
77
+// responsibility.
78
+type LoadResponse struct {
79
+	// Body must be closed to avoid a resource leak
80
+	Body io.ReadCloser
81
+	JSON bool
82
+}