Skip to content

Commit

Permalink
Propagate Docker container exit code (#613)
Browse files Browse the repository at this point in the history
* Propagate Docker container exit code

* Defer container removal
  • Loading branch information
x4204 authored Jul 14, 2024
1 parent 61e8cfb commit cd2697f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions internal/dag/executor/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ func (e *docker) Run() error {
return err
}

defer func() {
if e.autoRemove {
err := cli.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{})
util.LogErr("docker executor: remove container", err)
}
}()

statusCh, errCh := cli.ContainerWait(
ctx, resp.ID, container.WaitConditionNotRunning,
)
Expand All @@ -96,7 +103,10 @@ func (e *docker) Run() error {
if err != nil {
return err
}
case <-statusCh:
case status := <-statusCh:
if status.StatusCode != 0 {
return fmt.Errorf("exit status %v", status.StatusCode)
}
}

out, err := cli.ContainerLogs(
Expand All @@ -109,11 +119,6 @@ func (e *docker) Run() error {
_, err = stdcopy.StdCopy(e.stdout, e.stdout, out)
util.LogErr("docker executor: stdcopy", err)

if e.autoRemove {
err := cli.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{})
util.LogErr("docker executor: remove container", err)
}

return nil
}

Expand Down

0 comments on commit cd2697f

Please sign in to comment.