Skip to content

Commit 47970e3

Browse files
committed
Allow passing more env to docker run when running evals
Signed-off-by: David Gageot <david.gageot@docker.com>
1 parent 0001516 commit 47970e3

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

cmd/root/eval.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func newEvalCmd() *cobra.Command {
4343
cmd.Flags().StringSliceVar(&flags.Only, "only", nil, "Only run evaluations with file names matching these patterns (can be specified multiple times)")
4444
cmd.Flags().StringVar(&flags.BaseImage, "base-image", "", "Custom base Docker image for running evaluations")
4545
cmd.Flags().BoolVar(&flags.KeepContainers, "keep-containers", false, "Keep containers after evaluation (don't use --rm)")
46+
cmd.Flags().StringSliceVarP(&flags.EnvVars, "env", "e", nil, "Environment variables to pass to container (KEY or KEY=VALUE)")
4647

4748
return cmd
4849
}

pkg/evaluation/eval.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,18 @@ func (r *Runner) runCagentInContainer(ctx context.Context, imageID, question str
372372
}
373373
}
374374

375+
// Pass additional environment variables specified via -e flag
376+
// Format: KEY or KEY=VALUE
377+
for _, entry := range r.EnvVars {
378+
if key, val, hasValue := strings.Cut(entry, "="); hasValue {
379+
args = append(args, "-e", key)
380+
env = append(env, key+"="+val)
381+
} else if val, ok := r.runConfig.EnvProvider().Get(ctx, entry); ok {
382+
args = append(args, "-e", entry)
383+
env = append(env, entry+"="+val)
384+
}
385+
}
386+
375387
args = append(args, imageID, "/configs/"+agentFile, question)
376388

377389
cmd := exec.CommandContext(ctx, "docker", args...)

pkg/evaluation/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ type Config struct {
120120
Only []string // Only run evaluations matching these patterns
121121
BaseImage string // Custom base Docker image for running evaluations
122122
KeepContainers bool // If true, don't remove containers after evaluation (skip --rm)
123+
EnvVars []string // Environment variables to pass: KEY (value from env) or KEY=VALUE (explicit)
123124
}
124125

125126
// Session helper functions

0 commit comments

Comments
 (0)