MCPcopy
hub / github.com/docker/docker-agent / runDockerAgentInContainer

Method runDockerAgentInContainer

pkg/evaluation/eval.go:390–527  ·  view source on GitHub ↗
(ctx context.Context, imageID string, questions []string, setup string)

Source from the content-addressed store, hash-verified

388}
389
390func (r *Runner) runDockerAgentInContainer(ctx context.Context, imageID string, questions []string, setup string) ([]map[string]any, error) {
391 agentDir := r.agentSource.ParentDir()
392 agentFile := filepath.Base(r.agentSource.Name())
393 containerName := fmt.Sprintf("docker-agent-eval-%d", uuid.New().ID())
394
395 args := []string{
396 "run",
397 "--name", containerName,
398 "--privileged",
399 "--init",
400 }
401 if !r.KeepContainers {
402 args = append(args, "--rm")
403 }
404 args = append(args,
405 "-i",
406 "-v", agentDir+":/configs:ro",
407 )
408
409 var env []string
410 // addEnv forwards a variable to the container: "-e NAME" tells docker to
411 // pass it through, and NAME=VALUE sets it on the docker process.
412 addEnv := func(name, value string) {
413 args = append(args, "-e", name)
414 env = append(env, name+"="+value)
415 }
416
417 if r.runConfig.ModelsGateway != "" {
418 addEnv("DOCKER_AGENT_MODELS_GATEWAY", r.runConfig.ModelsGateway)
419
420 if token, ok := r.runConfig.EnvProvider().Get(ctx, environment.DockerDesktopTokenEnv); ok && token != "" {
421 addEnv(environment.DockerDesktopTokenEnv, token)
422 }
423 } else {
424 for _, name := range config.ProviderAPIKeyEnvVars() {
425 if val, ok := r.runConfig.EnvProvider().Get(ctx, name); ok && val != "" {
426 addEnv(name, val)
427 }
428 }
429 }
430
431 // Pass additional environment variables specified via -e flag
432 // Format: KEY or KEY=VALUE
433 for _, entry := range r.EnvVars {
434 if key, val, hasValue := strings.Cut(entry, "="); hasValue && key != "" {
435 addEnv(key, val)
436 } else if val, ok := r.runConfig.EnvProvider().Get(ctx, entry); ok && entry != "" {
437 addEnv(entry, val)
438 }
439 }
440
441 // When a setup script is provided, mount it into the container and
442 // override the entrypoint to run it before docker agent run --exec.
443 // The default entrypoint is: /run.sh /docker-agent run --exec --yolo --json
444 // /run.sh starts dockerd then exec's "$@".
445 if setup != "" {
446 setupFile := filepath.Join(os.TempDir(), fmt.Sprintf("docker-agent-eval-setup-%d.sh", uuid.New().ID()))
447 if err := os.WriteFile(setupFile, []byte(setup), 0o600); err != nil {

Callers 1

runSingleEvalMethod · 0.95

Implementers 2

mockRunnerpkg/tools/builtin/agent/agent_test.go
LocalRuntimepkg/runtime/runtime.go

Calls 11

ProviderAPIKeyEnvVarsFunction · 0.92
EnvProviderMethod · 0.80
ParentDirMethod · 0.65
NameMethod · 0.65
IDMethod · 0.65
GetMethod · 0.65
StartMethod · 0.65
ErrMethod · 0.65
WaitMethod · 0.65
NewMethod · 0.45
RemoveMethod · 0.45

Tested by

no test coverage detected