compare.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package cache
  2. import "github.com/docker/docker/api/types/container"
  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 *container.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. if len(a.Cmd) != len(b.Cmd) ||
  18. len(a.Env) != len(b.Env) ||
  19. len(a.Labels) != len(b.Labels) ||
  20. len(a.ExposedPorts) != len(b.ExposedPorts) ||
  21. len(a.Entrypoint) != len(b.Entrypoint) ||
  22. len(a.Volumes) != len(b.Volumes) {
  23. return false
  24. }
  25. for i := 0; i < len(a.Cmd); i++ {
  26. if a.Cmd[i] != b.Cmd[i] {
  27. return false
  28. }
  29. }
  30. for i := 0; i < len(a.Env); i++ {
  31. if a.Env[i] != b.Env[i] {
  32. return false
  33. }
  34. }
  35. for k, v := range a.Labels {
  36. if v != b.Labels[k] {
  37. return false
  38. }
  39. }
  40. for k := range a.ExposedPorts {
  41. if _, exists := b.ExposedPorts[k]; !exists {
  42. return false
  43. }
  44. }
  45. for i := 0; i < len(a.Entrypoint); i++ {
  46. if a.Entrypoint[i] != b.Entrypoint[i] {
  47. return false
  48. }
  49. }
  50. for key := range a.Volumes {
  51. if _, exists := b.Volumes[key]; !exists {
  52. return false
  53. }
  54. }
  55. return true
  56. }