Skip to content

Commit 63b0c95

Browse files
committed
Faster code to get image digest
Takes 3ms instead of 75ms of my machine Since it’s done each time an image is built, that makes a difference! Signed-off-by: David Gageot <[email protected]>
1 parent 9be665d commit 63b0c95

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

pkg/skaffold/docker/image.go

+4-15
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"net/http"
2323

2424
"github.com/docker/docker/api/types"
25-
"github.com/docker/docker/api/types/filters"
2625
"github.com/docker/docker/pkg/jsonmessage"
2726
"github.com/docker/docker/pkg/progress"
2827
"github.com/docker/docker/pkg/streamformatter"
@@ -125,22 +124,12 @@ func addTag(ref name.Reference, targetRef name.Reference, auth authn.Authenticat
125124
// The digest is of the form
126125
// sha256:<image_id>
127126
func Digest(ctx context.Context, cli APIClient, ref string) (string, error) {
128-
args := filters.KeyValuePair{Key: "reference", Value: ref}
129-
filters := filters.NewArgs(args)
130-
imageList, err := cli.ImageList(ctx, types.ImageListOptions{
131-
Filters: filters,
132-
})
127+
image, _, err := cli.ImageInspectWithRaw(ctx, ref)
133128
if err != nil {
134-
return "", errors.Wrap(err, "getting image id")
135-
}
136-
for _, image := range imageList {
137-
for _, tag := range image.RepoTags {
138-
if tag == ref {
139-
return image.ID, nil
140-
}
141-
}
129+
return "", errors.Wrap(err, "inspecting image")
142130
}
143-
return "", nil
131+
132+
return image.ID, nil
144133
}
145134

146135
func remoteImage(identifier string) (v1.Image, error) {

0 commit comments

Comments
 (0)