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 <danny@dcantah.dev>
This commit is contained in:
Danny Canter 2023-01-03 00:53:02 -08:00
parent 9a7c264d25
commit 0abc2f160c

View File

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