Merge pull request #5266 from Ace-Tang/ace
ctr: add --user for task exec
This commit is contained in:
commit
f2d84035f6
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/cio"
|
"github.com/containerd/containerd/cio"
|
||||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||||
|
"github.com/containerd/containerd/oci"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
@ -61,6 +62,10 @@ var execCommand = cli.Command{
|
|||||||
Name: "log-uri",
|
Name: "log-uri",
|
||||||
Usage: "log uri for custom shim logging",
|
Usage: "log uri for custom shim logging",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "user",
|
||||||
|
Usage: "user id or name",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(context *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
@ -85,15 +90,25 @@ var execCommand = cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
task, err := container.Task(ctx, nil)
|
if user := context.String("user"); user != "" {
|
||||||
|
c, err := container.Info(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := oci.WithUser(user)(ctx, client, &c, spec); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pspec := spec.Process
|
pspec := spec.Process
|
||||||
pspec.Terminal = tty
|
pspec.Terminal = tty
|
||||||
pspec.Args = args
|
pspec.Args = args
|
||||||
|
|
||||||
|
task, err := container.Task(ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ioCreator cio.Creator
|
ioCreator cio.Creator
|
||||||
stdinC = &stdinCloser{
|
stdinC = &stdinCloser{
|
||||||
|
Loading…
Reference in New Issue
Block a user