Skip to content

Commit

Permalink
fix portmap envvars in docker driver
Browse files Browse the repository at this point in the history
  • Loading branch information
jazzyfresh committed Sep 3, 2019
1 parent d29fa2b commit 43a177c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions client/taskenv/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,14 @@ func buildPortEnv(envMap map[string]string, p structs.Port, ip string, driverNet
}
}

func WithPortMapEnvs(envs map[string]string, ports map[string]int) map[string]string {
for portLabel, port := range ports {
portEnv := PortPrefix + portLabel
envs[portEnv] = strconv.Itoa(port)
}
return envs
}

// SetHostEnvvars adds the host environment variables to the tasks. The filter
// parameter can be use to filter host environment from entering the tasks.
func (b *Builder) SetHostEnvvars(filter []string) *Builder {
Expand Down
1 change: 1 addition & 0 deletions drivers/docker/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T
logger.Debug("applied labels on the container", "labels", config.Labels)
}

task.Env = taskenv.WithPortMapEnvs(task.Env, driverConfig.PortMap)
config.Env = task.EnvList()

containerName := fmt.Sprintf("%s-%s", strings.Replace(task.Name, "/", "_", -1), task.AllocID)
Expand Down

0 comments on commit 43a177c

Please sign in to comment.