Merge pull request #3301 from dmcgowan/add-run-platform
Fix run with specified platform
This commit is contained in:
		| @@ -115,6 +115,10 @@ var Command = cli.Command{ | ||||
| 			Name:  "cgroup", | ||||
| 			Usage: "cgroup path (To disable use of cgroup, set to \"\" explicitly)", | ||||
| 		}, | ||||
| 		cli.StringFlag{ | ||||
| 			Name:  "platform", | ||||
| 			Usage: "run image for specific platform", | ||||
| 		}, | ||||
| 	}, append(platformRunFlags, append(commands.SnapshotterFlags, commands.ContainerFlags...)...)...), | ||||
| 	Action: func(context *cli.Context) error { | ||||
| 		var ( | ||||
|   | ||||
| @@ -27,6 +27,7 @@ import ( | ||||
| 	"github.com/containerd/containerd/cmd/ctr/commands" | ||||
| 	"github.com/containerd/containerd/contrib/nvidia" | ||||
| 	"github.com/containerd/containerd/oci" | ||||
| 	"github.com/containerd/containerd/platforms" | ||||
| 	"github.com/opencontainers/runtime-spec/specs-go" | ||||
| 	"github.com/pkg/errors" | ||||
| 	"github.com/urfave/cli" | ||||
| @@ -73,10 +74,21 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli | ||||
| 			opts = append(opts, oci.WithRootFSPath(rootfs)) | ||||
| 		} else { | ||||
| 			snapshotter := context.String("snapshotter") | ||||
| 			image, err := client.GetImage(ctx, ref) | ||||
| 			var image containerd.Image | ||||
| 			i, err := client.ImageService().Get(ctx, ref) | ||||
| 			if err != nil { | ||||
| 				return nil, err | ||||
| 			} | ||||
| 			if ps := context.String("platform"); ps != "" { | ||||
| 				platform, err := platforms.Parse(ps) | ||||
| 				if err != nil { | ||||
| 					return nil, err | ||||
| 				} | ||||
| 				image = containerd.NewImageWithPlatform(client, i, platforms.Only(platform)) | ||||
| 			} else { | ||||
| 				image = containerd.NewImage(client, i) | ||||
| 			} | ||||
|  | ||||
| 			unpacked, err := image.IsUnpacked(ctx, snapshotter) | ||||
| 			if err != nil { | ||||
| 				return nil, err | ||||
|   | ||||
| @@ -132,7 +132,7 @@ func WithSnapshot(id string) NewContainerOpts { | ||||
| // root filesystem in read-write mode | ||||
| func WithNewSnapshot(id string, i Image, opts ...snapshots.Opt) NewContainerOpts { | ||||
| 	return func(ctx context.Context, client *Client, c *containers.Container) error { | ||||
| 		diffIDs, err := i.(*image).i.RootFS(ctx, client.ContentStore(), platforms.Default()) | ||||
| 		diffIDs, err := i.RootFS(ctx) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Wei Fu
					Wei Fu