batches: improve handling of non-root steps by LawnGnome · Pull Request #886 · sourcegraph/src-cli · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
7 changes: 7 additions & 0 deletions cmd/src/batch_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type batchExecuteFlags struct {
workspace string
cleanArchives bool
skipErrors bool
runAsRoot bool

// EXPERIMENTAL
textOnly bool
Expand Down Expand Up @@ -152,6 +153,11 @@ func newBatchExecuteFlags(flagSet *flag.FlagSet, cacheDir, tempDir string) *batc

flagSet.BoolVar(verbose, "v", false, "print verbose output")

flagSet.BoolVar(
&caf.runAsRoot, "run-as-root", false,
"If true, forces all step containers to run as root.",
)

return caf
}

Expand Down Expand Up @@ -382,6 +388,7 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp
Timeout: opts.flags.timeout,
TempDir: opts.flags.tempDir,
GlobalEnv: os.Environ(),
ForceRoot: opts.flags.runAsRoot,
},
Logger: logManager,
Cache: executor.NewDiskCache(opts.flags.cacheDir),
Expand Down
3 changes: 3 additions & 0 deletions cmd/src/batch_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
type executorModeFlags struct {
timeout time.Duration
file string
runAsImageUser bool
tempDir string
repoDir string
workspaceFilesDir string
Expand All @@ -42,6 +43,7 @@ func newExecutorModeFlags(flagSet *flag.FlagSet) (f *executorModeFlags) {
f = &executorModeFlags{}
flagSet.DurationVar(&f.timeout, "timeout", 60*time.Minute, "The maximum duration a single batch spec step can take.")
flagSet.StringVar(&f.file, "f", "", "The workspace execution input file to read.")
flagSet.BoolVar(&f.runAsImageUser, "run-as-image-user", false, "True to run step containers as the default image user; if false or omitted, containers are always run as root.")
flagSet.StringVar(&f.tempDir, "tmp", "", "Directory for storing temporary data.")
flagSet.StringVar(&f.repoDir, "repo", "", "Path of the checked out repo on disk.")
flagSet.StringVar(&f.workspaceFilesDir, "workspaceFiles", "", "Path of workspace files on disk.")
Expand Down Expand Up @@ -208,6 +210,7 @@ func executeBatchSpecInWorkspaces(ctx context.Context, flags *executorModeFlags)
GlobalEnv: globalEnv,
RepoArchive: &repozip.NoopArchive{},
UI: taskExecUI.StepsExecutionUI(task),
ForceRoot: !flags.runAsImageUser,
}
results, err := executor.RunSteps(ctx, opts)

Expand Down
2 changes: 2 additions & 0 deletions internal/batches/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type NewExecutorOpts struct {
TempDir string
IsRemote bool
GlobalEnv []string
ForceRoot bool
}

type executor struct {
Expand Down Expand Up @@ -178,6 +179,7 @@ func (x *executor) do(ctx context.Context, task *Task, ui TaskExecutionUI) (err
Timeout: x.opts.Timeout,
RepoArchive: repoArchive,
WorkingDirectory: x.opts.WorkingDirectory,
ForceRoot: x.opts.ForceRoot,

UI: ui.StepsExecutionUI(task),
}
Expand Down
7 changes: 7 additions & 0 deletions internal/batches/executor/run_steps.go