Skip to content

Commit

Permalink
Merge pull request containerd#10233 from dmcgowan/1.7-unpack-fetch-all
Browse files Browse the repository at this point in the history
[release/1.7] Unpack fetch all
  • Loading branch information
kzys authored May 15, 2024
2 parents a3c0f2f + 1573ea5 commit 62af107
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
27 changes: 14 additions & 13 deletions cmd/ctr/commands/images/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,25 @@ command. As part of this process, we do the following:
}

var sopts []image.StoreOpt
if !context.Bool("all-platforms") {
var p []ocispec.Platform
for _, s := range context.StringSlice("platform") {
ps, err := platforms.Parse(s)
if err != nil {
return fmt.Errorf("unable to parse platform %s: %w", s, err)
}
p = append(p, ps)

var p []ocispec.Platform
for _, s := range context.StringSlice("platform") {
ps, err := platforms.Parse(s)
if err != nil {
return fmt.Errorf("unable to parse platform %s: %w", s, err)
}
p = append(p, ps)
}

// Set unpack configuration
for _, platform := range p {
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...))

// 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 *?
Expand Down
16 changes: 12 additions & 4 deletions pkg/unpack/unpacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,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)
Expand Down Expand Up @@ -461,12 +462,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()
Expand All @@ -481,11 +488,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()
Expand Down

0 comments on commit 62af107

Please sign in to comment.