From 2788604e496c4010423ce47d693876605168dc3c Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Thu, 9 May 2024 20:48:38 -0700 Subject: [PATCH 1/2] Update ctr image pull all platforms Allows supporting fetching of all platforms while unpacking for a subset of platforms. Signed-off-by: Derek McGowan --- cmd/ctr/commands/images/pull.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/ctr/commands/images/pull.go b/cmd/ctr/commands/images/pull.go index 6d8d8ea5a..0b0de7c05 100644 --- a/cmd/ctr/commands/images/pull.go +++ b/cmd/ctr/commands/images/pull.go @@ -106,20 +106,20 @@ command. As part of this process, we do the following: } var sopts []image.StoreOpt + p, err := platforms.ParseAll(context.StringSlice("platform")) + if err != nil { + return err + } + + // Set unpack configuration + for _, platform := range p { + sopts = append(sopts, image.WithUnpack(platform, context.String("snapshotter"))) + } if !context.Bool("all-platforms") { - p, err := platforms.ParseAll(context.StringSlice("platform")) - if err != nil { - return err - } if len(p) == 0 { p = append(p, platforms.DefaultSpec()) } sopts = append(sopts, image.WithPlatforms(p...)) - - // Set unpack configuration - for _, platform := range p { - sopts = append(sopts, image.WithUnpack(platform, context.String("snapshotter"))) - } } // TODO: Support unpack for all platforms..? // Pass in a *? From 681a083fabed69cb37f0f4fdaa893aa243e8244b Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Thu, 9 May 2024 00:14:55 -0700 Subject: [PATCH 2/2] Update unpacker to always fetch all When a set of layers are provided to the unpacker, then the unpacker should still fetch them regardless of whether they will be used for unpack. The image handler filters are responsible for removing content which is not intended to be fetched. Currently there is no way to use an unpacker and also fetch all platforms. Signed-off-by: Derek McGowan --- core/unpack/unpacker.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/core/unpack/unpacker.go b/core/unpack/unpacker.go index 91d9e8111..5bf9baf2f 100644 --- a/core/unpack/unpacker.go +++ b/core/unpack/unpacker.go @@ -262,7 +262,8 @@ func (u *Unpacker) unpack( } if unpack == nil { - return fmt.Errorf("unpacker does not support platform %s for image %s", imgPlatform, config.Digest) + log.G(ctx).WithField("image", config.Digest).WithField("platform", platforms.Format(imgPlatform)).Debugf("unpacker does not support platform, only fetching layers") + return u.fetch(ctx, h, layers, nil) } atomic.AddInt32(&u.unpacks, 1) @@ -460,12 +461,18 @@ func (u *Unpacker) fetch(ctx context.Context, h images.Handler, layers []ocispec tracing.Attribute("layer.media.digest", desc.Digest.String()), ) desc := desc - i := i + var ch chan struct{} + if done != nil { + ch = done[i] + } + if err := u.acquire(ctx); err != nil { return err } eg.Go(func() error { + defer layerSpan.End() + unlock, err := u.lockBlobDescriptor(ctx2, desc) if err != nil { u.release() @@ -480,11 +487,12 @@ func (u *Unpacker) fetch(ctx context.Context, h images.Handler, layers []ocispec if err != nil && !errors.Is(err, images.ErrSkipDesc) { return err } - close(done[i]) + if ch != nil { + close(ch) + } return nil }) - layerSpan.End() } return eg.Wait()