compare.go 1.3 KB

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