2014-02-25 16:17:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-10-08 15:51:41 +00:00
|
|
|
"encoding/json"
|
2014-05-13 18:39:59 +00:00
|
|
|
"fmt"
|
2016-07-27 18:17:44 +00:00
|
|
|
"io/ioutil"
|
2014-02-25 16:17:48 +00:00
|
|
|
"os"
|
2014-05-13 18:39:59 +00:00
|
|
|
"os/exec"
|
2016-07-27 18:17:44 +00:00
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
2015-10-08 15:51:41 +00:00
|
|
|
|
2016-09-07 22:10:00 +00:00
|
|
|
"github.com/docker/docker/api/types/container"
|
2015-10-08 15:51:41 +00:00
|
|
|
"github.com/docker/docker/pkg/reexec"
|
2014-02-25 16:17:48 +00:00
|
|
|
)
|
|
|
|
|
2014-10-08 19:01:25 +00:00
|
|
|
var (
|
2016-05-26 11:14:35 +00:00
|
|
|
// the docker client binary to use
|
2014-10-08 19:01:25 +00:00
|
|
|
dockerBinary = "docker"
|
2016-05-26 11:14:35 +00:00
|
|
|
// the docker daemon binary to use
|
|
|
|
dockerdBinary = "dockerd"
|
2014-02-25 16:17:48 +00:00
|
|
|
|
2016-03-23 00:55:47 +00:00
|
|
|
// path to containerd's ctr binary
|
|
|
|
ctrBinary = "docker-containerd-ctr"
|
|
|
|
|
2014-10-08 19:01:25 +00:00
|
|
|
// the private registry image to use for tests involving the registry
|
|
|
|
registryImageName = "registry"
|
2014-02-25 16:17:48 +00:00
|
|
|
|
2014-10-08 19:01:25 +00:00
|
|
|
// the private registry to use for tests
|
|
|
|
privateRegistryURL = "127.0.0.1:5000"
|
2014-02-25 16:17:48 +00:00
|
|
|
|
2016-01-29 02:22:24 +00:00
|
|
|
// TODO Windows CI. These are incorrect and need fixing into
|
|
|
|
// platform specific pieces.
|
2016-03-18 19:43:17 +00:00
|
|
|
runtimePath = "/var/run/docker"
|
2015-03-24 17:47:30 +00:00
|
|
|
|
2014-10-08 19:01:25 +00:00
|
|
|
workingDirectory string
|
2015-08-05 16:21:45 +00:00
|
|
|
|
|
|
|
// isLocalDaemon is true if the daemon under test is on the same
|
|
|
|
// host as the CLI.
|
|
|
|
isLocalDaemon bool
|
2015-07-31 22:16:25 +00:00
|
|
|
|
|
|
|
// daemonPlatform is held globally so that tests can make intelligent
|
|
|
|
// decisions on how to configure themselves according to the platform
|
2015-12-13 16:00:39 +00:00
|
|
|
// of the daemon. This is initialized in docker_utils by sending
|
2015-07-31 22:16:25 +00:00
|
|
|
// a version call to the daemon and examining the response header.
|
|
|
|
daemonPlatform string
|
2015-09-01 21:37:04 +00:00
|
|
|
|
2015-09-23 23:04:51 +00:00
|
|
|
// windowsDaemonKV is used on Windows to distinguish between different
|
|
|
|
// versions. This is necessary to enable certain tests based on whether
|
2016-04-06 21:01:12 +00:00
|
|
|
// the platform supports it. For example, Windows Server 2016 TP3 did
|
|
|
|
// not support volumes, but TP4 did.
|
2015-09-23 23:04:51 +00:00
|
|
|
windowsDaemonKV int
|
|
|
|
|
2015-09-01 21:37:04 +00:00
|
|
|
// daemonDefaultImage is the name of the default image to use when running
|
|
|
|
// tests. This is platform dependent.
|
|
|
|
daemonDefaultImage string
|
2015-10-08 15:51:41 +00:00
|
|
|
|
|
|
|
// For a local daemon on Linux, these values will be used for testing
|
|
|
|
// user namespace support as the standard graph path(s) will be
|
|
|
|
// appended with the root remapped uid.gid prefix
|
|
|
|
dockerBasePath string
|
|
|
|
volumesConfigPath string
|
|
|
|
containerStoragePath string
|
2016-04-06 01:45:30 +00:00
|
|
|
|
2016-10-06 14:09:54 +00:00
|
|
|
// experimentalDaemon tell whether the main daemon has
|
|
|
|
// experimental features enabled or not
|
|
|
|
experimentalDaemon bool
|
|
|
|
|
2016-04-06 01:45:30 +00:00
|
|
|
// daemonStorageDriver is held globally so that tests can know the storage
|
|
|
|
// driver of the daemon. This is initialized in docker_utils by sending
|
|
|
|
// a version call to the daemon and examining the response header.
|
|
|
|
daemonStorageDriver string
|
2015-09-01 21:37:04 +00:00
|
|
|
|
|
|
|
// WindowsBaseImage is the name of the base image for Windows testing
|
2016-07-20 16:59:52 +00:00
|
|
|
// Environment variable WINDOWS_BASE_IMAGE can override this
|
2016-10-21 00:02:26 +00:00
|
|
|
WindowsBaseImage = "microsoft/windowsservercore"
|
2016-07-27 18:17:44 +00:00
|
|
|
|
2016-09-07 22:10:00 +00:00
|
|
|
// isolation is the isolation mode of the daemon under test
|
|
|
|
isolation container.Isolation
|
|
|
|
|
2016-07-27 18:17:44 +00:00
|
|
|
// daemonPid is the pid of the main test daemon
|
|
|
|
daemonPid int
|
2016-11-19 16:41:07 +00:00
|
|
|
|
|
|
|
daemonKernelVersion string
|
2016-07-20 16:59:52 +00:00
|
|
|
)
|
2015-09-01 21:37:04 +00:00
|
|
|
|
2016-07-20 16:59:52 +00:00
|
|
|
const (
|
2015-09-01 21:37:04 +00:00
|
|
|
// DefaultImage is the name of the base image for the majority of tests that
|
|
|
|
// are run across suites
|
|
|
|
DefaultImage = "busybox"
|
2014-10-08 19:01:25 +00:00
|
|
|
)
|
2014-02-25 16:17:48 +00:00
|
|
|
|
|
|
|
func init() {
|
2015-10-08 15:51:41 +00:00
|
|
|
reexec.Init()
|
2014-02-25 16:17:48 +00:00
|
|
|
if dockerBin := os.Getenv("DOCKER_BINARY"); dockerBin != "" {
|
|
|
|
dockerBinary = dockerBin
|
2015-01-10 00:28:40 +00:00
|
|
|
}
|
|
|
|
var err error
|
|
|
|
dockerBinary, err = exec.LookPath(dockerBinary)
|
|
|
|
if err != nil {
|
2016-08-23 00:59:45 +00:00
|
|
|
fmt.Printf("ERROR: couldn't resolve full path to the Docker binary (%v)\n", err)
|
2015-01-10 00:28:40 +00:00
|
|
|
os.Exit(1)
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
if registryImage := os.Getenv("REGISTRY_IMAGE"); registryImage != "" {
|
|
|
|
registryImageName = registryImage
|
|
|
|
}
|
|
|
|
if registry := os.Getenv("REGISTRY_URL"); registry != "" {
|
|
|
|
privateRegistryURL = registry
|
|
|
|
}
|
|
|
|
workingDirectory, _ = os.Getwd()
|
2015-08-05 16:21:45 +00:00
|
|
|
|
|
|
|
// Deterministically working out the environment in which CI is running
|
|
|
|
// to evaluate whether the daemon is local or remote is not possible through
|
|
|
|
// a build tag.
|
|
|
|
//
|
2016-01-29 02:22:24 +00:00
|
|
|
// For example Windows to Linux CI under Jenkins tests the 64-bit
|
2015-08-05 16:21:45 +00:00
|
|
|
// Windows binary build with the daemon build tag, but calls a remote
|
|
|
|
// Linux daemon.
|
|
|
|
//
|
|
|
|
// We can't just say if Windows then assume the daemon is local as at
|
|
|
|
// some point, we will be testing the Windows CLI against a Windows daemon.
|
|
|
|
//
|
|
|
|
// Similarly, it will be perfectly valid to also run CLI tests from
|
|
|
|
// a Linux CLI (built with the daemon tag) against a Windows daemon.
|
|
|
|
if len(os.Getenv("DOCKER_REMOTE_DAEMON")) > 0 {
|
|
|
|
isLocalDaemon = false
|
|
|
|
} else {
|
|
|
|
isLocalDaemon = true
|
|
|
|
}
|
2015-10-08 15:51:41 +00:00
|
|
|
|
2016-01-29 02:22:24 +00:00
|
|
|
// TODO Windows CI. This are incorrect and need fixing into
|
|
|
|
// platform specific pieces.
|
2015-10-08 15:51:41 +00:00
|
|
|
// This is only used for a tests with local daemon true (Linux-only today)
|
|
|
|
// default is "/var/lib/docker", but we'll try and ask the
|
|
|
|
// /info endpoint for the specific root dir
|
|
|
|
dockerBasePath = "/var/lib/docker"
|
|
|
|
type Info struct {
|
2016-10-06 14:09:54 +00:00
|
|
|
DockerRootDir string
|
|
|
|
ExperimentalBuild bool
|
2016-11-19 16:41:07 +00:00
|
|
|
KernelVersion string
|
2015-10-08 15:51:41 +00:00
|
|
|
}
|
|
|
|
var i Info
|
|
|
|
status, b, err := sockRequest("GET", "/info", nil)
|
|
|
|
if err == nil && status == 200 {
|
|
|
|
if err = json.Unmarshal(b, &i); err == nil {
|
|
|
|
dockerBasePath = i.DockerRootDir
|
2016-10-06 14:09:54 +00:00
|
|
|
experimentalDaemon = i.ExperimentalBuild
|
2016-11-19 16:41:07 +00:00
|
|
|
daemonKernelVersion = i.KernelVersion
|
2015-10-08 15:51:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
volumesConfigPath = dockerBasePath + "/volumes"
|
|
|
|
containerStoragePath = dockerBasePath + "/containers"
|
2016-07-20 16:59:52 +00:00
|
|
|
|
|
|
|
if len(os.Getenv("WINDOWS_BASE_IMAGE")) > 0 {
|
|
|
|
WindowsBaseImage = os.Getenv("WINDOWS_BASE_IMAGE")
|
|
|
|
fmt.Println("INFO: Windows Base image is ", WindowsBaseImage)
|
|
|
|
}
|
2016-07-27 18:17:44 +00:00
|
|
|
|
|
|
|
dest := os.Getenv("DEST")
|
|
|
|
b, err = ioutil.ReadFile(filepath.Join(dest, "docker.pid"))
|
|
|
|
if err == nil {
|
|
|
|
if p, err := strconv.ParseInt(string(b), 10, 32); err == nil {
|
|
|
|
daemonPid = int(p)
|
|
|
|
}
|
|
|
|
}
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|