Skip to content

Commit

Permalink
fix: Also request OCI media type image index (#524)
Browse files Browse the repository at this point in the history
Signed-off-by: jannfis <jann@mistrust.net>

Signed-off-by: jannfis <jann@mistrust.net>
  • Loading branch information
jannfis committed Jan 21, 2023
1 parent 7f059b8 commit c9c124f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/distribution/distribution/v3 v3.0.0-20221208165359-362910506bc2
github.com/go-git/go-git/v5 v5.2.0
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.0.2
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/prometheus/client_golang v1.12.1
github.com/sirupsen/logrus v1.8.1
Expand Down Expand Up @@ -110,7 +111,6 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
16 changes: 12 additions & 4 deletions pkg/registry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/distribution/distribution/v3/registry/client/transport"

"github.com/opencontainers/go-digest"
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"

"go.uber.org/ratelimit"

Expand All @@ -35,6 +36,15 @@ import (

// TODO: Check image's architecture and OS

// knownMediaTypes is the list of media types we can process
var knownMediaTypes = []string{
ocischema.SchemaVersion.MediaType,
schema1.MediaTypeSignedManifest,
schema2.SchemaVersion.MediaType,
manifestlist.SchemaVersion.MediaType,
ociv1.MediaTypeImageIndex,
}

// RegistryClient defines the methods we need for querying container registries
type RegistryClient interface {
NewRepository(nameInRepository string) error
Expand Down Expand Up @@ -159,11 +169,10 @@ func (clt *registryClient) ManifestForTag(tagStr string) (distribution.Manifest,
if err != nil {
return nil, err
}
mediaType := []string{ocischema.SchemaVersion.MediaType, schema1.MediaTypeSignedManifest, schema2.SchemaVersion.MediaType, manifestlist.SchemaVersion.MediaType}
manifest, err := manService.Get(
context.Background(),
digest.FromString(tagStr),
distribution.WithTag(tagStr), distribution.WithManifestMediaTypes(mediaType))
distribution.WithTag(tagStr), distribution.WithManifestMediaTypes(knownMediaTypes))
if err != nil {
return nil, err
}
Expand All @@ -176,11 +185,10 @@ func (clt *registryClient) ManifestForDigest(dgst digest.Digest) (distribution.M
if err != nil {
return nil, err
}
mediaType := []string{ocischema.SchemaVersion.MediaType, schema1.MediaTypeSignedManifest, schema2.SchemaVersion.MediaType, manifestlist.SchemaVersion.MediaType}
manifest, err := manService.Get(
context.Background(),
dgst,
distribution.WithManifestMediaTypes(mediaType))
distribution.WithManifestMediaTypes(knownMediaTypes))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit c9c124f

Please sign in to comment.