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:
Tim Gross
2024-10-01 16:41:38 -04:00
committed by GitHub
parent 4a74fda8ce
commit e9ba630639
2 changed files with 3 additions and 11 deletions

View File

@@ -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

View File

@@ -48,7 +48,6 @@ job "test" {
on_update = "ignore_warnings"
args = [
"-c",
"/local/ready.sh"
]
@@ -95,4 +94,3 @@ EOT
}
}
}