From fcabc48ee45e373c0dc40487bcf01be4c3a4f945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Mon, 9 Oct 2023 14:00:07 +0200 Subject: [PATCH] c8d/load: Handle compressed archives MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow to load images from compressed tars. Signed-off-by: Paweł Gronowski --- daemon/containerd/image_exporter.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/daemon/containerd/image_exporter.go b/daemon/containerd/image_exporter.go index 62482d0135336..99c8f85cc9fbe 100644 --- a/daemon/containerd/image_exporter.go +++ b/daemon/containerd/image_exporter.go @@ -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)