MCPcopy Create free account
hub / github.com/docker/docker-agent / EnsureCommand

Function EnsureCommand

pkg/toolinstall/resolver.go:26–42  ·  view source on GitHub ↗

EnsureCommand makes sure a command binary is available. It checks PATH first, then the docker agent tools directory, then attempts to install from the aqua registry if auto-install is enabled. Returns the resolved command (may be the same string if found in PATH, or a full path to the installed bin

(ctx context.Context, command, version string)

Source from the content-addressed store, hash-verified

24// When auto-install is disabled (globally or per-toolset), the original
25// command is returned with no error.
26func EnsureCommand(ctx context.Context, command, version string) (string, error) {
27 if strings.EqualFold(os.Getenv("DOCKER_AGENT_AUTO_INSTALL"), "false") {
28 return command, nil
29 }
30
31 lower := strings.ToLower(strings.TrimSpace(version))
32 if lower == "false" || lower == "off" {
33 return command, nil
34 }
35
36 resolvedPath, err := resolve(ctx, command, version, doInstall)
37 if err != nil {
38 return "", fmt.Errorf("auto-installing command %q: %w", command, err)
39 }
40
41 return resolvedPath, nil
42}
43
44// installGroup deduplicates concurrent installations of the same command.
45// If two goroutines call resolve("fzf") simultaneously, only one performs

Calls 1

resolveFunction · 0.70