Merge pull request #9864 from hinshun/feature/import-compressed

Automatically decompress archives for transfer service import
This commit is contained in:
Maksym Pavlenko 2024-03-19 22:16:25 +00:00 committed by GitHub
commit 124456ef83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -28,6 +28,7 @@ import (
"github.com/containerd/containerd/v2/core/images/archive" "github.com/containerd/containerd/v2/core/images/archive"
"github.com/containerd/containerd/v2/core/streaming" "github.com/containerd/containerd/v2/core/streaming"
tstreaming "github.com/containerd/containerd/v2/core/transfer/streaming" tstreaming "github.com/containerd/containerd/v2/core/transfer/streaming"
"github.com/containerd/containerd/v2/pkg/archive/compression"
"github.com/containerd/log" "github.com/containerd/log"
) )
@ -64,7 +65,18 @@ func (iis *ImageImportStream) Import(ctx context.Context, store content.Store) (
if iis.forceCompress { if iis.forceCompress {
opts = append(opts, archive.WithImportCompression()) opts = append(opts, archive.WithImportCompression())
} }
return archive.ImportIndex(ctx, store, iis.stream, opts...)
r := iis.stream
if iis.mediaType == "" {
d, err := compression.DecompressStream(iis.stream)
if err != nil {
return ocispec.Descriptor{}, err
}
defer d.Close()
r = d
}
return archive.ImportIndex(ctx, store, r, opts...)
} }
func (iis *ImageImportStream) MarshalAny(ctx context.Context, sm streaming.StreamCreator) (typeurl.Any, error) { func (iis *ImageImportStream) MarshalAny(ctx context.Context, sm streaming.StreamCreator) (typeurl.Any, error) {