c8d: Common unpack code for specific manifest
Use `ImageService.unpackImage` when we want to unpack an image and we know the exact platform-manifest to be unpacked beforehand. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
parent
c6bded3475
commit
8832cdf6e1
2 changed files with 13 additions and 10 deletions
|
@ -422,7 +422,7 @@ func (i *ImageService) CreateImage(ctx context.Context, config []byte, parent st
|
|||
}
|
||||
}
|
||||
|
||||
if err := i.unpackImage(ctx, createdImage, platforms.DefaultSpec()); err != nil {
|
||||
if err := i.unpackImage(ctx, i.StorageDriver(), img, commitManifestDesc); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/content"
|
||||
cerrdefs "github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/images"
|
||||
|
@ -150,7 +150,8 @@ func (i *ImageService) ImportImage(ctx context.Context, ref reference.Named, pla
|
|||
logger.WithError(err).Debug("failed to save image")
|
||||
return "", err
|
||||
}
|
||||
err = i.unpackImage(ctx, img, *platform)
|
||||
|
||||
err = i.unpackImage(ctx, i.StorageDriver(), img, manifestDesc)
|
||||
if err != nil {
|
||||
logger.WithError(err).Debug("failed to unpack image")
|
||||
} else {
|
||||
|
@ -312,18 +313,20 @@ func (i *ImageService) saveImage(ctx context.Context, img images.Image) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// unpackImage unpacks the image into the snapshotter.
|
||||
func (i *ImageService) unpackImage(ctx context.Context, img images.Image, platform ocispec.Platform) error {
|
||||
c8dImg := containerd.NewImageWithPlatform(i.client, img, platforms.Only(platform))
|
||||
unpacked, err := c8dImg.IsUnpacked(ctx, i.snapshotter)
|
||||
// unpackImage unpacks the platform-specific manifest of a image into the snapshotter.
|
||||
func (i *ImageService) unpackImage(ctx context.Context, snapshotter string, img images.Image, manifestDesc ocispec.Descriptor) error {
|
||||
c8dImg, err := i.NewImageManifest(ctx, img, manifestDesc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !unpacked {
|
||||
err = c8dImg.Unpack(ctx, i.snapshotter)
|
||||
|
||||
if err := c8dImg.Unpack(ctx, snapshotter); err != nil {
|
||||
if !cerrdefs.IsAlreadyExists(err) {
|
||||
return errdefs.System(fmt.Errorf("failed to unpack image: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
// detectCompression dectects the reader compression type.
|
||||
|
|
Loading…
Add table
Reference in a new issue