docker_test_vars.go 3.3 KB

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