github.com/csfrancis/docker@v1.8.0-rc2/runconfig/compare.go (about) 1 package runconfig 2 3 // Compare two Config struct. Do not compare the "Image" nor "Hostname" fields 4 // If OpenStdin is set, then it differs 5 func Compare(a, b *Config) bool { 6 if a == nil || b == nil || 7 a.OpenStdin || b.OpenStdin { 8 return false 9 } 10 if a.AttachStdout != b.AttachStdout || 11 a.AttachStderr != b.AttachStderr || 12 a.User != b.User || 13 a.OpenStdin != b.OpenStdin || 14 a.Tty != b.Tty { 15 return false 16 } 17 18 if a.Cmd.Len() != b.Cmd.Len() || 19 len(a.Env) != len(b.Env) || 20 len(a.Labels) != len(b.Labels) || 21 len(a.ExposedPorts) != len(b.ExposedPorts) || 22 a.Entrypoint.Len() != b.Entrypoint.Len() || 23 len(a.Volumes) != len(b.Volumes) { 24 return false 25 } 26 27 aCmd := a.Cmd.Slice() 28 bCmd := b.Cmd.Slice() 29 for i := 0; i < len(aCmd); i++ { 30 if aCmd[i] != bCmd[i] { 31 return false 32 } 33 } 34 for i := 0; i < len(a.Env); i++ { 35 if a.Env[i] != b.Env[i] { 36 return false 37 } 38 } 39 for k, v := range a.Labels { 40 if v != b.Labels[k] { 41 return false 42 } 43 } 44 for k := range a.ExposedPorts { 45 if _, exists := b.ExposedPorts[k]; !exists { 46 return false 47 } 48 } 49 50 aEntrypoint := a.Entrypoint.Slice() 51 bEntrypoint := b.Entrypoint.Slice() 52 for i := 0; i < len(aEntrypoint); i++ { 53 if aEntrypoint[i] != bEntrypoint[i] { 54 return false 55 } 56 } 57 for key := range a.Volumes { 58 if _, exists := b.Volumes[key]; !exists { 59 return false 60 } 61 } 62 return true 63 }