Skip to content

Commit 636c533

Browse files
committed
Add ctr subcommand to print default OCI spec
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
1 parent 563964e commit 636c533

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

cmd/ctr/app/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/containerd/containerd/cmd/ctr/commands/install"
2828
"github.com/containerd/containerd/cmd/ctr/commands/leases"
2929
namespacesCmd "github.com/containerd/containerd/cmd/ctr/commands/namespaces"
30+
ociCmd "github.com/containerd/containerd/cmd/ctr/commands/oci"
3031
"github.com/containerd/containerd/cmd/ctr/commands/plugins"
3132
"github.com/containerd/containerd/cmd/ctr/commands/pprof"
3233
"github.com/containerd/containerd/cmd/ctr/commands/run"
@@ -112,6 +113,7 @@ containerd CLI
112113
snapshots.Command,
113114
tasks.Command,
114115
install.Command,
116+
ociCmd.Command,
115117
}, extraCmds...)
116118
app.Before = func(context *cli.Context) error {
117119
if context.GlobalBool("debug") {

cmd/ctr/commands/oci/oci.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package oci
18+
19+
import (
20+
"github.com/pkg/errors"
21+
"github.com/urfave/cli"
22+
23+
"github.com/containerd/containerd/cmd/ctr/commands"
24+
"github.com/containerd/containerd/containers"
25+
"github.com/containerd/containerd/oci"
26+
)
27+
28+
var Command = cli.Command{
29+
Name: "oci",
30+
Usage: "OCI tools",
31+
Subcommands: []cli.Command{
32+
defaultSpecCommand,
33+
},
34+
}
35+
36+
var defaultSpecCommand = cli.Command{
37+
Name: "spec",
38+
Usage: "see the output of the default OCI spec",
39+
Action: func(context *cli.Context) error {
40+
ctx, cancel := commands.AppContext(context)
41+
defer cancel()
42+
43+
spec, err := oci.GenerateSpec(ctx, nil, &containers.Container{})
44+
if err != nil {
45+
return errors.Wrap(err, "failed to generate spec")
46+
}
47+
48+
commands.PrintAsJSON(spec)
49+
return nil
50+
},
51+
}

0 commit comments

Comments
 (0)