docker_test_vars.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "os"
  6. "os/exec"
  7. "github.com/docker/docker/pkg/reexec"
  8. )
  9. var (
  10. // the docker client binary to use
  11. dockerBinary = "docker"
  12. // the docker daemon binary to use
  13. dockerdBinary = "dockerd"
  14. // path to containerd's ctr binary
  15. ctrBinary = "docker-containerd-ctr"
  16. // the private registry image to use for tests involving the registry
  17. registryImageName = "registry"
  18. // the private registry to use for tests
  19. privateRegistryURL = "127.0.0.1:5000"
  20. // TODO Windows CI. These are incorrect and need fixing into
  21. // platform specific pieces.
  22. runtimePath = "/var/run/docker"
  23. workingDirectory string
  24. // isLocalDaemon is true if the daemon under test is on the same
  25. // host as the CLI.
  26. isLocalDaemon bool
  27. // daemonPlatform is held globally so that tests can make intelligent
  28. // decisions on how to configure themselves according to the platform
  29. // of the daemon. This is initialized in docker_utils by sending
  30. // a version call to the daemon and examining the response header.
  31. daemonPlatform string
  32. // windowsDaemonKV is used on Windows to distinguish between different
  33. // versions. This is necessary to enable certain tests based on whether
  34. // the platform supports it. For example, Windows Server 2016 TP3 did
  35. // not support volumes, but TP4 did.
  36. windowsDaemonKV int
  37. // daemonDefaultImage is the name of the default image to use when running
  38. // tests. This is platform dependent.
  39. daemonDefaultImage string
  40. // For a local daemon on Linux, these values will be used for testing
  41. // user namespace support as the standard graph path(s) will be
  42. // appended with the root remapped uid.gid prefix
  43. dockerBasePath string
  44. volumesConfigPath string
  45. containerStoragePath string
  46. // daemonStorageDriver is held globally so that tests can know the storage
  47. // driver of the daemon. This is initialized in docker_utils by sending
  48. // a version call to the daemon and examining the response header.
  49. daemonStorageDriver string
  50. )
  51. const (
  52. // WindowsBaseImage is the name of the base image for Windows testing
  53. WindowsBaseImage = "windowsservercore"
  54. // DefaultImage is the name of the base image for the majority of tests that
  55. // are run across suites
  56. DefaultImage = "busybox"
  57. )
  58. func init() {
  59. reexec.Init()
  60. if dockerBin := os.Getenv("DOCKER_BINARY"); dockerBin != "" {
  61. dockerBinary = dockerBin
  62. }
  63. var err error
  64. dockerBinary, err = exec.LookPath(dockerBinary)
  65. if err != nil {
  66. fmt.Printf("ERROR: couldn't resolve full path to the Docker binary (%v)", err)
  67. os.Exit(1)
  68. }
  69. if registryImage := os.Getenv("REGISTRY_IMAGE"); registryImage != "" {
  70. registryImageName = registryImage
  71. }
  72. if registry := os.Getenv("REGISTRY_URL"); registry != "" {
  73. privateRegistryURL = registry
  74. }
  75. workingDirectory, _ = os.Getwd()
  76. // Deterministically working out the environment in which CI is running
  77. // to evaluate whether the daemon is local or remote is not possible through
  78. // a build tag.
  79. //
  80. // For example Windows to Linux CI under Jenkins tests the 64-bit
  81. // Windows binary build with the daemon build tag, but calls a remote
  82. // Linux daemon.
  83. //
  84. // We can't just say if Windows then assume the daemon is local as at
  85. // some point, we will be testing the Windows CLI against a Windows daemon.
  86. //
  87. // Similarly, it will be perfectly valid to also run CLI tests from
  88. // a Linux CLI (built with the daemon tag) against a Windows daemon.
  89. if len(os.Getenv("DOCKER_REMOTE_DAEMON")) > 0 {
  90. isLocalDaemon = false
  91. } else {
  92. isLocalDaemon = true
  93. }
  94. // TODO Windows CI. This are incorrect and need fixing into
  95. // platform specific pieces.
  96. // This is only used for a tests with local daemon true (Linux-only today)
  97. // default is "/var/lib/docker", but we'll try and ask the
  98. // /info endpoint for the specific root dir
  99. dockerBasePath = "/var/lib/docker"
  100. type Info struct {
  101. DockerRootDir string
  102. }
  103. var i Info
  104. status, b, err := sockRequest("GET", "/info", nil)
  105. if err == nil && status == 200 {
  106. if err = json.Unmarshal(b, &i); err == nil {
  107. dockerBasePath = i.DockerRootDir
  108. }
  109. }
  110. volumesConfigPath = dockerBasePath + "/volumes"
  111. containerStoragePath = dockerBasePath + "/containers"
  112. }