Merge pull request #10202 from dmcgowan/unpack-fetch-all

Unpack fetch all
This commit is contained in:
Maksym Pavlenko 2024-05-11 20:17:27 +00:00 committed by GitHub
commit 29a6ab8261
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 13 deletions

View File

@ -106,20 +106,20 @@ command. As part of this process, we do the following:
} }
var sopts []image.StoreOpt var sopts []image.StoreOpt
if !context.Bool("all-platforms") {
p, err := platforms.ParseAll(context.StringSlice("platform")) p, err := platforms.ParseAll(context.StringSlice("platform"))
if err != nil { if err != nil {
return err return err
} }
if len(p) == 0 {
p = append(p, platforms.DefaultSpec())
}
sopts = append(sopts, image.WithPlatforms(p...))
// Set unpack configuration // Set unpack configuration
for _, platform := range p { for _, platform := range p {
sopts = append(sopts, image.WithUnpack(platform, context.String("snapshotter"))) sopts = append(sopts, image.WithUnpack(platform, context.String("snapshotter")))
} }
if !context.Bool("all-platforms") {
if len(p) == 0 {
p = append(p, platforms.DefaultSpec())
}
sopts = append(sopts, image.WithPlatforms(p...))
} }
// TODO: Support unpack for all platforms..? // TODO: Support unpack for all platforms..?
// Pass in a *? // Pass in a *?

View File

@ -262,7 +262,8 @@ func (u *Unpacker) unpack(
} }
if unpack == nil { 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) 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()), tracing.Attribute("layer.media.digest", desc.Digest.String()),
) )
desc := desc desc := desc
i := i var ch chan struct{}
if done != nil {
ch = done[i]
}
if err := u.acquire(ctx); err != nil { if err := u.acquire(ctx); err != nil {
return err return err
} }
eg.Go(func() error { eg.Go(func() error {
defer layerSpan.End()
unlock, err := u.lockBlobDescriptor(ctx2, desc) unlock, err := u.lockBlobDescriptor(ctx2, desc)
if err != nil { if err != nil {
u.release() 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) { if err != nil && !errors.Is(err, images.ErrSkipDesc) {
return err return err
} }
close(done[i]) if ch != nil {
close(ch)
}
return nil return nil
}) })
layerSpan.End()
} }
return eg.Wait() return eg.Wait()