Drivers: add work_dir config to exec/raw_exec/java drivers (#24249)

---------

Co-authored-by: wurosh <uros.m.perisic@gmail.com>
Co-authored-by: Michael Schurter <mschurter@hashicorp.com>
Co-authored-by: Tim Gross <tgross@hashicorp.com>
This commit is contained in:
Michael Smithhisler
2024-11-01 11:04:40 -04:00
committed by GitHub
parent 58ea294f0b
commit 658c429d75
21 changed files with 408 additions and 125 deletions

View File

@@ -98,6 +98,7 @@ var (
"ipc_mode": hclspec.NewAttr("ipc_mode", "string", false),
"cap_add": hclspec.NewAttr("cap_add", "list(string)", false),
"cap_drop": hclspec.NewAttr("cap_drop", "list(string)", false),
"work_dir": hclspec.NewAttr("work_dir", "string", false),
})
// driverCapabilities is returned by the Capabilities RPC and indicates what
@@ -189,6 +190,9 @@ type TaskConfig struct {
// CapDrop is a set of linux capabilities to disable.
CapDrop []string `codec:"cap_drop"`
// WorkDir is the working directory for the task
WorkDir string `coded:"work_dir"`
}
func (tc *TaskConfig) validate() error {
@@ -215,6 +219,9 @@ func (tc *TaskConfig) validate() error {
return fmt.Errorf("cap_drop configured with capabilities not supported by system: %s", badDrops)
}
if tc.WorkDir != "" && !filepath.IsAbs(tc.WorkDir) {
return fmt.Errorf("work_dir must be an absolute path: %s", tc.WorkDir)
}
return nil
}
@@ -496,6 +503,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
ResourceLimits: true,
Resources: cfg.Resources,
TaskDir: cfg.TaskDir().Dir,
WorkDir: driverConfig.WorkDir,
StdoutPath: cfg.StdoutPath,
StderrPath: cfg.StderrPath,
Mounts: cfg.Mounts,