2014-02-11 23:04:39 -05:00
|
|
|
package runconfig
|
|
|
|
|
|
|
|
// Compare two Config struct. Do not compare the "Image" nor "Hostname" fields
|
|
|
|
// If OpenStdin is set, then it differs
|
|
|
|
func Compare(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.OpenStdin != b.OpenStdin ||
|
2014-04-08 05:26:09 -04:00
|
|
|
a.Tty != b.Tty {
|
2014-02-11 23:04:39 -05:00
|
|
|
return false
|
|
|
|
}
|
2015-04-10 20:05:21 -04:00
|
|
|
|
|
|
|
if a.Cmd.Len() != b.Cmd.Len() ||
|
2014-02-11 23:04:39 -05:00
|
|
|
len(a.Env) != len(b.Env) ||
|
2015-03-20 08:14:31 -04:00
|
|
|
len(a.Labels) != len(b.Labels) ||
|
2014-02-11 23:04:39 -05:00
|
|
|
len(a.PortSpecs) != len(b.PortSpecs) ||
|
|
|
|
len(a.ExposedPorts) != len(b.ExposedPorts) ||
|
2015-04-10 20:05:21 -04:00
|
|
|
a.Entrypoint.Len() != b.Entrypoint.Len() ||
|
2014-02-11 23:04:39 -05:00
|
|
|
len(a.Volumes) != len(b.Volumes) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2015-04-10 20:05:21 -04:00
|
|
|
aCmd := a.Cmd.Slice()
|
|
|
|
bCmd := b.Cmd.Slice()
|
|
|
|
for i := 0; i < len(aCmd); i++ {
|
|
|
|
if aCmd[i] != bCmd[i] {
|
2014-02-11 23:04:39 -05:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for i := 0; i < len(a.Env); i++ {
|
|
|
|
if a.Env[i] != b.Env[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
2015-03-20 08:14:31 -04:00
|
|
|
for k, v := range a.Labels {
|
|
|
|
if v != b.Labels[k] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
2014-02-11 23:04:39 -05:00
|
|
|
for i := 0; i < len(a.PortSpecs); i++ {
|
|
|
|
if a.PortSpecs[i] != b.PortSpecs[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for k := range a.ExposedPorts {
|
|
|
|
if _, exists := b.ExposedPorts[k]; !exists {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
2015-04-10 20:05:21 -04:00
|
|
|
|
|
|
|
aEntrypoint := a.Entrypoint.Slice()
|
|
|
|
bEntrypoint := b.Entrypoint.Slice()
|
|
|
|
for i := 0; i < len(aEntrypoint); i++ {
|
|
|
|
if aEntrypoint[i] != bEntrypoint[i] {
|
2014-02-11 23:04:39 -05:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for key := range a.Volumes {
|
|
|
|
if _, exists := b.Volumes[key]; !exists {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|