Support --log-uri for exec subcommand

Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
This commit is contained in:
Maksym Pavlenko 2019-07-01 13:32:37 -07:00
parent d1b766a52b
commit 6b59b425e2

View File

@ -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,22 @@ 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
}
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