Merge pull request #7763 from cpuguy83/simpler_pushcontent

Change PushContent to require only Provider
This commit is contained in:
Fu Wei 2022-12-07 09:39:09 +08:00 committed by GitHub
commit 0fa51f54df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -198,7 +198,10 @@ func push(ctx context.Context, provider content.Provider, pusher Pusher, desc oc
// //
// Base handlers can be provided which will be called before any push specific // Base handlers can be provided which will be called before any push specific
// handlers. // handlers.
func PushContent(ctx context.Context, pusher Pusher, desc ocispec.Descriptor, store content.Store, limiter *semaphore.Weighted, platform platforms.MatchComparer, wrapper func(h images.Handler) images.Handler) error { //
// If the passed in content.Provider is also a content.Manager then this will
// also annotate the distribution sources in the manager.
func PushContent(ctx context.Context, pusher Pusher, desc ocispec.Descriptor, store content.Provider, limiter *semaphore.Weighted, platform platforms.MatchComparer, wrapper func(h images.Handler) images.Handler) error {
var m sync.Mutex var m sync.Mutex
manifests := []ocispec.Descriptor{} manifests := []ocispec.Descriptor{}
@ -225,13 +228,14 @@ func PushContent(ctx context.Context, pusher Pusher, desc ocispec.Descriptor, st
platformFilterhandler := images.FilterPlatforms(images.ChildrenHandler(store), platform) platformFilterhandler := images.FilterPlatforms(images.ChildrenHandler(store), platform)
annotateHandler := annotateDistributionSourceHandler(platformFilterhandler, store) var handler images.Handler
if m, ok := store.(content.Manager); ok {
annotateHandler := annotateDistributionSourceHandler(platformFilterhandler, m)
handler = images.Handlers(annotateHandler, filterHandler, pushHandler)
} else {
handler = images.Handlers(platformFilterhandler, filterHandler, pushHandler)
}
var handler images.Handler = images.Handlers(
annotateHandler,
filterHandler,
pushHandler,
)
if wrapper != nil { if wrapper != nil {
handler = wrapper(handler) handler = wrapper(handler)
} }