mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
83bc5b7435
Fall back to image-specified hostname if user doesn't provide one, instead of only using image-specified hostname if the user *does* try to set one. (ditto for username) Closes #694.
88 lines
2 KiB
Go
88 lines
2 KiB
Go
package docker
|
|
|
|
// Compare two Config struct. Do not compare the "Image" nor "Hostname" fields
|
|
// If OpenStdin is set, then it differs
|
|
func CompareConfig(a, b *Config) bool {
|
|
if a == nil || b == nil ||
|
|
a.OpenStdin || b.OpenStdin {
|
|
return false
|
|
}
|
|
if a.AttachStdout != b.AttachStdout ||
|
|
a.AttachStderr != b.AttachStderr ||
|
|
a.User != b.User ||
|
|
a.Memory != b.Memory ||
|
|
a.MemorySwap != b.MemorySwap ||
|
|
a.CpuShares != b.CpuShares ||
|
|
a.OpenStdin != b.OpenStdin ||
|
|
a.Tty != b.Tty {
|
|
return false
|
|
}
|
|
if len(a.Cmd) != len(b.Cmd) ||
|
|
len(a.Dns) != len(b.Dns) ||
|
|
len(a.Env) != len(b.Env) ||
|
|
len(a.PortSpecs) != len(b.PortSpecs) {
|
|
return false
|
|
}
|
|
|
|
for i := 0; i < len(a.Cmd); i++ {
|
|
if a.Cmd[i] != b.Cmd[i] {
|
|
return false
|
|
}
|
|
}
|
|
for i := 0; i < len(a.Dns); i++ {
|
|
if a.Dns[i] != b.Dns[i] {
|
|
return false
|
|
}
|
|
}
|
|
for i := 0; i < len(a.Env); i++ {
|
|
if a.Env[i] != b.Env[i] {
|
|
return false
|
|
}
|
|
}
|
|
for i := 0; i < len(a.PortSpecs); i++ {
|
|
if a.PortSpecs[i] != b.PortSpecs[i] {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
func MergeConfig(userConf, imageConf *Config) {
|
|
if userConf.Hostname == "" {
|
|
userConf.Hostname = imageConf.Hostname
|
|
}
|
|
if userConf.User == "" {
|
|
userConf.User = imageConf.User
|
|
}
|
|
if userConf.Memory == 0 {
|
|
userConf.Memory = imageConf.Memory
|
|
}
|
|
if userConf.MemorySwap == 0 {
|
|
userConf.MemorySwap = imageConf.MemorySwap
|
|
}
|
|
if userConf.CpuShares == 0 {
|
|
userConf.CpuShares = imageConf.CpuShares
|
|
}
|
|
if userConf.PortSpecs == nil || len(userConf.PortSpecs) == 0 {
|
|
userConf.PortSpecs = imageConf.PortSpecs
|
|
}
|
|
if !userConf.Tty {
|
|
userConf.Tty = imageConf.Tty
|
|
}
|
|
if !userConf.OpenStdin {
|
|
userConf.OpenStdin = imageConf.OpenStdin
|
|
}
|
|
if !userConf.StdinOnce {
|
|
userConf.StdinOnce = imageConf.StdinOnce
|
|
}
|
|
if userConf.Env == nil || len(userConf.Env) == 0 {
|
|
userConf.Env = imageConf.Env
|
|
}
|
|
if userConf.Cmd == nil || len(userConf.Cmd) == 0 {
|
|
userConf.Cmd = imageConf.Cmd
|
|
}
|
|
if userConf.Dns == nil || len(userConf.Dns) == 0 {
|
|
userConf.Dns = imageConf.Dns
|
|
}
|
|
}
|