Skip to content

Commit cd2697f

Browse files
authored
Propagate Docker container exit code (#613)
* Propagate Docker container exit code * Defer container removal
1 parent 61e8cfb commit cd2697f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

internal/dag/executor/docker.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ func (e *docker) Run() error {
8888
return err
8989
}
9090

91+
defer func() {
92+
if e.autoRemove {
93+
err := cli.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{})
94+
util.LogErr("docker executor: remove container", err)
95+
}
96+
}()
97+
9198
statusCh, errCh := cli.ContainerWait(
9299
ctx, resp.ID, container.WaitConditionNotRunning,
93100
)
@@ -96,7 +103,10 @@ func (e *docker) Run() error {
96103
if err != nil {
97104
return err
98105
}
99-
case <-statusCh:
106+
case status := <-statusCh:
107+
if status.StatusCode != 0 {
108+
return fmt.Errorf("exit status %v", status.StatusCode)
109+
}
100110
}
101111

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

112-
if e.autoRemove {
113-
err := cli.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{})
114-
util.LogErr("docker executor: remove container", err)
115-
}
116-
117122
return nil
118123
}
119124

0 commit comments

Comments
 (0)