github.com/SamWhited/moby@v1.13.1/integration-cli/docker_test_vars.go (about) 1 package main 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "io/ioutil" 7 "os" 8 "os/exec" 9 "path/filepath" 10 "strconv" 11 12 "github.com/docker/docker/api/types/container" 13 "github.com/docker/docker/pkg/reexec" 14 ) 15 16 var ( 17 // the docker client binary to use 18 dockerBinary = "docker" 19 // the docker daemon binary to use 20 dockerdBinary = "dockerd" 21 22 // path to containerd's ctr binary 23 ctrBinary = "docker-containerd-ctr" 24 25 // the private registry image to use for tests involving the registry 26 registryImageName = "registry" 27 28 // the private registry to use for tests 29 privateRegistryURL = "127.0.0.1:5000" 30 31 // TODO Windows CI. These are incorrect and need fixing into 32 // platform specific pieces. 33 runtimePath = "/var/run/docker" 34 35 workingDirectory string 36 37 // isLocalDaemon is true if the daemon under test is on the same 38 // host as the CLI. 39 isLocalDaemon bool 40 41 // daemonPlatform is held globally so that tests can make intelligent 42 // decisions on how to configure themselves according to the platform 43 // of the daemon. This is initialized in docker_utils by sending 44 // a version call to the daemon and examining the response header. 45 daemonPlatform string 46 47 // windowsDaemonKV is used on Windows to distinguish between different 48 // versions. This is necessary to enable certain tests based on whether 49 // the platform supports it. For example, Windows Server 2016 TP3 did 50 // not support volumes, but TP4 did. 51 windowsDaemonKV int 52 53 // daemonDefaultImage is the name of the default image to use when running 54 // tests. This is platform dependent. 55 daemonDefaultImage string 56 57 // For a local daemon on Linux, these values will be used for testing 58 // user namespace support as the standard graph path(s) will be 59 // appended with the root remapped uid.gid prefix 60 dockerBasePath string 61 volumesConfigPath string 62 containerStoragePath string 63 64 // experimentalDaemon tell whether the main daemon has 65 // experimental features enabled or not 66 experimentalDaemon bool 67 68 // daemonStorageDriver is held globally so that tests can know the storage 69 // driver of the daemon. This is initialized in docker_utils by sending 70 // a version call to the daemon and examining the response header. 71 daemonStorageDriver string 72 73 // WindowsBaseImage is the name of the base image for Windows testing 74 // Environment variable WINDOWS_BASE_IMAGE can override this 75 WindowsBaseImage = "microsoft/windowsservercore" 76 77 // isolation is the isolation mode of the daemon under test 78 isolation container.Isolation 79 80 // daemonPid is the pid of the main test daemon 81 daemonPid int 82 83 daemonKernelVersion string 84 ) 85 86 const ( 87 // DefaultImage is the name of the base image for the majority of tests that 88 // are run across suites 89 DefaultImage = "busybox" 90 ) 91 92 func init() { 93 reexec.Init() 94 if dockerBin := os.Getenv("DOCKER_BINARY"); dockerBin != "" { 95 dockerBinary = dockerBin 96 } 97 var err error 98 dockerBinary, err = exec.LookPath(dockerBinary) 99 if err != nil { 100 fmt.Printf("ERROR: couldn't resolve full path to the Docker binary (%v)\n", err) 101 os.Exit(1) 102 } 103 if registryImage := os.Getenv("REGISTRY_IMAGE"); registryImage != "" { 104 registryImageName = registryImage 105 } 106 if registry := os.Getenv("REGISTRY_URL"); registry != "" { 107 privateRegistryURL = registry 108 } 109 workingDirectory, _ = os.Getwd() 110 111 // Deterministically working out the environment in which CI is running 112 // to evaluate whether the daemon is local or remote is not possible through 113 // a build tag. 114 // 115 // For example Windows to Linux CI under Jenkins tests the 64-bit 116 // Windows binary build with the daemon build tag, but calls a remote 117 // Linux daemon. 118 // 119 // We can't just say if Windows then assume the daemon is local as at 120 // some point, we will be testing the Windows CLI against a Windows daemon. 121 // 122 // Similarly, it will be perfectly valid to also run CLI tests from 123 // a Linux CLI (built with the daemon tag) against a Windows daemon. 124 if len(os.Getenv("DOCKER_REMOTE_DAEMON")) > 0 { 125 isLocalDaemon = false 126 } else { 127 isLocalDaemon = true 128 } 129 130 // TODO Windows CI. This are incorrect and need fixing into 131 // platform specific pieces. 132 // This is only used for a tests with local daemon true (Linux-only today) 133 // default is "/var/lib/docker", but we'll try and ask the 134 // /info endpoint for the specific root dir 135 dockerBasePath = "/var/lib/docker" 136 type Info struct { 137 DockerRootDir string 138 ExperimentalBuild bool 139 KernelVersion string 140 } 141 var i Info 142 status, b, err := sockRequest("GET", "/info", nil) 143 if err == nil && status == 200 { 144 if err = json.Unmarshal(b, &i); err == nil { 145 dockerBasePath = i.DockerRootDir 146 experimentalDaemon = i.ExperimentalBuild 147 daemonKernelVersion = i.KernelVersion 148 } 149 } 150 volumesConfigPath = dockerBasePath + "/volumes" 151 containerStoragePath = dockerBasePath + "/containers" 152 153 if len(os.Getenv("WINDOWS_BASE_IMAGE")) > 0 { 154 WindowsBaseImage = os.Getenv("WINDOWS_BASE_IMAGE") 155 fmt.Println("INFO: Windows Base image is ", WindowsBaseImage) 156 } 157 158 dest := os.Getenv("DEST") 159 b, err = ioutil.ReadFile(filepath.Join(dest, "docker.pid")) 160 if err == nil { 161 if p, err := strconv.ParseInt(string(b), 10, 32); err == nil { 162 daemonPid = int(p) 163 } 164 } 165 }