docker_test_vars.go 3.8 KB

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