Skip to content

Commit 290fc9e

Browse files
authored
Merge pull request #3301 from dmcgowan/add-run-platform
Fix run with specified platform
2 parents 25daa73 + a274dbe commit 290fc9e

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

cmd/ctr/commands/run/run.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ var Command = cli.Command{
115115
Name: "cgroup",
116116
Usage: "cgroup path (To disable use of cgroup, set to \"\" explicitly)",
117117
},
118+
cli.StringFlag{
119+
Name: "platform",
120+
Usage: "run image for specific platform",
121+
},
118122
}, append(platformRunFlags, append(commands.SnapshotterFlags, commands.ContainerFlags...)...)...),
119123
Action: func(context *cli.Context) error {
120124
var (

cmd/ctr/commands/run/run_unix.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/containerd/containerd/cmd/ctr/commands"
2828
"github.com/containerd/containerd/contrib/nvidia"
2929
"github.com/containerd/containerd/oci"
30+
"github.com/containerd/containerd/platforms"
3031
"github.com/opencontainers/runtime-spec/specs-go"
3132
"github.com/pkg/errors"
3233
"github.com/urfave/cli"
@@ -73,10 +74,21 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
7374
opts = append(opts, oci.WithRootFSPath(rootfs))
7475
} else {
7576
snapshotter := context.String("snapshotter")
76-
image, err := client.GetImage(ctx, ref)
77+
var image containerd.Image
78+
i, err := client.ImageService().Get(ctx, ref)
7779
if err != nil {
7880
return nil, err
7981
}
82+
if ps := context.String("platform"); ps != "" {
83+
platform, err := platforms.Parse(ps)
84+
if err != nil {
85+
return nil, err
86+
}
87+
image = containerd.NewImageWithPlatform(client, i, platforms.Only(platform))
88+
} else {
89+
image = containerd.NewImage(client, i)
90+
}
91+
8092
unpacked, err := image.IsUnpacked(ctx, snapshotter)
8193
if err != nil {
8294
return nil, err

container_opts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func WithSnapshot(id string) NewContainerOpts {
132132
// root filesystem in read-write mode
133133
func WithNewSnapshot(id string, i Image, opts ...snapshots.Opt) NewContainerOpts {
134134
return func(ctx context.Context, client *Client, c *containers.Container) error {
135-
diffIDs, err := i.(*image).i.RootFS(ctx, client.ContentStore(), platforms.Default())
135+
diffIDs, err := i.RootFS(ctx)
136136
if err != nil {
137137
return err
138138
}

0 commit comments

Comments
 (0)