mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-22 05:40:50 +02:00
Refactor port mapping functions for build simplicity
This commit is contained in:
parent
e75236414e
commit
6a56597d45
3 changed files with 7 additions and 13 deletions
|
@ -136,7 +136,12 @@ func (c Container) runtimeConfig() *dockercontainer.Config {
|
||||||
|
|
||||||
config.Volumes = structMapSubtract(config.Volumes, imageConfig.Volumes)
|
config.Volumes = structMapSubtract(config.Volumes, imageConfig.Volumes)
|
||||||
|
|
||||||
config.ExposedPorts = structMapPortSubtract(config.ExposedPorts, imageConfig.ExposedPorts)
|
// subtract ports exposed in image from container
|
||||||
|
for k, _ := range config.ExposedPorts {
|
||||||
|
if _, ok := imageConfig.ExposedPorts[k]; ok {
|
||||||
|
delete(config.ExposedPorts, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
for p := range c.containerInfo.HostConfig.PortBindings {
|
for p := range c.containerInfo.HostConfig.PortBindings {
|
||||||
config.ExposedPorts[p] = struct{}{}
|
config.ExposedPorts[p] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/docker/go-connections/nat"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func sliceEqual(s1, s2 []string) bool {
|
func sliceEqual(s1, s2 []string) bool {
|
||||||
|
@ -67,14 +66,3 @@ func structMapSubtract(m1, m2 map[string]struct{}) map[string]struct{} {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func structMapPortSubtract(m1, m2 map[nat.Port]struct{}) map[nat.Port]struct{} {
|
|
||||||
m := map[nat.Port]struct{}{}
|
|
||||||
|
|
||||||
for k1, v1 := range m1 {
|
|
||||||
if _, ok := m2[k1]; !ok {
|
|
||||||
m[k1] = v1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
|
|
|
@ -63,3 +63,4 @@ func TestStructMapSubtract(t *testing.T) {
|
||||||
assert.Equal(t, map[string]struct{}{"a": x, "b": x, "c": x}, m1)
|
assert.Equal(t, map[string]struct{}{"a": x, "b": x, "c": x}, m1)
|
||||||
assert.Equal(t, map[string]struct{}{"a": x, "c": x}, m2)
|
assert.Equal(t, map[string]struct{}{"a": x, "c": x}, m2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue