Merge pull request #3384 from mxpv/exec-log-uri
Support --log-uri in exec subcommand
This commit is contained in:
commit
876c8890ae
@ -18,6 +18,7 @@ package tasks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
"github.com/containerd/console"
|
"github.com/containerd/console"
|
||||||
"github.com/containerd/containerd/cio"
|
"github.com/containerd/containerd/cio"
|
||||||
@ -53,6 +54,10 @@ var execCommand = cli.Command{
|
|||||||
Name: "fifo-dir",
|
Name: "fifo-dir",
|
||||||
Usage: "directory used for storing IO FIFOs",
|
Usage: "directory used for storing IO FIFOs",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "log-uri",
|
||||||
|
Usage: "log uri for custom shim logging",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(context *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
@ -86,11 +91,31 @@ var execCommand = cli.Command{
|
|||||||
pspec.Terminal = tty
|
pspec.Terminal = tty
|
||||||
pspec.Args = args
|
pspec.Args = args
|
||||||
|
|
||||||
|
var ioCreator cio.Creator
|
||||||
|
|
||||||
|
if logURI := context.String("log-uri"); logURI != "" {
|
||||||
|
uri, err := url.Parse(logURI)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if dir := context.String("fifo-dir"); dir != "" {
|
||||||
|
return errors.New("can't use log-uri with fifo-dir")
|
||||||
|
}
|
||||||
|
|
||||||
|
if tty {
|
||||||
|
return errors.New("can't use log-uri with tty")
|
||||||
|
}
|
||||||
|
|
||||||
|
ioCreator = cio.LogURI(uri)
|
||||||
|
} else {
|
||||||
cioOpts := []cio.Opt{cio.WithStdio, cio.WithFIFODir(context.String("fifo-dir"))}
|
cioOpts := []cio.Opt{cio.WithStdio, cio.WithFIFODir(context.String("fifo-dir"))}
|
||||||
if tty {
|
if tty {
|
||||||
cioOpts = append(cioOpts, cio.WithTerminal)
|
cioOpts = append(cioOpts, cio.WithTerminal)
|
||||||
}
|
}
|
||||||
ioCreator := cio.NewCreator(cioOpts...)
|
ioCreator = cio.NewCreator(cioOpts...)
|
||||||
|
}
|
||||||
|
|
||||||
process, err := task.Exec(ctx, context.String("exec-id"), pspec, ioCreator)
|
process, err := task.Exec(ctx, context.String("exec-id"), pspec, ioCreator)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user