mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
Added a jobspec directive to specify envvars. Updated Docker driver to use them accordingly.
This commit is contained in:
committed by
Alex Dadgar
parent
ccb36b3647
commit
9c17c0a1d8
@@ -44,6 +44,7 @@ type Task struct {
|
||||
Driver string
|
||||
Config map[string]string
|
||||
Constraints []*Constraint
|
||||
Env map[string]string
|
||||
Resources *Resources
|
||||
Meta map[string]string
|
||||
}
|
||||
|
||||
@@ -170,8 +170,14 @@ func createContainer(ctx *ExecContext, task *structs.Task, logger *log.Logger) d
|
||||
hostConfig.PortBindings = dockerPorts
|
||||
}
|
||||
|
||||
// Merge Nomad-native with user-specified envvars
|
||||
env := TaskEnvironmentVariables(ctx, task).List()
|
||||
for k, v := range task.Env {
|
||||
env = append(env, fmt.Sprintf("%s=%s", k, v))
|
||||
}
|
||||
|
||||
config := &docker.Config{
|
||||
Env: TaskEnvironmentVariables(ctx, task).List(),
|
||||
Env: env,
|
||||
Image: task.Config["image"],
|
||||
}
|
||||
|
||||
|
||||
@@ -284,6 +284,7 @@ func parseTasks(result *[]*structs.Task, obj *hclobj.Object) error {
|
||||
return err
|
||||
}
|
||||
delete(m, "config")
|
||||
delete(m, "env")
|
||||
delete(m, "constraint")
|
||||
delete(m, "meta")
|
||||
delete(m, "resources")
|
||||
@@ -295,6 +296,19 @@ func parseTasks(result *[]*structs.Task, obj *hclobj.Object) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// If we have env, then parse them
|
||||
if o := o.Get("env", false); o != nil {
|
||||
for _, o := range o.Elem(false) {
|
||||
var m map[string]interface{}
|
||||
if err := hcl.DecodeObject(&m, o); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := mapstructure.WeakDecode(m, &t.Env); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we have config, then parse that
|
||||
if o := o.Get("config", false); o != nil {
|
||||
for _, o := range o.Elem(false) {
|
||||
|
||||
@@ -86,6 +86,10 @@ func TestParse(t *testing.T) {
|
||||
Config: map[string]string{
|
||||
"image": "hashicorp/binstore",
|
||||
},
|
||||
Env: map[string]string{
|
||||
"HELLO": "world",
|
||||
"LOREM": "ipsum",
|
||||
},
|
||||
Resources: &structs.Resources{
|
||||
CPU: 500,
|
||||
MemoryMB: 128,
|
||||
|
||||
@@ -36,6 +36,10 @@ job "binstore-storagelocker" {
|
||||
config {
|
||||
image = "hashicorp/binstore"
|
||||
}
|
||||
env {
|
||||
HELLO = "world"
|
||||
PLOP = "coucou"
|
||||
}
|
||||
resources {
|
||||
cpu = 500
|
||||
memory = 128
|
||||
|
||||
@@ -966,6 +966,9 @@ type Task struct {
|
||||
// Config is provided to the driver to initialize
|
||||
Config map[string]string
|
||||
|
||||
// Map of environment variables to be used by the driver
|
||||
Env map[string]string
|
||||
|
||||
// Constraints can be specified at a task level and apply only to
|
||||
// the particular task.
|
||||
Constraints []*Constraint
|
||||
|
||||
Reference in New Issue
Block a user