Skip to content

Commit

Permalink
Merge pull request #4771 from tonistiigi/gha-checkdescriptor-fix
Browse files Browse the repository at this point in the history
remotecache: fix missing CheckDescriptor method
  • Loading branch information
tonistiigi committed Mar 18, 2024
2 parents 1d5a3ee + 5a8856d commit c23f565
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 9 additions & 0 deletions cache/remotecache/v1/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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".
Expand Down
9 changes: 6 additions & 3 deletions cache/remotecache/v1/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 ""
Expand Down

0 comments on commit c23f565

Please sign in to comment.