compare.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package cache
  2. import (
  3. "github.com/docker/docker/api/types/container"
  4. )
  5. // compare two Config struct. Do not compare the "Image" nor "Hostname" fields
  6. // If OpenStdin is set, then it differs
  7. func compare(a, b *container.Config) bool {
  8. if a == nil || b == nil ||
  9. a.OpenStdin || b.OpenStdin {
  10. return false
  11. }
  12. if a.AttachStdout != b.AttachStdout ||
  13. a.AttachStderr != b.AttachStderr ||
  14. a.User != b.User ||
  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.Labels) != len(b.Labels) ||
  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 k, v := range a.Labels {
  38. if v != b.Labels[k] {
  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. }