Skip to content

Commit

Permalink
api/types: move image-types to api/types/image
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Oct 12, 2023
1 parent aacd100 commit 48cacbc
Show file tree
Hide file tree
Showing 26 changed files with 116 additions and 86 deletions.
4 changes: 2 additions & 2 deletions api/server/router/image/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ type Backend interface {
}

type imageBackend interface {
ImageDelete(ctx context.Context, imageRef string, force, prune bool) ([]types.ImageDeleteResponseItem, error)
ImageDelete(ctx context.Context, imageRef string, force, prune bool) ([]image.DeleteResponse, error)
ImageHistory(ctx context.Context, imageName string) ([]*image.HistoryResponseItem, error)
Images(ctx context.Context, opts types.ImageListOptions) ([]*types.ImageSummary, error)
Images(ctx context.Context, opts types.ImageListOptions) ([]*image.Summary, error)
GetImage(ctx context.Context, refOrID string, options image.GetImageOpts) (*dockerimage.Image, error)
TagImage(ctx context.Context, id dockerimage.ID, newRef reference.Named) error
ImagesPrune(ctx context.Context, pruneFilters filters.Args) (*types.ImagesPruneReport, error)
Expand Down
2 changes: 1 addition & 1 deletion api/server/router/image/image_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (ir *imageRouter) toImageInspect(img *image.Image) (*types.ImageInspect, er
Data: img.Details.Metadata,
},
RootFS: rootFSToAPIType(img.RootFS),
Metadata: types.ImageMetadata{
Metadata: opts.Metadata{
LastTagTime: img.Details.LastUpdated,
},
}, nil
Expand Down
2 changes: 2 additions & 0 deletions api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,7 @@ definitions:
x-nullable: true
ImageSummary:
type: "object"
x-go-name: "Summary"
required:
- Id
- ParentId
Expand Down Expand Up @@ -4477,6 +4478,7 @@ definitions:

ImageDeleteResponseItem:
type: "object"
x-go-name: "DeleteResponse"
properties:
Untagged:
description: "The image ID of an image that was untagged"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package types
package image

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

// ImageDeleteResponseItem image delete response item
// swagger:model ImageDeleteResponseItem
type ImageDeleteResponseItem struct {
// DeleteResponse delete response
// swagger:model DeleteResponse
type DeleteResponse struct {

// The image ID of an image that was deleted
Deleted string `json:"Deleted,omitempty"`
Expand Down
9 changes: 9 additions & 0 deletions api/types/image/image.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package image

import "time"

// Metadata contains engine-local data about the image.
type Metadata struct {
// LastTagTime is the date and time at which the image was last tagged.
LastTagTime time.Time `json:",omitempty"`
}
8 changes: 4 additions & 4 deletions api/types/image_summary.go → api/types/image/summary.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package types
package image

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

// ImageSummary image summary
// swagger:model ImageSummary
type ImageSummary struct {
// Summary summary
// swagger:model Summary
type Summary struct {

// Number of containers using this image. Includes both stopped and running
// containers.
Expand Down
13 changes: 4 additions & 9 deletions api/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/swarm"
Expand Down Expand Up @@ -128,13 +129,7 @@ type ImageInspect struct {
// Metadata of the image in the local cache.
//
// This information is local to the daemon, and not part of the image itself.
Metadata ImageMetadata
}

// ImageMetadata contains engine-local data about the image
type ImageMetadata struct {
// LastTagTime is the date and time at which the image was last tagged.
LastTagTime time.Time `json:",omitempty"`
Metadata image.Metadata
}

// Container contains response of Engine API:
Expand Down Expand Up @@ -514,7 +509,7 @@ type DiskUsageOptions struct {
// GET "/system/df"
type DiskUsage struct {
LayersSize int64
Images []*ImageSummary
Images []*image.Summary
Containers []*Container
Volumes []*volume.Volume
BuildCache []*BuildCache
Expand All @@ -538,7 +533,7 @@ type VolumesPruneReport struct {
// ImagesPruneReport contains the response for Engine API:
// POST "/images/prune"
type ImagesPruneReport struct {
ImagesDeleted []ImageDeleteResponseItem
ImagesDeleted []image.DeleteResponse
SpaceReclaimed uint64
}

Expand Down
16 changes: 16 additions & 0 deletions api/types/types_deprecated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"github.com/docker/docker/api/types/checkpoint"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/system"
)

Expand Down Expand Up @@ -63,6 +64,21 @@ type SecurityOpt = system.SecurityOpt
// Deprecated: use [system.KeyValue].
type KeyValue = system.KeyValue

// ImageDeleteResponseItem image delete response item.
//
// Deprecated: use [image.DeleteResponse].
type ImageDeleteResponseItem = image.DeleteResponse

// ImageSummary image summary.
//
// Deprecated: use [image.Summary].
type ImageSummary = image.Summary

// ImageMetadata contains engine-local data about the image.
//
// Deprecated: use [image.Metadata].
type ImageMetadata = image.Metadata

// DecodeSecurityOptions decodes a security options string slice to a type safe
// [system.SecurityOpt].
//
Expand Down
5 changes: 3 additions & 2 deletions client/image_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import (

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/versions"
)

// ImageList returns a list of images in the docker host.
func (cli *Client) ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error) {
func (cli *Client) ImageList(ctx context.Context, options types.ImageListOptions) ([]image.Summary, error) {
// Make sure we negotiated (if the client is configured to do so),
// as code below contains API-version specific handling of options.
//
// Normally, version-negotiation (if enabled) would not happen until
// the API request is made.
cli.checkVersion(ctx)

var images []types.ImageSummary
var images []image.Summary
query := url.Values{}

optionFilters := options.Filters
Expand Down
5 changes: 3 additions & 2 deletions client/image_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/errdefs"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
Expand Down Expand Up @@ -80,7 +81,7 @@ func TestImageList(t *testing.T) {
return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual)
}
}
content, err := json.Marshal([]types.ImageSummary{
content, err := json.Marshal([]image.Summary{
{
ID: "image_id2",
},
Expand Down Expand Up @@ -121,7 +122,7 @@ func TestImageListApiBefore125(t *testing.T) {
if actualFilters != "" {
return nil, fmt.Errorf("filters should have not been present, were with value: %s", actualFilters)
}
content, err := json.Marshal([]types.ImageSummary{
content, err := json.Marshal([]image.Summary{
{
ID: "image_id2",
},
Expand Down
3 changes: 2 additions & 1 deletion client/image_prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"testing"

"github.com/docker/docker/api/types/image"
"github.com/docker/docker/errdefs"

"github.com/docker/docker/api/types"
Expand Down Expand Up @@ -84,7 +85,7 @@ func TestImagesPrune(t *testing.T) {
assert.Check(t, is.Equal(expected, actual))
}
content, err := json.Marshal(types.ImagesPruneReport{
ImagesDeleted: []types.ImageDeleteResponseItem{
ImagesDeleted: []image.DeleteResponse{
{
Deleted: "image_id1",
},
Expand Down
5 changes: 3 additions & 2 deletions client/image_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"net/url"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/image"
)

// ImageRemove removes an image from the docker host.
func (cli *Client) ImageRemove(ctx context.Context, imageID string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
func (cli *Client) ImageRemove(ctx context.Context, imageID string, options types.ImageRemoveOptions) ([]image.DeleteResponse, error) {
query := url.Values{}

if options.Force {
Expand All @@ -19,7 +20,7 @@ func (cli *Client) ImageRemove(ctx context.Context, imageID string, options type
query.Set("noprune", "1")
}

var dels []types.ImageDeleteResponseItem
var dels []image.DeleteResponse
resp, err := cli.delete(ctx, "/images/"+imageID, query, nil)
defer ensureReaderClosed(resp)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion client/image_remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/errdefs"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
Expand Down Expand Up @@ -74,7 +75,7 @@ func TestImageRemove(t *testing.T) {
return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual)
}
}
b, err := json.Marshal([]types.ImageDeleteResponseItem{
b, err := json.Marshal([]image.DeleteResponse{
{
Untagged: "image_id1",
},
Expand Down
4 changes: 2 additions & 2 deletions client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ type ImageAPIClient interface {
ImageHistory(ctx context.Context, image string) ([]image.HistoryResponseItem, error)
ImageImport(ctx context.Context, source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error)
ImageInspectWithRaw(ctx context.Context, image string) (types.ImageInspect, []byte, error)
ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error)
ImageList(ctx context.Context, options types.ImageListOptions) ([]image.Summary, error)
ImageLoad(ctx context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error)
ImagePull(ctx context.Context, ref string, options types.ImagePullOptions) (io.ReadCloser, error)
ImagePush(ctx context.Context, ref string, options types.ImagePushOptions) (io.ReadCloser, error)
ImageRemove(ctx context.Context, image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error)
ImageRemove(ctx context.Context, image string, options types.ImageRemoveOptions) ([]image.DeleteResponse, error)
ImageSearch(ctx context.Context, term string, options types.ImageSearchOptions) ([]registry.SearchResult, error)
ImageSave(ctx context.Context, images []string) (io.ReadCloser, error)
ImageTag(ctx context.Context, image, ref string) error
Expand Down
20 changes: 10 additions & 10 deletions daemon/containerd/image_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/containerd/containerd/images"
"github.com/containerd/log"
"github.com/distribution/reference"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/events"
imagetypes "github.com/docker/docker/api/types/image"
"github.com/docker/docker/container"
"github.com/docker/docker/image"
"github.com/docker/docker/internal/compatcontext"
Expand Down Expand Up @@ -52,7 +52,7 @@ import (
// conflict will not be reported.
//
// TODO(thaJeztah): image delete should send prometheus counters; see https://github.com/moby/moby/issues/45268
func (i *ImageService) ImageDelete(ctx context.Context, imageRef string, force, prune bool) ([]types.ImageDeleteResponseItem, error) {
func (i *ImageService) ImageDelete(ctx context.Context, imageRef string, force, prune bool) ([]imagetypes.DeleteResponse, error) {
parsedRef, err := reference.ParseNormalizedNamed(imageRef)
if err != nil {
return nil, err
Expand Down Expand Up @@ -80,7 +80,7 @@ func (i *ImageService) ImageDelete(ctx context.Context, imageRef string, force,
return nil, err
}
i.LogImageEvent(imgID.String(), imgID.String(), events.ActionUnTag)
records := []types.ImageDeleteResponseItem{{Untagged: reference.FamiliarString(reference.TagNameOnly(parsedRef))}}
records := []imagetypes.DeleteResponse{{Untagged: reference.FamiliarString(reference.TagNameOnly(parsedRef))}}
return records, nil
}

Expand Down Expand Up @@ -111,7 +111,7 @@ func (i *ImageService) ImageDelete(ctx context.Context, imageRef string, force,
}

i.LogImageEvent(imgID.String(), imgID.String(), events.ActionUnTag)
records := []types.ImageDeleteResponseItem{{Untagged: reference.FamiliarString(reference.TagNameOnly(parsedRef))}}
records := []imagetypes.DeleteResponse{{Untagged: reference.FamiliarString(reference.TagNameOnly(parsedRef))}}
return records, nil
}

Expand All @@ -122,8 +122,8 @@ func (i *ImageService) ImageDelete(ctx context.Context, imageRef string, force,
// also deletes dangling parents if there is no conflict in doing so.
// Parent images are removed quietly, and if there is any issue/conflict
// it is logged but does not halt execution/an error is not returned.
func (i *ImageService) deleteAll(ctx context.Context, img images.Image, force, prune bool) ([]types.ImageDeleteResponseItem, error) {
var records []types.ImageDeleteResponseItem
func (i *ImageService) deleteAll(ctx context.Context, img images.Image, force, prune bool) ([]imagetypes.DeleteResponse, error) {
var records []imagetypes.DeleteResponse

// Workaround for: https://github.com/moby/buildkit/issues/3797
possiblyDeletedConfigs := map[digest.Digest]struct{}{}
Expand Down Expand Up @@ -163,7 +163,7 @@ func (i *ImageService) deleteAll(ctx context.Context, img images.Image, force, p
}
}
i.LogImageEvent(imgID, imgID, events.ActionDelete)
records = append(records, types.ImageDeleteResponseItem{Deleted: imgID})
records = append(records, imagetypes.DeleteResponse{Deleted: imgID})

for _, parent := range parents {
if !isDanglingImage(parent.img) {
Expand All @@ -176,7 +176,7 @@ func (i *ImageService) deleteAll(ctx context.Context, img images.Image, force, p
}
parentID := parent.img.Target.Digest.String()
i.LogImageEvent(parentID, parentID, events.ActionDelete)
records = append(records, types.ImageDeleteResponseItem{Deleted: parentID})
records = append(records, imagetypes.DeleteResponse{Deleted: parentID})
}

return records, nil
Expand Down Expand Up @@ -238,7 +238,7 @@ const (
// images and untagged references are appended to the given records. If any
// error or conflict is encountered, it will be returned immediately without
// deleting the image.
func (i *ImageService) imageDeleteHelper(ctx context.Context, img images.Image, records *[]types.ImageDeleteResponseItem, force bool) error {
func (i *ImageService) imageDeleteHelper(ctx context.Context, img images.Image, records *[]imagetypes.DeleteResponse, force bool) error {
// First, determine if this image has any conflicts. Ignore soft conflicts
// if force is true.
c := conflictHard
Expand All @@ -264,7 +264,7 @@ func (i *ImageService) imageDeleteHelper(ctx context.Context, img images.Image,

if !isDanglingImage(img) {
i.LogImageEvent(imgID.String(), imgID.String(), events.ActionUnTag)
*records = append(*records, types.ImageDeleteResponseItem{Untagged: reference.FamiliarString(untaggedRef)})
*records = append(*records, imagetypes.DeleteResponse{Untagged: reference.FamiliarString(untaggedRef)})
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions daemon/containerd/image_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var acceptedImageFilterTags = map[string]bool{

// byCreated is a temporary type used to sort a list of images by creation
// time.
type byCreated []*types.ImageSummary
type byCreated []*imagetypes.Summary

func (r byCreated) Len() int { return len(r) }
func (r byCreated) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
Expand All @@ -57,7 +57,7 @@ func (r byCreated) Less(i, j int) bool { return r[i].Created < r[j].Created }
// TODO(thaJeztah): implement opts.ContainerCount (used for docker system df); see https://github.com/moby/moby/issues/43853
// TODO(thaJeztah): verify behavior of `RepoDigests` and `RepoTags` for images without (untagged) or multiple tags; see https://github.com/moby/moby/issues/43861
// TODO(thaJeztah): verify "Size" vs "VirtualSize" in images; see https://github.com/moby/moby/issues/43862
func (i *ImageService) Images(ctx context.Context, opts types.ImageListOptions) ([]*types.ImageSummary, error) {
func (i *ImageService) Images(ctx context.Context, opts types.ImageListOptions) ([]*imagetypes.Summary, error) {
if err := opts.Filters.Validate(acceptedImageFilterTags); err != nil {
return nil, err
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func (i *ImageService) Images(ctx context.Context, opts types.ImageListOptions)

var (
allContainers []*container.Container
summaries = make([]*types.ImageSummary, 0, len(imgs))
summaries = make([]*imagetypes.Summary, 0, len(imgs))
root []*[]digest.Digest
layers map[digest.Digest]int
)
Expand Down Expand Up @@ -208,7 +208,7 @@ func (i *ImageService) Images(ctx context.Context, opts types.ImageListOptions)
return summaries, nil
}

func (i *ImageService) singlePlatformImage(ctx context.Context, contentStore content.Store, repoTags []string, imageManifest *ImageManifest, opts types.ImageListOptions, allContainers []*container.Container) (*types.ImageSummary, []digest.Digest, error) {
func (i *ImageService) singlePlatformImage(ctx context.Context, contentStore content.Store, repoTags []string, imageManifest *ImageManifest, opts types.ImageListOptions, allContainers []*container.Container) (*imagetypes.Summary, []digest.Digest, error) {
diffIDs, err := imageManifest.RootFS(ctx)
if err != nil {
return nil, nil, errors.Wrapf(err, "failed to get rootfs of image %s", imageManifest.Name())
Expand Down Expand Up @@ -276,7 +276,7 @@ func (i *ImageService) singlePlatformImage(ctx context.Context, contentStore con
return nil, nil, err
}

summary := &types.ImageSummary{
summary := &imagetypes.Summary{
ParentID: "",
ID: target.String(),
Created: rawImg.CreatedAt.Unix(),
Expand Down
Loading

0 comments on commit 48cacbc

Please sign in to comment.