docker_test_vars.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "os/exec"
  6. )
  7. var (
  8. // the docker binary to use
  9. dockerBinary = "docker"
  10. // the private registry image to use for tests involving the registry
  11. registryImageName = "registry"
  12. // the private registry to use for tests
  13. privateRegistryURL = "127.0.0.1:5000"
  14. dockerBasePath = "/var/lib/docker"
  15. volumesConfigPath = dockerBasePath + "/volumes"
  16. containerStoragePath = dockerBasePath + "/containers"
  17. runtimePath = "/var/run/docker"
  18. execDriverPath = runtimePath + "/execdriver/native"
  19. workingDirectory string
  20. // isLocalDaemon is true if the daemon under test is on the same
  21. // host as the CLI.
  22. isLocalDaemon bool
  23. )
  24. func init() {
  25. if dockerBin := os.Getenv("DOCKER_BINARY"); dockerBin != "" {
  26. dockerBinary = dockerBin
  27. }
  28. var err error
  29. dockerBinary, err = exec.LookPath(dockerBinary)
  30. if err != nil {
  31. fmt.Printf("ERROR: couldn't resolve full path to the Docker binary (%v)", err)
  32. os.Exit(1)
  33. }
  34. if registryImage := os.Getenv("REGISTRY_IMAGE"); registryImage != "" {
  35. registryImageName = registryImage
  36. }
  37. if registry := os.Getenv("REGISTRY_URL"); registry != "" {
  38. privateRegistryURL = registry
  39. }
  40. workingDirectory, _ = os.Getwd()
  41. // Deterministically working out the environment in which CI is running
  42. // to evaluate whether the daemon is local or remote is not possible through
  43. // a build tag.
  44. //
  45. // For example Windows CI under Jenkins test the 64-bit
  46. // Windows binary build with the daemon build tag, but calls a remote
  47. // Linux daemon.
  48. //
  49. // We can't just say if Windows then assume the daemon is local as at
  50. // some point, we will be testing the Windows CLI against a Windows daemon.
  51. //
  52. // Similarly, it will be perfectly valid to also run CLI tests from
  53. // a Linux CLI (built with the daemon tag) against a Windows daemon.
  54. if len(os.Getenv("DOCKER_REMOTE_DAEMON")) > 0 {
  55. fmt.Println("INFO: Testing against a remote daemon")
  56. isLocalDaemon = false
  57. } else {
  58. fmt.Println("INFO: Testing against a local daemon")
  59. isLocalDaemon = true
  60. }
  61. }