diff --git a/cache/remotecache/v1/chains.go b/cache/remotecache/v1/chains.go index a6916ebb9e66..644878340ce3 100644 --- a/cache/remotecache/v1/chains.go +++ b/cache/remotecache/v1/chains.go @@ -122,6 +122,8 @@ type DescriptorProviderPair struct { Provider content.Provider } +var _ withCheckDescriptor = DescriptorProviderPair{} + func (p DescriptorProviderPair) ReaderAt(ctx context.Context, desc ocispecs.Descriptor) (content.ReaderAt, error) { return p.Provider.ReaderAt(ctx, desc) } @@ -156,6 +158,13 @@ func (p DescriptorProviderPair) SnapshotLabels(descs []ocispecs.Descriptor, inde return nil } +func (p DescriptorProviderPair) CheckDescriptor(ctx context.Context, desc ocispecs.Descriptor) error { + if cd, ok := p.Provider.(withCheckDescriptor); ok { + return cd.CheckDescriptor(ctx, desc) + } + return nil +} + // item is an implementation of a record in the cache chain. After validation, // normalization and marshalling into the cache config, the item results form // into the "layers", while the digests and the links form into the "records". diff --git a/cache/remotecache/v1/utils.go b/cache/remotecache/v1/utils.go index 213e670a61d2..01d44c90278f 100644 --- a/cache/remotecache/v1/utils.go +++ b/cache/remotecache/v1/utils.go @@ -12,6 +12,11 @@ import ( "github.com/pkg/errors" ) +type withCheckDescriptor interface { + // CheckDescriptor is additional method on Provider to check if the descriptor is available without opening the reader + CheckDescriptor(context.Context, ocispecs.Descriptor) error +} + // sortConfig sorts the config structure to make sure it is deterministic func sortConfig(cc *CacheConfig) { type indexedLayer struct { @@ -279,9 +284,7 @@ func marshalRemote(ctx context.Context, r *solver.Remote, state *marshalState) s return "" } - if cd, ok := r.Provider.(interface { - CheckDescriptor(context.Context, ocispecs.Descriptor) error - }); ok && len(r.Descriptors) > 0 { + if cd, ok := r.Provider.(withCheckDescriptor); ok && len(r.Descriptors) > 0 { for _, d := range r.Descriptors { if cd.CheckDescriptor(ctx, d) != nil { return ""