@@ -25,14 +25,16 @@ import (
2525 "github.com/containerd/containerd/errdefs"
2626 "github.com/containerd/containerd/images"
2727 "github.com/containerd/containerd/images/archive"
28+ "github.com/containerd/containerd/platforms"
2829 digest "github.com/opencontainers/go-digest"
2930 ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3031)
3132
3233type importOpts struct {
33- indexName string
34- imageRefT func (string ) string
35- dgstRefT func (digest.Digest ) string
34+ indexName string
35+ imageRefT func (string ) string
36+ dgstRefT func (digest.Digest ) string
37+ allPlatforms bool
3638}
3739
3840// ImportOpt allows the caller to specify import specific options
@@ -64,6 +66,14 @@ func WithIndexName(name string) ImportOpt {
6466 }
6567}
6668
69+ // WithAllPlatforms is used to import content for all platforms.
70+ func WithAllPlatforms (allPlatforms bool ) ImportOpt {
71+ return func (c * importOpts ) error {
72+ c .allPlatforms = allPlatforms
73+ return nil
74+ }
75+ }
76+
6777// Import imports an image from a Tar stream using reader.
6878// Caller needs to specify importer. Future version may use oci.v1 as the default.
6979// Note that unreferrenced blobs may be imported to the content store as well.
@@ -98,6 +108,10 @@ func (c *Client) Import(ctx context.Context, reader io.Reader, opts ...ImportOpt
98108 Target : index ,
99109 })
100110 }
111+ var platformMatcher = platforms .All
112+ if ! iopts .allPlatforms {
113+ platformMatcher = platforms .Default ()
114+ }
101115
102116 var handler images.HandlerFunc = func (ctx context.Context , desc ocispec.Descriptor ) ([]ocispec.Descriptor , error ) {
103117 // Only save images at top level
@@ -141,6 +155,7 @@ func (c *Client) Import(ctx context.Context, reader io.Reader, opts ...ImportOpt
141155 return idx .Manifests , nil
142156 }
143157
158+ handler = images .FilterPlatforms (handler , platformMatcher )
144159 handler = images .SetChildrenLabels (cs , handler )
145160 if err := images .Walk (ctx , handler , index ); err != nil {
146161 return nil , err
0 commit comments