Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture stderr from Docker container #615

Merged
merged 2 commits into from
Jul 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions internal/dag/executor/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ func (e *docker) Run() error {
}
}()

out, err := cli.ContainerLogs(
ctx, resp.ID, types.ContainerLogsOptions{
ShowStdout: true,
ShowStderr: true,
Follow: true,
},
)
if err != nil {
return err
}

go func() {
_, err = stdcopy.StdCopy(e.stdout, e.stdout, out)
util.LogErr("docker executor: stdcopy", err)
}()

statusCh, errCh := cli.ContainerWait(
ctx, resp.ID, container.WaitConditionNotRunning,
)
Expand All @@ -109,16 +125,6 @@ func (e *docker) Run() error {
}
}

out, err := cli.ContainerLogs(
ctx, resp.ID, types.ContainerLogsOptions{ShowStdout: true},
)
Comment on lines -112 to -114
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this above cli.ContainerWait so that log streaming starts immediately after container starts and not after the container exits

if err != nil {
return err
}

_, err = stdcopy.StdCopy(e.stdout, e.stdout, out)
util.LogErr("docker executor: stdcopy", err)

return nil
}

Expand Down
Loading