// TaskEnvironmentVariables converts exec context and task configuration into a // TaskEnvironment. func TaskEnvironmentVariables(ctx *ExecContext, task *structs.Task) environment.TaskEnvironment { env := environment.NewTaskEnivornment() env.SetMeta(task.Meta) if ctx.AllocDir != nil { env.SetAllocDir(ctx.AllocDir.SharedDir) } if task.Resources != nil { env.SetMemLimit(task.Resources.MemoryMB) env.SetCpuLimit(task.Resources.CPU) if len(task.Resources.Networks) > 0 { network := task.Resources.Networks[0] env.SetTaskIp(network.IP) env.SetPorts(network.MapDynamicPorts()) } } if task.Env != nil { env.SetEnvvars(task.Env) } return env }
// TaskEnvironmentVariables converts exec context and task configuration into a // TaskEnvironment. func TaskEnvironmentVariables(ctx *ExecContext, task *structs.Task) environment.TaskEnvironment { env := environment.NewTaskEnivornment() env.SetMeta(task.Meta) if ctx.AllocDir != nil { env.SetAllocDir(ctx.AllocDir.SharedDir) taskdir, ok := ctx.AllocDir.TaskDirs[task.Name] if !ok { // TODO: Update this to return an error } env.SetTaskLocalDir(filepath.Join(taskdir, allocdir.TaskLocal)) } if task.Resources != nil { env.SetMemLimit(task.Resources.MemoryMB) env.SetCpuLimit(task.Resources.CPU) if len(task.Resources.Networks) > 0 { network := task.Resources.Networks[0] env.SetTaskIp(network.IP) env.SetPorts(network.MapDynamicPorts()) } } if task.Env != nil { env.SetEnvvars(task.Env) } return env }