docker_test_vars.go 4.0 KB

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