Merge pull request #46605 from vvoland/c8d-load-compressed

c8d/load: Handle compressed archives
This commit is contained in:
Paweł Gronowski 2023-10-11 13:48:30 +02:00 committed by GitHub
commit e78152aecb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,6 +17,7 @@ import (
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/container"
"github.com/docker/docker/errdefs"
dockerarchive "github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/platforms"
"github.com/docker/docker/pkg/streamformatter"
"github.com/opencontainers/image-spec/specs-go"
@ -148,6 +149,12 @@ func leaseContent(ctx context.Context, store content.Store, leasesManager leases
// complement of ExportImage. The input stream is an uncompressed tar
// ball containing images and metadata.
func (i *ImageService) LoadImage(ctx context.Context, inTar io.ReadCloser, outStream io.Writer, quiet bool) error {
decompressed, err := dockerarchive.DecompressStream(inTar)
if err != nil {
return errors.Wrap(err, "failed to decompress input tar archive")
}
defer decompressed.Close()
opts := []containerd.ImportOpt{
// TODO(vvoland): Allow user to pass platform
containerd.WithImportPlatform(cplatforms.All),
@ -164,7 +171,7 @@ func (i *ImageService) LoadImage(ctx context.Context, inTar io.ReadCloser, outSt
}),
}
imgs, err := i.client.Import(ctx, inTar, opts...)
imgs, err := i.client.Import(ctx, decompressed, opts...)
if err != nil {
log.G(ctx).WithError(err).Debug("failed to import image to containerd")
return errdefs.System(err)