Skip to content

Commit 876c889

Browse files
Merge pull request #3384 from mxpv/exec-log-uri
Support --log-uri in exec subcommand
2 parents 3ce077e + 46af8cc commit 876c889

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

cmd/ctr/commands/tasks/exec.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package tasks
1818

1919
import (
2020
"errors"
21+
"net/url"
2122

2223
"github.com/containerd/console"
2324
"github.com/containerd/containerd/cio"
@@ -53,6 +54,10 @@ var execCommand = cli.Command{
5354
Name: "fifo-dir",
5455
Usage: "directory used for storing IO FIFOs",
5556
},
57+
cli.StringFlag{
58+
Name: "log-uri",
59+
Usage: "log uri for custom shim logging",
60+
},
5661
},
5762
Action: func(context *cli.Context) error {
5863
var (
@@ -86,11 +91,31 @@ var execCommand = cli.Command{
8691
pspec.Terminal = tty
8792
pspec.Args = args
8893

89-
cioOpts := []cio.Opt{cio.WithStdio, cio.WithFIFODir(context.String("fifo-dir"))}
90-
if tty {
91-
cioOpts = append(cioOpts, cio.WithTerminal)
94+
var ioCreator cio.Creator
95+
96+
if logURI := context.String("log-uri"); logURI != "" {
97+
uri, err := url.Parse(logURI)
98+
if err != nil {
99+
return err
100+
}
101+
102+
if dir := context.String("fifo-dir"); dir != "" {
103+
return errors.New("can't use log-uri with fifo-dir")
104+
}
105+
106+
if tty {
107+
return errors.New("can't use log-uri with tty")
108+
}
109+
110+
ioCreator = cio.LogURI(uri)
111+
} else {
112+
cioOpts := []cio.Opt{cio.WithStdio, cio.WithFIFODir(context.String("fifo-dir"))}
113+
if tty {
114+
cioOpts = append(cioOpts, cio.WithTerminal)
115+
}
116+
ioCreator = cio.NewCreator(cioOpts...)
92117
}
93-
ioCreator := cio.NewCreator(cioOpts...)
118+
94119
process, err := task.Exec(ctx, context.String("exec-id"), pspec, ioCreator)
95120
if err != nil {
96121
return err

0 commit comments

Comments
 (0)