From 6b123e9e54a2b7131bf320270c8803a1fe97d3b5 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki <31478878+silvin-lubecki@users.noreply.github.com> Date: Tue, 26 Mar 2019 13:20:06 +0100 Subject: [PATCH] Configure container streams (#674) Add output and error container streams configuration on Docker Driver, different from the Operation.Out, which is there to configure the driver logs. Signed-off-by: Silvin Lubecki --- pkg/driver/docker_driver.go | 24 +++++++++++++++++++++++- pkg/driver/driver.go | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/pkg/driver/docker_driver.go b/pkg/driver/docker_driver.go index b3803e4f..720e5a63 100644 --- a/pkg/driver/docker_driver.go +++ b/pkg/driver/docker_driver.go @@ -28,6 +28,8 @@ type DockerDriver struct { Simulate bool dockerCli command.Cli dockerConfigurationOptions []DockerConfigurationOption + containerOut io.Writer + containerErr io.Writer } // Run executes the Docker driver @@ -64,6 +66,16 @@ func (d *DockerDriver) SetDockerCli(dockerCli command.Cli) { d.dockerCli = dockerCli } +// SetContainerOut sets the container output stream +func (d *DockerDriver) SetContainerOut(w io.Writer) { + d.containerOut = w +} + +// SetContainerErr sets the container error stream +func (d *DockerDriver) SetContainerErr(w io.Writer) { + d.containerErr = w +} + func pullImage(ctx context.Context, cli command.Cli, image string) error { ref, err := reference.ParseNormalizedNamed(image) if err != nil { @@ -185,10 +197,20 @@ func (d *DockerDriver) exec(op *Operation) error { if err != nil { return fmt.Errorf("unable to retrieve logs: %v", err) } + var ( + stdout io.Writer = os.Stdout + stderr io.Writer = os.Stderr + ) + if d.containerOut != nil { + stdout = d.containerOut + } + if d.containerErr != nil { + stderr = d.containerErr + } go func() { defer attach.Close() for { - _, err := stdcopy.StdCopy(os.Stdout, os.Stderr, attach.Reader) + _, err := stdcopy.StdCopy(stdout, stderr, attach.Reader) if err != nil { break } diff --git a/pkg/driver/driver.go b/pkg/driver/driver.go index be128ff6..7bd74be0 100644 --- a/pkg/driver/driver.go +++ b/pkg/driver/driver.go @@ -80,7 +80,7 @@ type DebugDriver struct { config map[string]string } -// Run executes the operation on the Debug driver +// Run executes the operation on the Debug driver func (d *DebugDriver) Run(op *Operation) error { data, err := json.MarshalIndent(op, "", " ") if err != nil {