Fix run with specified platform

Adds the platform flag to the run command and resolves
the image based on that platform.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan 2019-05-23 11:57:53 -07:00
parent ec0b722083
commit a274dbe822
No known key found for this signature in database
GPG Key ID: F58C5D0A4405ACDB
3 changed files with 18 additions and 2 deletions

View File

@ -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 (

View File

@ -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

View File

@ -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
}