Skip to content

Commit

Permalink
docker: remove NopCloser from the executor. (#2345)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan Colgate-McFarlane authored and alexec committed Mar 4, 2020
1 parent 5d3bdd5 commit 793c072
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions workflow/executor/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"time"
Expand Down Expand Up @@ -70,21 +69,46 @@ func (d *DockerExecutor) CopyFile(containerID string, sourcePath string, destPat
return nil
}

type multiReadCloser struct {
io.Reader
closers map[string]io.Closer
}

func (mc *multiReadCloser) Close() error {
var lastErr error
for name, c := range mc.closers {
err := c.Close()
if err != nil {
log.Errorf("error closing docker logs %s pipe , %v", name, err)
lastErr = err
}
}
return lastErr
}

func (d *DockerExecutor) GetOutputStream(containerID string, combinedOutput bool) (io.ReadCloser, error) {
cmd := exec.Command("docker", "logs", containerID)
log.Info(cmd.Args)

reader, err := cmd.StdoutPipe()
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, errors.InternalWrapError(err)
}

reader := stdout

if combinedOutput {
stderr, err := cmd.StderrPipe()
if err != nil {
return nil, errors.InternalWrapError(err)
}
reader = ioutil.NopCloser(io.MultiReader(reader, stderr))
reader = &multiReadCloser{
Reader: io.MultiReader(stdout, stderr),
closers: map[string]io.Closer{
"stdout": stdout,
"stderr": stderr,
},
}
}

err = cmd.Start()
Expand Down

0 comments on commit 793c072

Please sign in to comment.