-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed some issues with expose, port mapping, and environment variables #476
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f75404e
Fixed some issues with expose, port mapping, and environment variables
cbednarski 63439ee
Squash []map[string]type for port_map and labels into map[string]type
cbednarski e5d5d42
Added nil to network.MapLabelToValues call
cbednarski c298425
Added client checks back to the tests that can't use dockerSetup()
cbednarski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,8 +249,19 @@ func (d *DockerDriver) createContainer(ctx *ExecContext, task *structs.Task, dri | |
exposedPorts := map[docker.Port]struct{}{} | ||
|
||
for _, port := range network.ReservedPorts { | ||
// By default we will map the allocated port 1:1 to the container | ||
containerPortInt := port.Value | ||
|
||
// If the user has mapped a port using port_map we'll change it here | ||
if len(driverConfig.PortMap) == 1 { | ||
mapped, ok := driverConfig.PortMap[0][port.Label] | ||
if ok { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this up with the previous line? |
||
containerPortInt = mapped | ||
} | ||
} | ||
|
||
hostPortStr := strconv.Itoa(port.Value) | ||
containerPort := docker.Port(hostPortStr) | ||
containerPort := docker.Port(strconv.Itoa(containerPortInt)) | ||
|
||
publishedPorts[containerPort+"/tcp"] = []docker.PortBinding{docker.PortBinding{HostIP: network.IP, HostPort: hostPortStr}} | ||
publishedPorts[containerPort+"/udp"] = []docker.PortBinding{docker.PortBinding{HostIP: network.IP, HostPort: hostPortStr}} | ||
|
@@ -261,7 +272,6 @@ func (d *DockerDriver) createContainer(ctx *ExecContext, task *structs.Task, dri | |
d.logger.Printf("[DEBUG] driver.docker: exposed port %d", port.Value) | ||
} | ||
|
||
containerToHostPortMap := make(map[string]int) | ||
for _, port := range network.DynamicPorts { | ||
// By default we will map the allocated port 1:1 to the container | ||
containerPortInt := port.Value | ||
|
@@ -275,7 +285,6 @@ func (d *DockerDriver) createContainer(ctx *ExecContext, task *structs.Task, dri | |
} | ||
|
||
hostPortStr := strconv.Itoa(port.Value) | ||
// containerPort := docker.Port(hostPortStr) | ||
containerPort := docker.Port(strconv.Itoa(containerPortInt)) | ||
|
||
publishedPorts[containerPort+"/tcp"] = []docker.PortBinding{docker.PortBinding{HostIP: network.IP, HostPort: hostPortStr}} | ||
|
@@ -284,12 +293,18 @@ func (d *DockerDriver) createContainer(ctx *ExecContext, task *structs.Task, dri | |
|
||
exposedPorts[containerPort+"/tcp"] = struct{}{} | ||
exposedPorts[containerPort+"/udp"] = struct{}{} | ||
d.logger.Printf("[DEBUG] driver.docker: exposed port %s", hostPortStr) | ||
|
||
containerToHostPortMap[string(containerPort)] = port.Value | ||
d.logger.Printf("[DEBUG] driver.docker: exposed port %s", containerPort) | ||
} | ||
|
||
env.SetPorts(containerToHostPortMap) | ||
// This was set above in a call to TaskEnvironmentVariables but if we | ||
// have mapped any ports we will need to override them. | ||
// | ||
// TODO refactor the implementation in TaskEnvironmentVariables to match | ||
// the 0.2 ports world view. Docker seems to be the only place where | ||
// this is actually needed, but this is kinda hacky. | ||
if len(driverConfig.PortMap) == 1 { | ||
env.SetPorts(network.MapLabelToValues(driverConfig.PortMap[0])) | ||
} | ||
hostConfig.PortBindings = publishedPorts | ||
config.ExposedPorts = exposedPorts | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it makes sense to do > 0, and choose the first block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the first block is always 0. If we're worried about multiple port_map entries we should normalize this instead.