github.com/goern/docker@v1.9.0-rc1/integration-cli/docker_test_vars.go (about)

     1  package main
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"os"
     7  	"os/exec"
     8  
     9  	"github.com/docker/docker/pkg/reexec"
    10  )
    11  
    12  var (
    13  	// the docker binary to use
    14  	dockerBinary = "docker"
    15  
    16  	// the private registry image to use for tests involving the registry
    17  	registryImageName = "registry"
    18  
    19  	// the private registry to use for tests
    20  	privateRegistryURL = "127.0.0.1:5000"
    21  
    22  	runtimePath    = "/var/run/docker"
    23  	execDriverPath = runtimePath + "/execdriver/native"
    24  
    25  	workingDirectory string
    26  
    27  	// isLocalDaemon is true if the daemon under test is on the same
    28  	// host as the CLI.
    29  	isLocalDaemon bool
    30  
    31  	// daemonPlatform is held globally so that tests can make intelligent
    32  	// decisions on how to configure themselves according to the platform
    33  	// of the daemon. This is initialised in docker_utils by sending
    34  	// a version call to the daemon and examining the response header.
    35  	daemonPlatform string
    36  
    37  	// daemonDefaultImage is the name of the default image to use when running
    38  	// tests. This is platform dependent.
    39  	daemonDefaultImage string
    40  
    41  	// For a local daemon on Linux, these values will be used for testing
    42  	// user namespace support as the standard graph path(s) will be
    43  	// appended with the root remapped uid.gid prefix
    44  	dockerBasePath       string
    45  	volumesConfigPath    string
    46  	containerStoragePath string
    47  )
    48  
    49  const (
    50  	// WindowsBaseImage is the name of the base image for Windows testing
    51  	WindowsBaseImage = "windowsservercore"
    52  
    53  	// DefaultImage is the name of the base image for the majority of tests that
    54  	// are run across suites
    55  	DefaultImage = "busybox"
    56  )
    57  
    58  func init() {
    59  	reexec.Init()
    60  	if dockerBin := os.Getenv("DOCKER_BINARY"); dockerBin != "" {
    61  		dockerBinary = dockerBin
    62  	}
    63  	var err error
    64  	dockerBinary, err = exec.LookPath(dockerBinary)
    65  	if err != nil {
    66  		fmt.Printf("ERROR: couldn't resolve full path to the Docker binary (%v)", err)
    67  		os.Exit(1)
    68  	}
    69  	if registryImage := os.Getenv("REGISTRY_IMAGE"); registryImage != "" {
    70  		registryImageName = registryImage
    71  	}
    72  	if registry := os.Getenv("REGISTRY_URL"); registry != "" {
    73  		privateRegistryURL = registry
    74  	}
    75  	workingDirectory, _ = os.Getwd()
    76  
    77  	// Deterministically working out the environment in which CI is running
    78  	// to evaluate whether the daemon is local or remote is not possible through
    79  	// a build tag.
    80  	//
    81  	// For example Windows CI under Jenkins test the 64-bit
    82  	// Windows binary build with the daemon build tag, but calls a remote
    83  	// Linux daemon.
    84  	//
    85  	// We can't just say if Windows then assume the daemon is local as at
    86  	// some point, we will be testing the Windows CLI against a Windows daemon.
    87  	//
    88  	// Similarly, it will be perfectly valid to also run CLI tests from
    89  	// a Linux CLI (built with the daemon tag) against a Windows daemon.
    90  	if len(os.Getenv("DOCKER_REMOTE_DAEMON")) > 0 {
    91  		isLocalDaemon = false
    92  	} else {
    93  		isLocalDaemon = true
    94  	}
    95  
    96  	// This is only used for a tests with local daemon true (Linux-only today)
    97  	// default is "/var/lib/docker", but we'll try and ask the
    98  	// /info endpoint for the specific root dir
    99  	dockerBasePath = "/var/lib/docker"
   100  	type Info struct {
   101  		DockerRootDir string
   102  	}
   103  	var i Info
   104  	status, b, err := sockRequest("GET", "/info", nil)
   105  	if err == nil && status == 200 {
   106  		if err = json.Unmarshal(b, &i); err == nil {
   107  			dockerBasePath = i.DockerRootDir
   108  		}
   109  	}
   110  	volumesConfigPath = dockerBasePath + "/volumes"
   111  	containerStoragePath = dockerBasePath + "/containers"
   112  }