Skip to content

Commit 1d9b969

Browse files
committed
fix when --config provided, don't need Image/RootFS
Signed-off-by: Lifubang <[email protected]>
1 parent 830363a commit 1d9b969

3 files changed

Lines changed: 43 additions & 12 deletions

File tree

cmd/ctr/commands/containers/containers.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,22 @@ var createCommand = cli.Command{
5353
Flags: append(commands.SnapshotterFlags, commands.ContainerFlags...),
5454
Action: func(context *cli.Context) error {
5555
var (
56-
id = context.Args().Get(1)
57-
ref = context.Args().First()
56+
id string
57+
ref string
58+
config = context.IsSet("config")
5859
)
59-
if ref == "" {
60-
return errors.New("image ref must be provided")
60+
61+
if config {
62+
id = context.Args().First()
63+
if context.NArg() > 1 {
64+
return errors.New("with spec config file, only container id should be provided")
65+
}
66+
} else {
67+
id = context.Args().Get(1)
68+
ref = context.Args().First()
69+
if ref == "" {
70+
return errors.New("image ref must be provided")
71+
}
6172
}
6273
if id == "" {
6374
return errors.New("container id must be provided")

cmd/ctr/commands/run/run.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,26 @@ var Command = cli.Command{
110110
Action: func(context *cli.Context) error {
111111
var (
112112
err error
113+
id string
114+
ref string
113115

114-
id = context.Args().Get(1)
115-
ref = context.Args().First()
116116
tty = context.Bool("tty")
117117
detach = context.Bool("detach")
118+
config = context.IsSet("config")
118119
)
119120

120-
if ref == "" {
121-
return errors.New("image ref must be provided")
121+
if config {
122+
id = context.Args().First()
123+
if context.NArg() > 1 {
124+
return errors.New("with spec config file, only container id should be provided")
125+
}
126+
} else {
127+
id = context.Args().Get(1)
128+
ref = context.Args().First()
129+
130+
if ref == "" {
131+
return errors.New("image ref must be provided")
132+
}
122133
}
123134
if id == "" {
124135
return errors.New("container id must be provided")

cmd/ctr/commands/run/run_unix.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ import (
3434
// NewContainer creates a new container
3535
func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli.Context) (containerd.Container, error) {
3636
var (
37-
ref = context.Args().First()
38-
id = context.Args().Get(1)
39-
args = context.Args()[2:]
37+
id string
38+
Config = context.IsSet("config")
4039
)
40+
if Config {
41+
id = context.Args().First()
42+
} else {
43+
id = context.Args().Get(1)
44+
}
4145

4246
if raw := context.String("checkpoint"); raw != "" {
4347
im, err := client.GetImage(ctx, raw)
@@ -53,9 +57,14 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
5357
spec containerd.NewContainerOpts
5458
)
5559

56-
if context.IsSet("config") {
60+
if Config {
5761
opts = append(opts, oci.WithSpecFromFile(context.String("config")))
5862
} else {
63+
var (
64+
ref = context.Args().First()
65+
//for container's id is Args[1]
66+
args = context.Args()[2:]
67+
)
5968
opts = append(opts, oci.WithDefaultSpec(), oci.WithDefaultUnixDevices)
6069
opts = append(opts, oci.WithEnv(context.StringSlice("env")))
6170
opts = append(opts, withMounts(context))

0 commit comments

Comments
 (0)