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:
parent
9a7c264d25
commit
0abc2f160c
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||||
"github.com/containerd/containerd/containers"
|
"github.com/containerd/containerd/containers"
|
||||||
"github.com/containerd/containerd/oci"
|
"github.com/containerd/containerd/oci"
|
||||||
|
"github.com/containerd/containerd/platforms"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Command is the parent for all OCI related tools under 'oci'
|
// Command is the parent for all OCI related tools under 'oci'
|
||||||
@ -38,11 +39,22 @@ var Command = cli.Command{
|
|||||||
var defaultSpecCommand = cli.Command{
|
var defaultSpecCommand = cli.Command{
|
||||||
Name: "spec",
|
Name: "spec",
|
||||||
Usage: "see the output of the default OCI 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 {
|
Action: func(context *cli.Context) error {
|
||||||
ctx, cancel := commands.AppContext(context)
|
ctx, cancel := commands.AppContext(context)
|
||||||
defer cancel()
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to generate spec: %w", err)
|
return fmt.Errorf("failed to generate spec: %w", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user