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