From 0abc2f160c94423e367394903f348f72b20f6e9c Mon Sep 17 00:00:00 2001 From: Danny Canter Date: Tue, 3 Jan 2023 00:53:02 -0800 Subject: [PATCH] ctr: Add platform flag to 'oci spec' command This adds in a simple flag to control what platform the spec it generates is for. Useful to easily get a glance at whats the default across platforms. Signed-off-by: Danny Canter --- cmd/ctr/commands/oci/oci.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/ctr/commands/oci/oci.go b/cmd/ctr/commands/oci/oci.go index cbd64fee3..45251314c 100644 --- a/cmd/ctr/commands/oci/oci.go +++ b/cmd/ctr/commands/oci/oci.go @@ -24,6 +24,7 @@ import ( "github.com/containerd/containerd/cmd/ctr/commands" "github.com/containerd/containerd/containers" "github.com/containerd/containerd/oci" + "github.com/containerd/containerd/platforms" ) // Command is the parent for all OCI related tools under 'oci' @@ -38,11 +39,22 @@ var Command = cli.Command{ var defaultSpecCommand = cli.Command{ Name: "spec", Usage: "see the output of the default OCI spec", + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "platform", + Usage: "platform of the spec to print (Examples: 'linux/arm64', 'windows/amd64')", + }, + }, Action: func(context *cli.Context) error { ctx, cancel := commands.AppContext(context) defer cancel() - spec, err := oci.GenerateSpec(ctx, nil, &containers.Container{}) + platform := platforms.DefaultString() + if plat := context.String("platform"); plat != "" { + platform = plat + } + + spec, err := oci.GenerateSpecWithPlatform(ctx, nil, platform, &containers.Container{}) if err != nil { return fmt.Errorf("failed to generate spec: %w", err) }