@@ -26,6 +26,7 @@ import (
2626 "github.com/containerd/containerd/cmd/ctr/commands"
2727 "github.com/containerd/containerd/images/archive"
2828 "github.com/containerd/containerd/log"
29+ "github.com/containerd/containerd/platforms"
2930 "github.com/urfave/cli"
3031)
3132
@@ -72,6 +73,10 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
7273 Name : "all-platforms" ,
7374 Usage : "imports content for all platforms, false by default" ,
7475 },
76+ cli.BoolFlag {
77+ Name : "platform" ,
78+ Usage : "imports content for specific platform" ,
79+ },
7580 cli.BoolFlag {
7681 Name : "no-unpack" ,
7782 Usage : "skip unpacking the images, false by default" ,
@@ -84,8 +89,9 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
8489
8590 Action : func (context * cli.Context ) error {
8691 var (
87- in = context .Args ().First ()
88- opts []containerd.ImportOpt
92+ in = context .Args ().First ()
93+ opts []containerd.ImportOpt
94+ platformMacher platforms.MatchComparer
8995 )
9096
9197 prefix := context .String ("base-name" )
@@ -115,6 +121,15 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
115121 opts = append (opts , containerd .WithImportCompression ())
116122 }
117123
124+ if platform := context .String ("platform" ); platform != "" {
125+ platSpec , err := platforms .Parse (platform )
126+ if err != nil {
127+ return err
128+ }
129+ platformMacher = platforms .Only (platSpec )
130+ opts = append (opts , containerd .WithImportPlatform (platformMacher ))
131+ }
132+
118133 opts = append (opts , containerd .WithAllPlatforms (context .Bool ("all-platforms" )))
119134
120135 client , ctx , cancel , err := commands .NewClient (context )
@@ -145,8 +160,10 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
145160 log .G (ctx ).Debugf ("unpacking %d images" , len (imgs ))
146161
147162 for _ , img := range imgs {
148- // TODO: Allow configuration of the platform
149- image := containerd .NewImage (client , img )
163+ if platformMacher == nil { // if platform not specified use default.
164+ platformMacher = platforms .Default ()
165+ }
166+ image := containerd .NewImageWithPlatform (client , img , platformMacher )
150167
151168 // TODO: Show unpack status
152169 fmt .Printf ("unpacking %s (%s)..." , img .Name , img .Target .Digest )
0 commit comments