Skip to content

Commit

Permalink
docker: fix script check execution
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tgross committed Oct 1, 2024
1 parent 5e1ad14 commit 8e05c82
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
12 changes: 3 additions & 9 deletions drivers/docker/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions e2e/consul/input/on_update_check_restart.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ job "test" {
on_update = "ignore_warnings"

args = [
"-c",
"/local/ready.sh"
]

Expand Down Expand Up @@ -95,4 +94,3 @@ EOT
}
}
}

0 comments on commit 8e05c82

Please sign in to comment.