diff --git a/pkg/content/local.go b/pkg/content/local.go index d238bb8f..fa30c862 100644 --- a/pkg/content/local.go +++ b/pkg/content/local.go @@ -110,7 +110,7 @@ func (pvd *LocalProvider) Image(ctx context.Context, ref string) (*ocispec.Descr if err != nil { return nil, err } - target := image.Target() + target := containerd.NewImageWithPlatform(pvd.client, image.Metadata(), pvd.platformMC).Target() return &target, nil } diff --git a/pkg/converter/converter.go b/pkg/converter/converter.go index b127d541..5b820b65 100644 --- a/pkg/converter/converter.go +++ b/pkg/converter/converter.go @@ -26,7 +26,6 @@ import ( "github.com/containerd/containerd/reference/docker" "github.com/goharbor/acceleration-service/pkg/content" "github.com/goharbor/acceleration-service/pkg/driver" - nydusUtils "github.com/goharbor/acceleration-service/pkg/driver/nydus/utils" "github.com/goharbor/acceleration-service/pkg/errdefs" "github.com/goharbor/acceleration-service/pkg/utils" ) @@ -51,7 +50,6 @@ func New(opts ...ConvertOpt) (*Converter, error) { if options.platformMC != nil { platformMC = options.platformMC } - platformMC = nydusUtils.ExcludeNydusPlatformComparer{MatchComparer: platformMC} driver, err := driver.NewLocalDriver(options.driverType, options.driverConfig, platformMC) if err != nil { @@ -80,7 +78,7 @@ func (cvt *Converter) pull(ctx context.Context, source string) error { // Write a diff id label of layer in content store for simplifying // diff id calculation to speed up the conversion. // See: /~https://github.com/containerd/containerd/blob/e4fefea5544d259177abb85b64e428702ac49c97/images/diffid.go#L49 - if err := utils.UpdateLayerDiffID(ctx, cvt.provider.ContentStore(), *image); err != nil { + if err := utils.UpdateLayerDiffID(ctx, cvt.provider.ContentStore(), *image, cvt.platformMC); err != nil { return errors.Wrap(err, "update layer diff id") } diff --git a/pkg/driver/nydus/nydus.go b/pkg/driver/nydus/nydus.go index 18a961aa..93fdb5b3 100644 --- a/pkg/driver/nydus/nydus.go +++ b/pkg/driver/nydus/nydus.go @@ -28,7 +28,6 @@ import ( nydusify "github.com/containerd/nydus-snapshotter/pkg/converter" "github.com/goharbor/acceleration-service/pkg/driver/nydus/parser" "github.com/goharbor/acceleration-service/pkg/errdefs" - "github.com/goharbor/harbor/src/jobservice/logger" "github.com/opencontainers/image-spec/specs-go" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" @@ -227,12 +226,12 @@ func (d *Driver) convert(ctx context.Context, provider accelcontent.Provider, so } func (d *Driver) makeManifestIndex(ctx context.Context, cs content.Store, oci, nydus ocispec.Descriptor) (*ocispec.Descriptor, error) { - ociDescs, err := utils.GetManifests(ctx, cs, oci) + ociDescs, err := utils.GetManifests(ctx, cs, oci, d.platformMC) if err != nil { return nil, errors.Wrap(err, "get oci image manifest list") } - nydusDescs, err := utils.GetManifests(ctx, cs, nydus) + nydusDescs, err := utils.GetManifests(ctx, cs, nydus, d.platformMC) if err != nil { return nil, errors.Wrap(err, "get nydus image manifest list") } @@ -284,7 +283,7 @@ func (d *Driver) getChunkDict(ctx context.Context, provider accelcontent.Provide bootstrapReader, _, err := parser.PullAsChunkDict(ctx, d.chunkDictRef, false) if err != nil { if errdefs.NeedsRetryWithHTTP(err) { - logger.Infof("try to pull chunk dict image with plain HTTP for %s", d.chunkDictRef) + logrus.Infof("try to pull chunk dict image with plain HTTP for %s", d.chunkDictRef) bootstrapReader, _, err = parser.PullAsChunkDict(ctx, d.chunkDictRef, true) if err != nil { return nil, errors.Wrapf(err, "try to pull chunk dict image %s", d.chunkDictRef) diff --git a/pkg/platformutil/platformutil.go b/pkg/platformutil/platformutil.go index b02394cb..79558900 100644 --- a/pkg/platformutil/platformutil.go +++ b/pkg/platformutil/platformutil.go @@ -5,7 +5,6 @@ import ( "strings" "github.com/containerd/containerd/platforms" - nydusUtils "github.com/goharbor/acceleration-service/pkg/driver/nydus/utils" ocispec "github.com/opencontainers/image-spec/specs-go/v1" ) @@ -33,11 +32,7 @@ func ParsePlatforms(all bool, ss string) (platforms.MatchComparer, error) { platforms = append(platforms, plat) } } - platformMC, err := NewMatchComparer(all, platforms) - if err != nil { - return nil, err - } - return nydusUtils.ExcludeNydusPlatformComparer{MatchComparer: platformMC}, nil + return NewMatchComparer(all, platforms) } // Ported from nerdctl project, copyright The containerd Authors. diff --git a/pkg/remote/resolve.go b/pkg/remote/resolve.go index fc55bfb2..afc166c5 100644 --- a/pkg/remote/resolve.go +++ b/pkg/remote/resolve.go @@ -79,10 +79,12 @@ func NewDockerConfigCredFunc() CredentialFunc { func NewResolver(insecure, plainHTTP bool, credFunc CredentialFunc) remotes.Resolver { registryHosts := docker.ConfigureDefaultRegistries( - docker.WithAuthorizer(docker.NewAuthorizer( - newDefaultClient(insecure), - credFunc, - )), + docker.WithAuthorizer( + docker.NewDockerAuthorizer( + docker.WithAuthClient(newDefaultClient(insecure)), + docker.WithAuthCreds(credFunc), + ), + ), docker.WithClient(newDefaultClient(insecure)), docker.WithPlainHTTP(func(host string) (bool, error) { return plainHTTP, nil diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index ff5011fb..0573e025 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -9,6 +9,7 @@ import ( "github.com/containerd/containerd/content" "github.com/containerd/containerd/images" "github.com/containerd/containerd/labels" + "github.com/containerd/containerd/platforms" "github.com/opencontainers/go-digest" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" @@ -59,32 +60,12 @@ func WriteJSON(ctx context.Context, cs content.Store, x interface{}, oldDesc oci return &newDesc, nil } -func GetManifests(ctx context.Context, provider content.Provider, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) { - var descs []ocispec.Descriptor - switch desc.MediaType { - case images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest: - descs = append(descs, desc) - case images.MediaTypeDockerSchema2ManifestList, ocispec.MediaTypeImageIndex: - p, err := content.ReadBlob(ctx, provider, desc) - if err != nil { - return nil, err - } - - var index ocispec.Index - if err := json.Unmarshal(p, &index); err != nil { - return nil, err - } - - descs = append(descs, index.Manifests...) - default: - return nil, nil - } - - return descs, nil +func GetManifests(ctx context.Context, provider content.Provider, desc ocispec.Descriptor, platform platforms.MatchComparer) ([]ocispec.Descriptor, error) { + return images.FilterPlatforms(images.ChildrenHandler(provider), platform)(ctx, desc) } -func UpdateLayerDiffID(ctx context.Context, cs content.Store, image ocispec.Descriptor) error { - maniDescs, err := GetManifests(ctx, cs, image) +func UpdateLayerDiffID(ctx context.Context, cs content.Store, image ocispec.Descriptor, platform platforms.MatchComparer) error { + maniDescs, err := GetManifests(ctx, cs, image, platform) if err != nil { return errors.Wrap(err, "get manifests") }