engine: resources: Fix backwards docker ports
This wasn't setup properly, now it's fixed. Woops.
This commit is contained in:
@@ -56,7 +56,7 @@ It has the following properties:
|
|||||||
* `image`: docker `image` or `image:tag`
|
* `image`: docker `image` or `image:tag`
|
||||||
* `cmd`: a command or list of commands to run on the container
|
* `cmd`: a command or list of commands to run on the container
|
||||||
* `env`: a list of environment variables, e.g. `["VAR=val",],`
|
* `env`: a list of environment variables, e.g. `["VAR=val",],`
|
||||||
* `ports`: a map of portmappings, e.g. `{"tcp" => {80 => 8080, 443 => 8443,},},`
|
* `ports`: a map of portmappings, e.g. `{"tcp" => {8080 => 80, 8443 => 443,},},`
|
||||||
* `apiversion:` override the host's default docker version, e.g. `"v1.35"`
|
* `apiversion:` override the host's default docker version, e.g. `"v1.35"`
|
||||||
* `force`: destroy and rebuild the container instead of erroring on wrong image
|
* `force`: destroy and rebuild the container instead of erroring on wrong image
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,9 @@ type DockerContainerRes struct {
|
|||||||
// Env is a list of environment variables. E.g. ["VAR=val",].
|
// Env is a list of environment variables. E.g. ["VAR=val",].
|
||||||
Env []string `lang:"env" yaml:"env"`
|
Env []string `lang:"env" yaml:"env"`
|
||||||
|
|
||||||
// Ports is a map of port bindings. E.g. {"tcp" => {80 => 8080},}.
|
// Ports is a map of port bindings. E.g. {"tcp" => {8080 => 80},}. The
|
||||||
|
// key is the host port, and the val is the inner service port to
|
||||||
|
// forward to.
|
||||||
Ports map[string]map[int64]int64 `lang:"ports" yaml:"ports"`
|
Ports map[string]map[int64]int64 `lang:"ports" yaml:"ports"`
|
||||||
|
|
||||||
// APIVersion allows you to override the host's default client API
|
// APIVersion allows you to override the host's default client API
|
||||||
@@ -261,6 +263,8 @@ func (obj *DockerContainerRes) CheckApply(ctx context.Context, apply bool) (bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX: Check if defined ports matches what we expect.
|
||||||
|
|
||||||
if !apply {
|
if !apply {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
@@ -309,15 +313,25 @@ func (obj *DockerContainerRes) CheckApply(ctx context.Context, apply bool) (bool
|
|||||||
PortBindings: make(map[nat.Port][]nat.PortBinding),
|
PortBindings: make(map[nat.Port][]nat.PortBinding),
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range obj.Ports {
|
for proto, v := range obj.Ports {
|
||||||
|
// On the outside, on the host, we'd see 8080 which is p
|
||||||
|
// and on the inside, the container would have something
|
||||||
|
// running on 80, which is q.
|
||||||
for p, q := range v {
|
for p, q := range v {
|
||||||
containerConfig.ExposedPorts[nat.Port(k)] = struct{}{}
|
// Port is a string containing port number and
|
||||||
hostConfig.PortBindings[nat.Port(fmt.Sprintf("%d/%s", p, k))] = []nat.PortBinding{
|
// protocol in the format "80/tcp".
|
||||||
{
|
port := fmt.Sprintf("%d/%s", q, proto)
|
||||||
HostIP: "0.0.0.0",
|
n := nat.Port(port)
|
||||||
HostPort: fmt.Sprintf("%d", q),
|
containerConfig.ExposedPorts[n] = struct{}{} // PortSet
|
||||||
},
|
|
||||||
|
pb := nat.PortBinding{
|
||||||
|
HostIP: "0.0.0.0",
|
||||||
|
HostPort: fmt.Sprintf("%d", p), // eg: 8080
|
||||||
}
|
}
|
||||||
|
if _, exists := hostConfig.PortBindings[n]; !exists {
|
||||||
|
hostConfig.PortBindings[n] = []nat.PortBinding{}
|
||||||
|
}
|
||||||
|
hostConfig.PortBindings[n] = append(hostConfig.PortBindings[n], pb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ docker:container "mgmt-nginx" {
|
|||||||
state => "running",
|
state => "running",
|
||||||
image => "nginx",
|
image => "nginx",
|
||||||
cmd => ["nginx", "-g", "daemon off;",],
|
cmd => ["nginx", "-g", "daemon off;",],
|
||||||
ports => {"tcp" => {80 => 8080,},},
|
ports => {"tcp" => {8080 => 80,},},
|
||||||
}
|
}
|
||||||
|
|
||||||
docker:image "nginx" {
|
docker:image "nginx" {
|
||||||
|
|||||||
@@ -2,5 +2,5 @@ docker:container "mgmt-nginx" {
|
|||||||
state => "running",
|
state => "running",
|
||||||
image => "nginx",
|
image => "nginx",
|
||||||
cmd => ["nginx", "-g", "daemon off;",],
|
cmd => ["nginx", "-g", "daemon off;",],
|
||||||
ports => {"tcp" => {80 => 8080,},},
|
ports => {"tcp" => {8080 => 80,},},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user