docker_test_vars.go 3.6 KB

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