mirror of
https://github.com/kemko/nomad.git
synced 2026-01-08 03:15:42 +03:00
environment variables
This commit is contained in:
@@ -14,11 +14,17 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
//Path inside container for mounted directory shared across tasks in a task group.
|
||||
// SharedAllocContainerPath is the path inside container for mounted
|
||||
// directory shared across tasks in a task group.
|
||||
SharedAllocContainerPath = filepath.Join("/", SharedAllocName)
|
||||
|
||||
//Path inside container for mounted directory for local storage.
|
||||
// TaskLocalContainer is the path inside a container for mounted directory
|
||||
// for local storage.
|
||||
TaskLocalContainerPath = filepath.Join("/", TaskLocal)
|
||||
|
||||
// TaskSecretsContainerPath is the path inside a container for mounted
|
||||
// secrets directory
|
||||
TaskSecretsContainerPath = filepath.Join("/", TaskSecrets)
|
||||
)
|
||||
|
||||
func (d *AllocDir) linkOrCopy(src, dst string, perm os.FileMode) error {
|
||||
|
||||
@@ -381,6 +381,7 @@ func (d *DockerDriver) createContainer(ctx *ExecContext, task *structs.Task,
|
||||
// Set environment variables.
|
||||
d.taskEnv.SetAllocDir(allocdir.SharedAllocContainerPath)
|
||||
d.taskEnv.SetTaskLocalDir(allocdir.TaskLocalContainerPath)
|
||||
d.taskEnv.SetTaskLocalDir(allocdir.TaskSecretsContainerPath)
|
||||
|
||||
config := &docker.Config{
|
||||
Image: driverConfig.ImageName,
|
||||
|
||||
@@ -156,6 +156,7 @@ func GetTaskEnv(allocDir *allocdir.AllocDir, node *structs.Node,
|
||||
}
|
||||
|
||||
env.SetTaskLocalDir(filepath.Join(taskdir, allocdir.TaskLocal))
|
||||
env.SetSecretDir(filepath.Join(taskdir, allocdir.TaskSecrets))
|
||||
}
|
||||
|
||||
if task.Resources != nil {
|
||||
|
||||
18
client/driver/env/env.go
vendored
18
client/driver/env/env.go
vendored
@@ -21,6 +21,10 @@ const (
|
||||
// removed.
|
||||
TaskLocalDir = "NOMAD_TASK_DIR"
|
||||
|
||||
// SecretDir is the environment variable with the path to the tasks secret
|
||||
// directory where it can store sensitive data.
|
||||
SecretDir = "NOMAD_SECRET_DIR"
|
||||
|
||||
// MemLimit is the environment variable with the tasks memory limit in MBs.
|
||||
MemLimit = "NOMAD_MEMORY_LIMIT"
|
||||
|
||||
@@ -79,6 +83,7 @@ type TaskEnvironment struct {
|
||||
JobMeta map[string]string
|
||||
AllocDir string
|
||||
TaskDir string
|
||||
SecretDir string
|
||||
CpuLimit int
|
||||
MemLimit int
|
||||
TaskName string
|
||||
@@ -153,6 +158,9 @@ func (t *TaskEnvironment) Build() *TaskEnvironment {
|
||||
if t.TaskDir != "" {
|
||||
t.TaskEnv[TaskLocalDir] = t.TaskDir
|
||||
}
|
||||
if t.SecretDir != "" {
|
||||
t.TaskEnv[SecretDir] = t.SecretDir
|
||||
}
|
||||
|
||||
// Build the resource limits
|
||||
if t.MemLimit != 0 {
|
||||
@@ -249,6 +257,16 @@ func (t *TaskEnvironment) ClearTaskLocalDir() *TaskEnvironment {
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *TaskEnvironment) SetSecretDir(dir string) *TaskEnvironment {
|
||||
t.SecretDir = dir
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *TaskEnvironment) ClearSecretDir() *TaskEnvironment {
|
||||
t.SecretDir = ""
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *TaskEnvironment) SetMemLimit(limit int) *TaskEnvironment {
|
||||
t.MemLimit = limit
|
||||
return t
|
||||
|
||||
@@ -240,6 +240,7 @@ func (e *UniversalExecutor) configureChroot() error {
|
||||
e.ctx.TaskEnv.
|
||||
SetAllocDir(filepath.Join("/", allocdir.SharedAllocName)).
|
||||
SetTaskLocalDir(filepath.Join("/", allocdir.TaskLocal)).
|
||||
SetSecretDir(filepath.Join("/", allocdir.TaskSecrets)).
|
||||
Build()
|
||||
|
||||
if e.cmd.SysProcAttr == nil {
|
||||
|
||||
Reference in New Issue
Block a user