Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/docker/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Command interface {
// When force is true, it will always attempt to pull the image.
Pull(ctx context.Context, ref string, force bool) (*image.InspectResponse, error)
Push(ctx context.Context, ref string) error
LocalImageID(ctx context.Context, ref string) (string, error)
LoadUserInformation(ctx context.Context, registryHost string) (*UserInfo, error)
Inspect(ctx context.Context, ref string) (*image.InspectResponse, error)
ImageExists(ctx context.Context, ref string) (bool, error)
Expand Down
29 changes: 29 additions & 0 deletions pkg/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/docker/docker/api/types"
"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/network"
"github.com/docker/docker/api/types/registry"
Expand Down Expand Up @@ -277,6 +278,34 @@ func (c *apiClient) Inspect(ctx context.Context, ref string) (*image.InspectResp
return &inspect, nil
}

func (c *apiClient) LocalImageID(ctx context.Context, ref string) (string, error) {
console.Debugf("=== APIClient.LocalImageTag %s", ref)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting this debug line to say APIClient.LocalImageID 🤔


if !strings.HasSuffix(ref, ":latest") {
ref = fmt.Sprintf("%s:latest", ref)
}

imageList, err := c.client.ImageList(ctx, image.ListOptions{
Filters: filters.NewArgs(filters.KeyValuePair{
Key: "reference",
Value: ref,
}),
})
if err != nil {
if command.IsNotFoundError(err) {
return "", nil
}
return "", err
}
if len(imageList) == 0 {
return "", &command.NotFoundError{Ref: ref, Object: "image"}
}
if len(imageList) > 1 {
return "", &command.NotFoundError{Ref: ref, Object: "image"}
}
return imageList[0].ID, nil
}

func (c *apiClient) ImageExists(ctx context.Context, ref string) (bool, error) {
console.Debugf("=== APIClient.ImageExists %s", ref)

Expand Down
Loading