Skip to content

Commit

Permalink
feat: use Get to determine digest of an image
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanholsteijn committed Jul 31, 2023
1 parent 7e9123d commit 32f2fed
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
8 changes: 2 additions & 6 deletions ref/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,12 @@ func (r ContainerImageReference) ResolveDigest() (*ContainerImageReference, erro
return nil, err
}

img, err := remote.Image(ref, remote.WithAuthFromKeychain(authn.DefaultKeychain))
if err != nil {
return nil, err
}
digest, err := img.Digest()
descriptor, err := remote.Get(ref, remote.WithAuthFromKeychain(authn.DefaultKeychain))
if err != nil {
return nil, fmt.Errorf("failed to get Digest for %s, %s", r, err)
}

return &ContainerImageReference{Name: r.Name, Tag: r.Tag, Digest: digest.String()}, nil
return &ContainerImageReference{Name: r.Name, Tag: r.Tag, Digest: descriptor.Digest.String()}, nil
}

func (r *ContainerImageReference) SetTag(tag string) {
Expand Down
7 changes: 2 additions & 5 deletions ref/resolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ func TestImageResolve(t *testing.T) {
t.Fatal(err)
}

img, err := remote.Image(ref, remote.WithAuthFromKeychain(authn.DefaultKeychain))
if err != nil {
t.Fatal(err)
}
digest, err := img.Digest()
descriptor, err := remote.Get(ref, remote.WithAuthFromKeychain(authn.DefaultKeychain))
if err != nil {
t.Fatal(err)
}
digest := descriptor.Digest

if digest.String() != rr.Digest {
t.Fatalf("expected %s, got %s", digest, rr.Digest)
Expand Down

0 comments on commit 32f2fed

Please sign in to comment.