github.com/kim0/docker@v0.6.2-0.20161130212042-4addda3f07e7/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 84 const ( 85 // DefaultImage is the name of the base image for the majority of tests that 86 // are run across suites 87 DefaultImage = "busybox" 88 ) 89 90 func init() { 91 reexec.Init() 92 if dockerBin := os.Getenv("DOCKER_BINARY"); dockerBin != "" { 93 dockerBinary = dockerBin 94 } 95 var err error 96 dockerBinary, err = exec.LookPath(dockerBinary) 97 if err != nil { 98 fmt.Printf("ERROR: couldn't resolve full path to the Docker binary (%v)\n", err) 99 os.Exit(1) 100 } 101 if registryImage := os.Getenv("REGISTRY_IMAGE"); registryImage != "" { 102 registryImageName = registryImage 103 } 104 if registry := os.Getenv("REGISTRY_URL"); registry != "" { 105 privateRegistryURL = registry 106 } 107 workingDirectory, _ = os.Getwd() 108 109 // Deterministically working out the environment in which CI is running 110 // to evaluate whether the daemon is local or remote is not possible through 111 // a build tag. 112 // 113 // For example Windows to Linux CI under Jenkins tests the 64-bit 114 // Windows binary build with the daemon build tag, but calls a remote 115 // Linux daemon. 116 // 117 // We can't just say if Windows then assume the daemon is local as at 118 // some point, we will be testing the Windows CLI against a Windows daemon. 119 // 120 // Similarly, it will be perfectly valid to also run CLI tests from 121 // a Linux CLI (built with the daemon tag) against a Windows daemon. 122 if len(os.Getenv("DOCKER_REMOTE_DAEMON")) > 0 { 123 isLocalDaemon = false 124 } else { 125 isLocalDaemon = true 126 } 127 128 // TODO Windows CI. This are incorrect and need fixing into 129 // platform specific pieces. 130 // This is only used for a tests with local daemon true (Linux-only today) 131 // default is "/var/lib/docker", but we'll try and ask the 132 // /info endpoint for the specific root dir 133 dockerBasePath = "/var/lib/docker" 134 type Info struct { 135 DockerRootDir string 136 ExperimentalBuild bool 137 } 138 var i Info 139 status, b, err := sockRequest("GET", "/info", nil) 140 if err == nil && status == 200 { 141 if err = json.Unmarshal(b, &i); err == nil { 142 dockerBasePath = i.DockerRootDir 143 experimentalDaemon = i.ExperimentalBuild 144 } 145 } 146 volumesConfigPath = dockerBasePath + "/volumes" 147 containerStoragePath = dockerBasePath + "/containers" 148 149 if len(os.Getenv("WINDOWS_BASE_IMAGE")) > 0 { 150 WindowsBaseImage = os.Getenv("WINDOWS_BASE_IMAGE") 151 fmt.Println("INFO: Windows Base image is ", WindowsBaseImage) 152 } 153 154 dest := os.Getenv("DEST") 155 b, err = ioutil.ReadFile(filepath.Join(dest, "docker.pid")) 156 if err == nil { 157 if p, err := strconv.ParseInt(string(b), 10, 32); err == nil { 158 daemonPid = int(p) 159 } 160 } 161 }