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 {