Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Configure container streams (#674)
Browse files Browse the repository at this point in the history
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 <silvin.lubecki@docker.com>
  • Loading branch information
silvin-lubecki authored and radu-matei committed Mar 26, 2019
1 parent f2bec71 commit 6b123e9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 23 additions & 1 deletion pkg/driver/docker_driver.go
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driver/driver.go
Expand Up @@ -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 {
Expand Down

0 comments on commit 6b123e9

Please sign in to comment.