diff --git a/cio/io.go b/cio/io.go index 8ee13edda4a3..055d13fef3d5 100644 --- a/cio/io.go +++ b/cio/io.go @@ -260,26 +260,6 @@ func BinaryIO(binary string, args map[string]string) Creator { } } -// TerminalBinaryIO forwards container STDOUT|STDERR directly to a logging binary -// It also sets the terminal option to true -func TerminalBinaryIO(binary string, args map[string]string) Creator { - return func(_ string) (IO, error) { - uri, err := LogURIGenerator("binary", binary, args) - if err != nil { - return nil, err - } - - res := uri.String() - return &logURI{ - config: Config{ - Stdout: res, - Stderr: res, - Terminal: true, - }, - }, nil - } -} - // LogFile creates a file on disk that logs the task's STDOUT,STDERR. // If the log file already exists, the logs will be appended to the file. func LogFile(path string) Creator { diff --git a/cio/io_unix.go b/cio/io_unix.go index 5606cc88a942..ba95d40a8cda 100644 --- a/cio/io_unix.go +++ b/cio/io_unix.go @@ -23,6 +23,7 @@ import ( "context" "fmt" "io" + "net/url" "os" "path/filepath" "sync" @@ -152,3 +153,37 @@ func NewDirectIO(ctx context.Context, fifos *FIFOSet) (*DirectIO, error) { }, }, err } + +// TerminalLogURI provides the raw logging URI +// as well as sets the terminal option to true. +func TerminalLogURI(uri *url.URL) Creator { + return func(_ string) (IO, error) { + return &logURI{ + config: Config{ + Stdout: uri.String(), + Stderr: uri.String(), + Terminal: true, + }, + }, nil + } +} + +// TerminalBinaryIO forwards container STDOUT|STDERR directly to a logging binary +// It also sets the terminal option to true +func TerminalBinaryIO(binary string, args map[string]string) Creator { + return func(_ string) (IO, error) { + uri, err := LogURIGenerator("binary", binary, args) + if err != nil { + return nil, err + } + + res := uri.String() + return &logURI{ + config: Config{ + Stdout: res, + Stderr: res, + Terminal: true, + }, + }, nil + } +} diff --git a/cio/io_windows.go b/cio/io_windows.go index 59b14c42ffc5..d67c4b30b3cf 100644 --- a/cio/io_windows.go +++ b/cio/io_windows.go @@ -20,6 +20,7 @@ import ( "context" "fmt" "io" + "net/url" winio "github.com/Microsoft/go-winio" "github.com/containerd/log" @@ -155,3 +156,42 @@ func NewDirectIOFromFIFOSet(ctx context.Context, stdin io.WriteCloser, stdout, s }, } } + +// TerminalLogURI provides the raw logging URI +// as well as sets the terminal option to true. +func TerminalLogURI(uri *url.URL) Creator { + return func(_ string) (IO, error) { + return &logURI{ + config: Config{ + Terminal: true, + Stdout: uri.String(), + + // Windows HCSShim requires that stderr is an empty string when using terminal. + // https://github.com/microsoft/hcsshim/blob/200feabd854da69f615a598ed6a1263ce9531676/cmd/containerd-shim-runhcs-v1/service_internal.go#L127 + Stderr: "", + }, + }, nil + } +} + +// TerminalBinaryIO forwards container STDOUT|STDERR directly to a logging binary +// It also sets the terminal option to true +func TerminalBinaryIO(binary string, args map[string]string) Creator { + return func(_ string) (IO, error) { + uri, err := LogURIGenerator("binary", binary, args) + if err != nil { + return nil, err + } + + return &logURI{ + config: Config{ + Terminal: true, + Stdout: uri.String(), + + // Windows HCSShim requires that stderr is an empty string when using terminal. + // https://github.com/microsoft/hcsshim/blob/200feabd854da69f615a598ed6a1263ce9531676/cmd/containerd-shim-runhcs-v1/service_internal.go#L127 + Stderr: "", + }, + }, nil + } +}