Browse code

api/types: move ImageImportSource to api/types/image

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

Sebastiaan van Stijn authored on 2024/06/10 01:10:20
Showing 9 changed files
... ...
@@ -130,12 +130,6 @@ type ImageBuildResponse struct {
130 130
 	OSType string
131 131
 }
132 132
 
133
-// ImageImportSource holds source information for ImageImport
134
-type ImageImportSource struct {
135
-	Source     io.Reader // Source is the data to send to the server to create this image from. You must set SourceName to "-" to leverage this.
136
-	SourceName string    // SourceName is the name of the image to pull. Set to "-" to leverage the Source attribute.
137
-}
138
-
139 133
 // ImageLoadResponse returns information to the client about a load process.
140 134
 type ImageLoadResponse struct {
141 135
 	// Body must be closed to avoid a resource leak
... ...
@@ -2,10 +2,17 @@ package image
2 2
 
3 3
 import (
4 4
 	"context"
5
+	"io"
5 6
 
6 7
 	"github.com/docker/docker/api/types/filters"
7 8
 )
8 9
 
10
+// ImportSource holds source information for ImageImport
11
+type ImportSource struct {
12
+	Source     io.Reader // Source is the data to send to the server to create this image from. You must set SourceName to "-" to leverage this.
13
+	SourceName string    // SourceName is the name of the image to pull. Set to "-" to leverage the Source attribute.
14
+}
15
+
9 16
 // ImportOptions holds information to import images from the client host.
10 17
 type ImportOptions struct {
11 18
 	Tag      string   // Tag is the name to tag this image with. This attribute is deprecated.
... ...
@@ -123,3 +123,8 @@ type EventsOptions = events.ListOptions
123 123
 //
124 124
 // Deprecated: use [registry.SearchOptions].
125 125
 type ImageSearchOptions = registry.SearchOptions
126
+
127
+// ImageImportSource holds source information for ImageImport
128
+//
129
+// Deprecated: use [image.ImportSource].
130
+type ImageImportSource image.ImportSource
... ...
@@ -7,13 +7,12 @@ import (
7 7
 	"strings"
8 8
 
9 9
 	"github.com/distribution/reference"
10
-	"github.com/docker/docker/api/types"
11 10
 	"github.com/docker/docker/api/types/image"
12 11
 )
13 12
 
14 13
 // ImageImport creates a new image based on the source options.
15 14
 // It returns the JSON content in the response body.
16
-func (cli *Client) ImageImport(ctx context.Context, source types.ImageImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error) {
15
+func (cli *Client) ImageImport(ctx context.Context, source image.ImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error) {
17 16
 	if ref != "" {
18 17
 		// Check if the given image name can be resolved
19 18
 		if _, err := reference.ParseNormalizedNamed(ref); err != nil {
... ...
@@ -10,7 +10,6 @@ import (
10 10
 	"strings"
11 11
 	"testing"
12 12
 
13
-	"github.com/docker/docker/api/types"
14 13
 	"github.com/docker/docker/api/types/image"
15 14
 	"github.com/docker/docker/errdefs"
16 15
 	"gotest.tools/v3/assert"
... ...
@@ -21,7 +20,7 @@ func TestImageImportError(t *testing.T) {
21 21
 	client := &Client{
22 22
 		client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
23 23
 	}
24
-	_, err := client.ImageImport(context.Background(), types.ImageImportSource{}, "image:tag", image.ImportOptions{})
24
+	_, err := client.ImageImport(context.Background(), image.ImportSource{}, "image:tag", image.ImportOptions{})
25 25
 	assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
26 26
 }
27 27
 
... ...
@@ -61,7 +60,7 @@ func TestImageImport(t *testing.T) {
61 61
 			}, nil
62 62
 		}),
63 63
 	}
64
-	importResponse, err := client.ImageImport(context.Background(), types.ImageImportSource{
64
+	importResponse, err := client.ImageImport(context.Background(), image.ImportSource{
65 65
 		Source:     strings.NewReader("source"),
66 66
 		SourceName: "image_source",
67 67
 	}, "repository_name:imported", image.ImportOptions{
... ...
@@ -92,7 +92,7 @@ type ImageAPIClient interface {
92 92
 	BuildCancel(ctx context.Context, id string) error
93 93
 	ImageCreate(ctx context.Context, parentReference string, options image.CreateOptions) (io.ReadCloser, error)
94 94
 	ImageHistory(ctx context.Context, image string) ([]image.HistoryResponseItem, error)
95
-	ImageImport(ctx context.Context, source types.ImageImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error)
95
+	ImageImport(ctx context.Context, source image.ImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error)
96 96
 	ImageInspectWithRaw(ctx context.Context, image string) (types.ImageInspect, []byte, error)
97 97
 	ImageList(ctx context.Context, options image.ListOptions) ([]image.Summary, error)
98 98
 	ImageLoad(ctx context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error)
... ...
@@ -6,7 +6,6 @@ import (
6 6
 	"testing"
7 7
 	"time"
8 8
 
9
-	"github.com/docker/docker/api/types"
10 9
 	"github.com/docker/docker/api/types/filters"
11 10
 	"github.com/docker/docker/api/types/image"
12 11
 	"github.com/docker/docker/integration/internal/container"
... ...
@@ -32,7 +31,7 @@ func TestExportContainerAndImportImage(t *testing.T) {
32 32
 	reference := "repo/" + strings.ToLower(t.Name()) + ":v1"
33 33
 	exportResp, err := apiClient.ContainerExport(ctx, cID)
34 34
 	assert.NilError(t, err)
35
-	importResp, err := apiClient.ImageImport(ctx, types.ImageImportSource{
35
+	importResp, err := apiClient.ImageImport(ctx, image.ImportSource{
36 36
 		Source:     exportResp,
37 37
 		SourceName: "-",
38 38
 	}, reference, image.ImportOptions{})
... ...
@@ -9,7 +9,6 @@ import (
9 9
 	"strings"
10 10
 	"testing"
11 11
 
12
-	"github.com/docker/docker/api/types"
13 12
 	imagetypes "github.com/docker/docker/api/types/image"
14 13
 	"github.com/docker/docker/errdefs"
15 14
 	"github.com/docker/docker/image"
... ...
@@ -48,7 +47,7 @@ func TestImportExtremelyLargeImageWorks(t *testing.T) {
48 48
 	reference := strings.ToLower(t.Name()) + ":v42"
49 49
 
50 50
 	_, err = client.ImageImport(ctx,
51
-		types.ImageImportSource{Source: imageRdr, SourceName: "-"},
51
+		imagetypes.ImportSource{Source: imageRdr, SourceName: "-"},
52 52
 		reference,
53 53
 		imagetypes.ImportOptions{})
54 54
 	assert.NilError(t, err)
... ...
@@ -111,7 +110,7 @@ func TestImportWithCustomPlatform(t *testing.T) {
111 111
 			reference := "import-with-platform:tc-" + strconv.Itoa(i)
112 112
 
113 113
 			_, err = client.ImageImport(ctx,
114
-				types.ImageImportSource{Source: imageRdr, SourceName: "-"},
114
+				imagetypes.ImportSource{Source: imageRdr, SourceName: "-"},
115 115
 				reference,
116 116
 				imagetypes.ImportOptions{Platform: tc.platform})
117 117
 			assert.NilError(t, err)
... ...
@@ -177,7 +176,7 @@ func TestImportWithCustomPlatformReject(t *testing.T) {
177 177
 			ctx := testutil.StartSpan(ctx, t)
178 178
 			reference := "import-with-platform:tc-" + strconv.Itoa(i)
179 179
 			_, err = client.ImageImport(ctx,
180
-				types.ImageImportSource{Source: imageRdr, SourceName: "-"},
180
+				imagetypes.ImportSource{Source: imageRdr, SourceName: "-"},
181 181
 				reference,
182 182
 				imagetypes.ImportOptions{Platform: tc.platform})
183 183
 
... ...
@@ -16,7 +16,6 @@ import (
16 16
 	"testing"
17 17
 	"time"
18 18
 
19
-	"github.com/docker/docker/api/types"
20 19
 	containertypes "github.com/docker/docker/api/types/container"
21 20
 	eventtypes "github.com/docker/docker/api/types/events"
22 21
 	"github.com/docker/docker/api/types/image"
... ...
@@ -463,7 +462,7 @@ func imageImport(ctx context.Context, client client.APIClient, path string) erro
463 463
 	defer file.Close()
464 464
 	options := image.ImportOptions{}
465 465
 	ref := ""
466
-	source := types.ImageImportSource{
466
+	source := image.ImportSource{
467 467
 		Source:     file,
468 468
 		SourceName: "-",
469 469
 	}