mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
docker: fix script check execution (#24098)
In #24095 we made a fix for non-streaming exec into Docker tasks for script checks and `change_mode = "script"`, but didn't complete E2E testing. We need to use `ContainerExecAttach` in the new API in order to get stdout/stderr from tasklets, but the previous `ContainerExecStart` call will prevent this from running successfully with an error that the exec has already run. * Ref: [NET-11202 (comment)](https://hashicorp.atlassian.net/browse/NET-11202?focusedCommentId=551618) * This has shipped in Nomad 1.9.0-beta.1 but not production yet. * This should fix the remaining issues in nightly E2E for Docker.
This commit is contained in:
@@ -105,17 +105,11 @@ func (h *taskHandle) Exec(ctx context.Context, cmd string, args []string) (*driv
|
||||
Detach: false,
|
||||
Tty: false,
|
||||
}
|
||||
if err := h.dockerClient.ContainerExecStart(ctx, exec.ID, startOpts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// hijack exec output streams
|
||||
hijacked, err := h.dockerClient.ContainerExecAttach(ctx, exec.ID, containerapi.ExecStartOptions{
|
||||
Detach: false,
|
||||
Tty: false,
|
||||
})
|
||||
hijacked, err := h.dockerClient.ContainerExecAttach(ctx, exec.ID, startOpts)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to attach to exec: %v", err)
|
||||
return nil, fmt.Errorf("failed to attach to exec object: %w", err)
|
||||
}
|
||||
|
||||
_, err = stdcopy.StdCopy(stdout, stderr, hijacked.Reader)
|
||||
@@ -128,7 +122,7 @@ func (h *taskHandle) Exec(ctx context.Context, cmd string, args []string) (*driv
|
||||
execResult.Stderr = stderr.Bytes()
|
||||
res, err := h.dockerClient.ContainerExecInspect(ctx, exec.ID)
|
||||
if err != nil {
|
||||
return execResult, err
|
||||
return execResult, fmt.Errorf("failed to inspect exit code of exec object: %w", err)
|
||||
}
|
||||
|
||||
execResult.ExitResult.ExitCode = res.ExitCode
|
||||
|
||||
@@ -48,7 +48,6 @@ job "test" {
|
||||
on_update = "ignore_warnings"
|
||||
|
||||
args = [
|
||||
"-c",
|
||||
"/local/ready.sh"
|
||||
]
|
||||
|
||||
@@ -95,4 +94,3 @@ EOT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user