Skip to content

Commit ac2a028

Browse files
committed
api/types: move image options to api/types/image
To prevent a circular import between api/types and api/types image, the RequestPrivilegeFunc reference was not moved, but defined as part of the PullOptions / PushOptions. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 8906adc commit ac2a028

41 files changed

Lines changed: 206 additions & 161 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/server/router/image/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type Backend interface {
2525
type imageBackend interface {
2626
ImageDelete(ctx context.Context, imageRef string, force, prune bool) ([]image.DeleteResponse, error)
2727
ImageHistory(ctx context.Context, imageName string) ([]*image.HistoryResponseItem, error)
28-
Images(ctx context.Context, opts types.ImageListOptions) ([]*image.Summary, error)
28+
Images(ctx context.Context, opts image.ListOptions) ([]*image.Summary, error)
2929
GetImage(ctx context.Context, refOrID string, options backend.GetImageOpts) (*dockerimage.Image, error)
3030
TagImage(ctx context.Context, id dockerimage.ID, newRef reference.Named) error
3131
ImagesPrune(ctx context.Context, pruneFilters filters.Args) (*types.ImagesPruneReport, error)

api/server/router/image/image_routes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (ir *imageRouter) postImagesPush(ctx context.Context, w http.ResponseWriter
190190

191191
var ref reference.Named
192192

193-
// Tag is empty only in case ImagePushOptions.All is true.
193+
// Tag is empty only in case PushOptions.All is true.
194194
if tag != "" {
195195
r, err := httputils.RepoTagReference(img, tag)
196196
if err != nil {
@@ -396,7 +396,7 @@ func (ir *imageRouter) getImagesJSON(ctx context.Context, w http.ResponseWriter,
396396
sharedSize = httputils.BoolValue(r, "shared-size")
397397
}
398398

399-
images, err := ir.backend.Images(ctx, types.ImageListOptions{
399+
images, err := ir.backend.Images(ctx, imagetypes.ListOptions{
400400
All: httputils.BoolValue(r, "all"),
401401
Filters: imageFilters,
402402
SharedSize: sharedSize,

api/types/client.go

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -157,57 +157,19 @@ type ImageBuildResponse struct {
157157
OSType string
158158
}
159159

160-
// ImageCreateOptions holds information to create images.
161-
type ImageCreateOptions struct {
162-
RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry.
163-
Platform string // Platform is the target platform of the image if it needs to be pulled from the registry.
164-
}
165-
166160
// ImageImportSource holds source information for ImageImport
167161
type ImageImportSource struct {
168162
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.
169163
SourceName string // SourceName is the name of the image to pull. Set to "-" to leverage the Source attribute.
170164
}
171165

172-
// ImageImportOptions holds information to import images from the client host.
173-
type ImageImportOptions struct {
174-
Tag string // Tag is the name to tag this image with. This attribute is deprecated.
175-
Message string // Message is the message to tag the image with
176-
Changes []string // Changes are the raw changes to apply to this image
177-
Platform string // Platform is the target platform of the image
178-
}
179-
180-
// ImageListOptions holds parameters to list images with.
181-
type ImageListOptions struct {
182-
// All controls whether all images in the graph are filtered, or just
183-
// the heads.
184-
All bool
185-
186-
// Filters is a JSON-encoded set of filter arguments.
187-
Filters filters.Args
188-
189-
// SharedSize indicates whether the shared size of images should be computed.
190-
SharedSize bool
191-
192-
// ContainerCount indicates whether container count should be computed.
193-
ContainerCount bool
194-
}
195-
196166
// ImageLoadResponse returns information to the client about a load process.
197167
type ImageLoadResponse struct {
198168
// Body must be closed to avoid a resource leak
199169
Body io.ReadCloser
200170
JSON bool
201171
}
202172

203-
// ImagePullOptions holds information to pull images.
204-
type ImagePullOptions struct {
205-
All bool
206-
RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
207-
PrivilegeFunc RequestPrivilegeFunc
208-
Platform string
209-
}
210-
211173
// RequestPrivilegeFunc is a function interface that
212174
// clients can supply to retry operations after
213175
// getting an authorization error.
@@ -216,15 +178,6 @@ type ImagePullOptions struct {
216178
// if the privilege request fails.
217179
type RequestPrivilegeFunc func() (string, error)
218180

219-
// ImagePushOptions holds information to push images.
220-
type ImagePushOptions ImagePullOptions
221-
222-
// ImageRemoveOptions holds parameters to remove images.
223-
type ImageRemoveOptions struct {
224-
Force bool
225-
PruneChildren bool
226-
}
227-
228181
// ImageSearchOptions holds parameters to search images with.
229182
type ImageSearchOptions struct {
230183
RegistryAuth string

api/types/image/opts.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package image
2+
3+
import "github.com/docker/docker/api/types/filters"
4+
5+
// ImportOptions holds information to import images from the client host.
6+
type ImportOptions struct {
7+
Tag string // Tag is the name to tag this image with. This attribute is deprecated.
8+
Message string // Message is the message to tag the image with
9+
Changes []string // Changes are the raw changes to apply to this image
10+
Platform string // Platform is the target platform of the image
11+
}
12+
13+
// CreateOptions holds information to create images.
14+
type CreateOptions struct {
15+
RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry.
16+
Platform string // Platform is the target platform of the image if it needs to be pulled from the registry.
17+
}
18+
19+
// PullOptions holds information to pull images.
20+
type PullOptions struct {
21+
All bool
22+
RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry
23+
24+
// PrivilegeFunc is a function that clients can supply to retry operations
25+
// after getting an authorization error. This function returns the registry
26+
// authentication header value in base64 encoded format, or an error if the
27+
// privilege request fails.
28+
//
29+
// Also see [github.com/docker/docker/api/types.RequestPrivilegeFunc].
30+
PrivilegeFunc func() (string, error)
31+
Platform string
32+
}
33+
34+
// PushOptions holds information to push images.
35+
type PushOptions PullOptions
36+
37+
// ListOptions holds parameters to list images with.
38+
type ListOptions struct {
39+
// All controls whether all images in the graph are filtered, or just
40+
// the heads.
41+
All bool
42+
43+
// Filters is a JSON-encoded set of filter arguments.
44+
Filters filters.Args
45+
46+
// SharedSize indicates whether the shared size of images should be computed.
47+
SharedSize bool
48+
49+
// ContainerCount indicates whether container count should be computed.
50+
ContainerCount bool
51+
}
52+
53+
// RemoveOptions holds parameters to remove images.
54+
type RemoveOptions struct {
55+
Force bool
56+
PruneChildren bool
57+
}

api/types/types_deprecated.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,33 @@ type ContainerRemoveOptions = container.RemoveOptions
136136
func DecodeSecurityOptions(opts []string) ([]system.SecurityOpt, error) {
137137
return system.DecodeSecurityOptions(opts)
138138
}
139+
140+
// ImageImportOptions holds information to import images from the client host.
141+
//
142+
// Deprecated: use [image.ImportOptions].
143+
type ImageImportOptions = image.ImportOptions
144+
145+
// ImageCreateOptions holds information to create images.
146+
//
147+
// Deprecated: use [image.CreateOptions].
148+
type ImageCreateOptions = image.CreateOptions
149+
150+
// ImagePullOptions holds information to pull images.
151+
//
152+
// Deprecated: use [image.PullOptions].
153+
type ImagePullOptions = image.PullOptions
154+
155+
// ImagePushOptions holds information to push images.
156+
//
157+
// Deprecated: use [image.PushOptions].
158+
type ImagePushOptions = image.PushOptions
159+
160+
// ImageListOptions holds parameters to list images with.
161+
//
162+
// Deprecated: use [image.ListOptions].
163+
type ImageListOptions = image.ListOptions
164+
165+
// ImageRemoveOptions holds parameters to remove images.
166+
//
167+
// Deprecated: use [image.RemoveOptions].
168+
type ImageRemoveOptions = image.RemoveOptions

client/image_create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import (
88
"strings"
99

1010
"github.com/distribution/reference"
11-
"github.com/docker/docker/api/types"
11+
"github.com/docker/docker/api/types/image"
1212
"github.com/docker/docker/api/types/registry"
1313
)
1414

1515
// ImageCreate creates a new image based on the parent options.
1616
// It returns the JSON content in the response body.
17-
func (cli *Client) ImageCreate(ctx context.Context, parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) {
17+
func (cli *Client) ImageCreate(ctx context.Context, parentReference string, options image.CreateOptions) (io.ReadCloser, error) {
1818
ref, err := reference.ParseNormalizedNamed(parentReference)
1919
if err != nil {
2020
return nil, err

client/image_create_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strings"
1010
"testing"
1111

12-
"github.com/docker/docker/api/types"
12+
"github.com/docker/docker/api/types/image"
1313
"github.com/docker/docker/api/types/registry"
1414
"github.com/docker/docker/errdefs"
1515
"gotest.tools/v3/assert"
@@ -20,7 +20,7 @@ func TestImageCreateError(t *testing.T) {
2020
client := &Client{
2121
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
2222
}
23-
_, err := client.ImageCreate(context.Background(), "reference", types.ImageCreateOptions{})
23+
_, err := client.ImageCreate(context.Background(), "reference", image.CreateOptions{})
2424
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
2525
}
2626

@@ -58,7 +58,7 @@ func TestImageCreate(t *testing.T) {
5858
}),
5959
}
6060

61-
createResponse, err := client.ImageCreate(context.Background(), expectedReference, types.ImageCreateOptions{
61+
createResponse, err := client.ImageCreate(context.Background(), expectedReference, image.CreateOptions{
6262
RegistryAuth: expectedRegistryAuth,
6363
})
6464
if err != nil {

client/image_import.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import (
88

99
"github.com/distribution/reference"
1010
"github.com/docker/docker/api/types"
11+
"github.com/docker/docker/api/types/image"
1112
)
1213

1314
// ImageImport creates a new image based on the source options.
1415
// It returns the JSON content in the response body.
15-
func (cli *Client) ImageImport(ctx context.Context, source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) {
16+
func (cli *Client) ImageImport(ctx context.Context, source types.ImageImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error) {
1617
if ref != "" {
1718
// Check if the given image name can be resolved
1819
if _, err := reference.ParseNormalizedNamed(ref); err != nil {

client/image_import_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"testing"
1212

1313
"github.com/docker/docker/api/types"
14+
"github.com/docker/docker/api/types/image"
1415
"github.com/docker/docker/errdefs"
1516
"gotest.tools/v3/assert"
1617
is "gotest.tools/v3/assert/cmp"
@@ -20,7 +21,7 @@ func TestImageImportError(t *testing.T) {
2021
client := &Client{
2122
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
2223
}
23-
_, err := client.ImageImport(context.Background(), types.ImageImportSource{}, "image:tag", types.ImageImportOptions{})
24+
_, err := client.ImageImport(context.Background(), types.ImageImportSource{}, "image:tag", image.ImportOptions{})
2425
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
2526
}
2627

@@ -63,7 +64,7 @@ func TestImageImport(t *testing.T) {
6364
importResponse, err := client.ImageImport(context.Background(), types.ImageImportSource{
6465
Source: strings.NewReader("source"),
6566
SourceName: "image_source",
66-
}, "repository_name:imported", types.ImageImportOptions{
67+
}, "repository_name:imported", image.ImportOptions{
6768
Tag: "imported",
6869
Message: "A message",
6970
Changes: []string{"change1", "change2"},

client/image_list.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ import (
55
"encoding/json"
66
"net/url"
77

8-
"github.com/docker/docker/api/types"
98
"github.com/docker/docker/api/types/filters"
109
"github.com/docker/docker/api/types/image"
1110
"github.com/docker/docker/api/types/versions"
1211
)
1312

1413
// ImageList returns a list of images in the docker host.
15-
func (cli *Client) ImageList(ctx context.Context, options types.ImageListOptions) ([]image.Summary, error) {
14+
func (cli *Client) ImageList(ctx context.Context, options image.ListOptions) ([]image.Summary, error) {
1615
// Make sure we negotiated (if the client is configured to do so),
1716
// as code below contains API-version specific handling of options.
1817
//

0 commit comments

Comments
 (0)