|
@@ -1,5 +1,9 @@
|
|
package docker
|
|
package docker
|
|
|
|
|
|
|
|
+import (
|
|
|
|
+ "strings"
|
|
|
|
+)
|
|
|
|
+
|
|
// Compare two Config struct. Do not compare the "Image" nor "Hostname" fields
|
|
// Compare two Config struct. Do not compare the "Image" nor "Hostname" fields
|
|
// If OpenStdin is set, then it differs
|
|
// If OpenStdin is set, then it differs
|
|
func CompareConfig(a, b *Config) bool {
|
|
func CompareConfig(a, b *Config) bool {
|
|
@@ -68,6 +72,20 @@ func MergeConfig(userConf, imageConf *Config) {
|
|
}
|
|
}
|
|
if userConf.PortSpecs == nil || len(userConf.PortSpecs) == 0 {
|
|
if userConf.PortSpecs == nil || len(userConf.PortSpecs) == 0 {
|
|
userConf.PortSpecs = imageConf.PortSpecs
|
|
userConf.PortSpecs = imageConf.PortSpecs
|
|
|
|
+ } else {
|
|
|
|
+ for _, imagePortSpec := range imageConf.PortSpecs {
|
|
|
|
+ found := false
|
|
|
|
+ imageNat, _ := parseNat(imagePortSpec)
|
|
|
|
+ for _, userPortSpec := range userConf.PortSpecs {
|
|
|
|
+ userNat, _ := parseNat(userPortSpec)
|
|
|
|
+ if imageNat.Proto == userNat.Proto && imageNat.Frontend == userNat.Frontend {
|
|
|
|
+ found = true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if !found {
|
|
|
|
+ userConf.PortSpecs = append(userConf.PortSpecs, imagePortSpec)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
if !userConf.Tty {
|
|
if !userConf.Tty {
|
|
userConf.Tty = imageConf.Tty
|
|
userConf.Tty = imageConf.Tty
|
|
@@ -80,17 +98,38 @@ func MergeConfig(userConf, imageConf *Config) {
|
|
}
|
|
}
|
|
if userConf.Env == nil || len(userConf.Env) == 0 {
|
|
if userConf.Env == nil || len(userConf.Env) == 0 {
|
|
userConf.Env = imageConf.Env
|
|
userConf.Env = imageConf.Env
|
|
|
|
+ } else {
|
|
|
|
+ for _, imageEnv := range imageConf.Env {
|
|
|
|
+ found := false
|
|
|
|
+ imageEnvKey := strings.Split(imageEnv, "=")[0]
|
|
|
|
+ for _, userEnv := range userConf.Env {
|
|
|
|
+ userEnvKey := strings.Split(userEnv, "=")[0]
|
|
|
|
+ if imageEnvKey == userEnvKey {
|
|
|
|
+ found = true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if !found {
|
|
|
|
+ userConf.Env = append(userConf.Env, imageEnv)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
if userConf.Cmd == nil || len(userConf.Cmd) == 0 {
|
|
if userConf.Cmd == nil || len(userConf.Cmd) == 0 {
|
|
userConf.Cmd = imageConf.Cmd
|
|
userConf.Cmd = imageConf.Cmd
|
|
}
|
|
}
|
|
if userConf.Dns == nil || len(userConf.Dns) == 0 {
|
|
if userConf.Dns == nil || len(userConf.Dns) == 0 {
|
|
userConf.Dns = imageConf.Dns
|
|
userConf.Dns = imageConf.Dns
|
|
|
|
+ } else {
|
|
|
|
+ //duplicates aren't an issue here
|
|
|
|
+ userConf.Dns = append(userConf.Dns, imageConf.Dns...)
|
|
}
|
|
}
|
|
if userConf.Entrypoint == nil || len(userConf.Entrypoint) == 0 {
|
|
if userConf.Entrypoint == nil || len(userConf.Entrypoint) == 0 {
|
|
userConf.Entrypoint = imageConf.Entrypoint
|
|
userConf.Entrypoint = imageConf.Entrypoint
|
|
}
|
|
}
|
|
if userConf.Volumes == nil || len(userConf.Volumes) == 0 {
|
|
if userConf.Volumes == nil || len(userConf.Volumes) == 0 {
|
|
userConf.Volumes = imageConf.Volumes
|
|
userConf.Volumes = imageConf.Volumes
|
|
|
|
+ } else {
|
|
|
|
+ for k, v := range imageConf.Volumes {
|
|
|
|
+ userConf.Volumes[k] = v
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|