2016-08-26 14:49:06 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Script for launching the Docker integration tests
|
2019-03-10 22:20:43 +01:00
|
|
|
# XXX: We currently only support running integration-cli.
|
2016-08-26 14:49:06 +02:00
|
|
|
#
|
|
|
|
|
2019-03-11 05:39:28 +01:00
|
|
|
set -Eeuo pipefail
|
2016-08-26 14:49:06 +02:00
|
|
|
|
|
|
|
DOCKER_DIR=/usr/src/docker
|
2019-03-11 05:39:28 +01:00
|
|
|
SCRIPTS_DIR="$DOCKER_DIR/hack"
|
|
|
|
TESTS_EXE="$DOCKER_DIR/integration-cli/tests.main"
|
|
|
|
VERSION="$(cat "$DOCKER_DIR/VERSION")"
|
2016-08-26 14:49:06 +02:00
|
|
|
|
|
|
|
# working dirs
|
|
|
|
TESTS_DIR=/tmp/docker-int-tests
|
2019-03-11 05:39:28 +01:00
|
|
|
FROZEN_IMAGES=/docker-frozen-images
|
|
|
|
BUNDLES_DIR="$TESTS_DIR/run/bundles"
|
2016-08-26 14:49:06 +02:00
|
|
|
|
2016-09-06 16:03:21 +02:00
|
|
|
CHECK_TIMEOUT="${CHECK_TIMEOUT:-5m}"
|
|
|
|
TEST_TIMEOUT="${TEST_TIMEOUT:-60m}"
|
2019-03-11 05:39:28 +01:00
|
|
|
TEST_ARGS=("-check.v" "-check.timeout=${CHECK_TIMEOUT}" "-test.timeout=${TEST_TIMEOUT}")
|
2016-08-26 14:49:06 +02:00
|
|
|
TEST_SELECT=
|
|
|
|
TEST_LOG=/tmp/docker-tests.log
|
2019-03-11 05:39:28 +01:00
|
|
|
ENABLE_XUNIT="${ENABLE_XUNIT-yes}"
|
|
|
|
KEEPBUNDLE="${KEEPBUNDLE:-}"
|
2016-08-26 14:49:06 +02:00
|
|
|
|
2019-03-11 01:44:36 +01:00
|
|
|
# the config file for Docker
|
|
|
|
CFG_DOCKER=/etc/docker/daemon.json
|
2016-08-26 14:49:06 +02:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
2019-03-11 05:39:28 +01:00
|
|
|
log() { echo ">>> $@" ; }
|
|
|
|
warn() { log "WARNING: $@" ; }
|
|
|
|
error() { log "ERROR: $@" ; }
|
|
|
|
abort() { log "FATAL: $@" ; exit 1 ; }
|
|
|
|
usage() { echo "$USAGE" ; }
|
|
|
|
abort_usage() { usage ; abort "$@" ; }
|
2016-08-26 14:49:06 +02:00
|
|
|
|
|
|
|
bundle() {
|
2019-03-11 05:39:28 +01:00
|
|
|
local bundle="$1"; shift
|
|
|
|
log "Making bundle: $(basename "$bundle") (in $DEST)"
|
|
|
|
local oldFlags="$-"
|
|
|
|
set +Eeu
|
|
|
|
source "$SCRIPTS_DIR/make/$bundle" "$@"
|
|
|
|
set "-$oldFlags"
|
2016-08-26 14:49:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fix_expected() {
|
2019-03-11 05:39:28 +01:00
|
|
|
EXPECTED="$1"
|
|
|
|
EXISTING="$2"
|
|
|
|
|
|
|
|
exp_base="$(basename "$EXPECTED")"
|
|
|
|
exp_dir="$(dirname "$EXPECTED")"
|
|
|
|
[ -d "$exp_dir" ] || mkdir -p "$exp_dir"
|
|
|
|
rm -f "$exp_dir/$exp_base"
|
|
|
|
( cd "$exp_dir" && ln -sf "$EXISTING" "$exp_base" )
|
2016-08-26 14:49:06 +02:00
|
|
|
}
|
|
|
|
|
2019-03-11 05:39:28 +01:00
|
|
|
save_backup() {
|
|
|
|
for x in $@ ; do
|
|
|
|
if [ ! -f "$x" ] ; then
|
|
|
|
touch "$x.nbak"
|
|
|
|
elif [ -f "$x.bak" ] ; then
|
|
|
|
warn "$x.bak already exists: no backup will be done"
|
|
|
|
else
|
|
|
|
cp -f "$x" "$x.bak"
|
|
|
|
fi
|
|
|
|
done
|
2016-08-26 14:49:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
restore_backup() {
|
2019-03-11 05:39:28 +01:00
|
|
|
for x in $@ ; do
|
|
|
|
if [ -f "$x.nbak" ] ; then
|
|
|
|
rm -f "$x.nbak"
|
|
|
|
else
|
|
|
|
if [ -f "$x.bak" ] ; then
|
|
|
|
mv -f "$x.bak" "$x"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2016-08-26 14:49:06 +02:00
|
|
|
}
|
|
|
|
|
2019-03-11 05:39:28 +01:00
|
|
|
require_go() { go version >/dev/null 2>&1 ; }
|
|
|
|
require_git() { git version >/dev/null 2>&1 ; }
|
2016-08-26 14:49:06 +02:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
2019-03-11 05:39:28 +01:00
|
|
|
[ -x "$TESTS_EXE" ] || abort "integration tests executable not found at $TESTS_EXE"
|
|
|
|
[ "$EUID" -eq 0 ] || abort "this script must be run as root"
|
|
|
|
[ -n "$VERSION" ] || abort "could not obtain version"
|
2016-08-26 14:49:06 +02:00
|
|
|
|
2019-03-11 05:39:28 +01:00
|
|
|
if [ "$#" -gt 0 ] ; then
|
|
|
|
# run only some specific tests
|
|
|
|
TEST_SELECT="-check.f=$(echo $@ | tr ' ' '|')"
|
2016-08-26 14:49:06 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# We want this to fail if the bundles already exist and cannot be removed.
|
|
|
|
# This is to avoid mixing bundles from different versions of the code.
|
2019-03-11 05:39:28 +01:00
|
|
|
mkdir -p "$BUNDLES_DIR"
|
2016-08-26 14:49:06 +02:00
|
|
|
if [ -e "$BUNDLES_DIR/$VERSION" ] && [ -z "$KEEPBUNDLE" ]; then
|
2019-03-11 05:39:28 +01:00
|
|
|
log "$BUNDLES_DIR/$VERSION already exists. Removing."
|
|
|
|
rm -fr "$BUNDLES_DIR/$VERSION" && mkdir "$BUNDLES_DIR/$VERSION" || exit 1
|
|
|
|
echo
|
2016-08-26 14:49:06 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
DEST="$BUNDLES_DIR/$VERSION/"
|
|
|
|
mkdir -p "$DEST"
|
2019-03-11 05:39:28 +01:00
|
|
|
export DEST="$(realpath "$DEST")"
|
2016-08-26 14:49:06 +02:00
|
|
|
|
|
|
|
if [ -n "$ENABLE_XUNIT" ] ; then
|
2019-03-11 05:39:28 +01:00
|
|
|
if [ ! -x /usr/local/bin/go2xunit ] ; then
|
|
|
|
echo >&2 "Installing go2xunit."
|
2016-08-26 14:49:06 +02:00
|
|
|
|
2019-03-11 05:39:28 +01:00
|
|
|
require_go || abort "the Go compiler is not installed"
|
2016-08-26 14:49:06 +02:00
|
|
|
|
2019-03-11 05:39:28 +01:00
|
|
|
export GOPATH="$(mktemp -d)"
|
2016-08-26 14:49:06 +02:00
|
|
|
|
2019-03-11 05:39:28 +01:00
|
|
|
go get -d github.com/tebeka/go2xunit
|
|
|
|
cd "$GOPATH/src/github.com/tebeka/go2xunit" && go build -o /usr/local/bin/go2xunit .
|
|
|
|
chmod 755 /usr/local/bin/go2xunit
|
|
|
|
[ -x /usr/local/bin/go2xunit ] || abort "go2xunit could not be built"
|
2016-08-26 14:49:06 +02:00
|
|
|
|
2019-03-11 05:39:28 +01:00
|
|
|
rm -rf "$GOPATH"
|
|
|
|
export -n GOPATH
|
|
|
|
fi
|
2016-08-26 14:49:06 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# tests require this user and group
|
|
|
|
/usr/sbin/groupadd -r docker >/dev/null 2>&1 || /bin/true
|
|
|
|
/usr/sbin/useradd --create-home --gid docker unprivilegeduser >/dev/null 2>&1 || /bin/true
|
|
|
|
|
|
|
|
# prepare some expected dirs, files, etc...
|
2019-03-11 05:39:28 +01:00
|
|
|
fix_expected "$TESTS_DIR/contrib" "$DOCKER_DIR/contrib"
|
|
|
|
fix_expected "$DEST/fixtures" "$DOCKER_DIR/integration-cli/fixtures"
|
|
|
|
fix_expected "$DEST/../Dockerfile" "$DOCKER_DIR/Dockerfile"
|
2016-08-26 14:49:06 +02:00
|
|
|
|
|
|
|
export DOCKER_TEST_HOST="tcp://127.0.0.1:2375"
|
2019-03-11 05:39:28 +01:00
|
|
|
export PATH="/usr/local/bin:$PATH"
|
2016-08-26 14:49:06 +02:00
|
|
|
export TZ=utc
|
|
|
|
|
|
|
|
export DOCKER_GRAPHDRIVER="${DOCKER_GRAPHDRIVER:-vfs}"
|
|
|
|
export DOCKER_USERLANDPROXY="${DOCKER_USERLANDPROXY:-true}"
|
2019-03-11 05:39:28 +01:00
|
|
|
export DOCKER_STORAGE_OPTS="${DOCKER_STORAGE_OPTS:-}"
|
|
|
|
export DOCKER_REMAP_ROOT="${DOCKER_REMAP_ROOT:-}" # "default" uses dockremap
|
2016-08-26 14:49:06 +02:00
|
|
|
|
2019-03-11 05:39:28 +01:00
|
|
|
# Example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G".
|
|
|
|
storage_opts=()
|
2016-08-26 14:49:06 +02:00
|
|
|
if [ -n "$DOCKER_STORAGE_OPTS" ]; then
|
2019-03-11 05:39:28 +01:00
|
|
|
IFS=','
|
|
|
|
for i in ${DOCKER_STORAGE_OPTS}; do
|
|
|
|
storage_opts+=("$i")
|
|
|
|
done
|
|
|
|
unset IFS
|
2016-08-26 14:49:06 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# deal with remapping
|
|
|
|
save_backup /etc/subuid /etc/subgid
|
2019-03-11 05:39:28 +01:00
|
|
|
echo "dockremap:500000:65536" >/etc/subuid
|
|
|
|
echo "dockremap:500000:65536" >/etc/subgid
|
|
|
|
groupadd dockremap >/dev/null 2>&1 || /bin/true
|
|
|
|
useradd -g dockremap dockremap >/dev/null 2>&1 || /bin/true
|
2016-08-26 14:49:06 +02:00
|
|
|
|
|
|
|
# make sure Docker is stopped, set our config file and then start again
|
2019-03-11 05:39:28 +01:00
|
|
|
save_backup "$CFG_DOCKER"
|
|
|
|
cat <<CFG_DOCKER_EOF >"$CFG_DOCKER"
|
2019-03-11 01:44:36 +01:00
|
|
|
{
|
|
|
|
"log-level": "debug",
|
|
|
|
"log-driver": "json-file",
|
|
|
|
"log-opts": {
|
|
|
|
"max-size": "50m",
|
|
|
|
"max-file": "5"
|
|
|
|
},
|
2019-03-11 05:39:28 +01:00
|
|
|
"userns-remap": "$DOCKER_REMAP_ROOT",
|
2019-03-11 01:44:36 +01:00
|
|
|
"pidfile": "$DEST/docker.pid",
|
2019-03-11 05:39:28 +01:00
|
|
|
"hosts": [
|
2019-03-11 01:44:36 +01:00
|
|
|
"tcp://127.0.0.1:2375"
|
|
|
|
],
|
|
|
|
"storage-driver": "$DOCKER_GRAPHDRIVER",
|
2019-03-11 05:39:28 +01:00
|
|
|
"storage-opts": [
|
|
|
|
$(printf '"%s",' "${storage_opts[@]}" | sed 's/"",//g;$s/,$//')
|
|
|
|
],
|
2019-03-11 01:44:36 +01:00
|
|
|
"userland-proxy": $DOCKER_USERLANDPROXY
|
|
|
|
}
|
|
|
|
CFG_DOCKER_EOF
|
|
|
|
systemctl restart docker.service
|
2016-08-26 14:49:06 +02:00
|
|
|
|
|
|
|
cleanup() {
|
2019-03-11 05:39:28 +01:00
|
|
|
log "Restoring the Docker service..."
|
|
|
|
restore_backup "$CFG_DOCKER"
|
|
|
|
systemctl restart docker.service
|
|
|
|
|
|
|
|
log "Removing extra files and restoring backups..."
|
|
|
|
restore_backup /etc/subuid /etc/subgid
|
|
|
|
rm -f "$TESTS_DIR/contrib" "$DEST/fixtures"
|
|
|
|
rm -rf "$FROZEN_IMAGES"
|
2016-08-26 14:49:06 +02:00
|
|
|
}
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
2019-03-11 05:39:28 +01:00
|
|
|
cd "$DOCKER_DIR"
|
2016-08-26 14:49:06 +02:00
|
|
|
|
|
|
|
log "Preparing the environment..."
|
2019-03-11 05:39:28 +01:00
|
|
|
export MAKEDIR="$SCRIPTS_DIR/make"
|
|
|
|
export DOCKER_HOST="$DOCKER_TEST_HOST"
|
2016-08-26 14:49:06 +02:00
|
|
|
bundle .integration-daemon-setup
|
|
|
|
|
2019-03-11 05:39:28 +01:00
|
|
|
# XXX: Really this should be sourced from the Dockerfile but this is good
|
|
|
|
# enough for now. This comes from the Docker 18.09.1-ce Dockerfile.
|
|
|
|
log "Downlading frozen images..."
|
|
|
|
mkdir -p "$FROZEN_IMAGES"
|
|
|
|
"$DOCKER_DIR/contrib/download-frozen-image-v2.sh" "$FROZEN_IMAGES" \
|
|
|
|
buildpack-deps:jessie@sha256:dd86dced7c9cd2a724e779730f0a53f93b7ef42228d4344b25ce9a42a1486251 \
|
|
|
|
busybox:latest@sha256:bbc3a03235220b170ba48a157dd097dd1379299370e1ed99ce976df0355d24f0 \
|
|
|
|
busybox:glibc@sha256:0b55a30394294ab23b9afd58fab94e61a923f5834fba7ddbae7f8e0c11ba85e6 \
|
|
|
|
debian:jessie@sha256:287a20c5f73087ab406e6b364833e3fb7b3ae63ca0eb3486555dc27ed32c6e60 \
|
|
|
|
hello-world:latest@sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
|
|
|
|
|
2016-08-26 14:49:06 +02:00
|
|
|
log "Running integration tests..."
|
2019-03-11 05:39:28 +01:00
|
|
|
cd "$DEST" && \
|
|
|
|
"$TESTS_EXE" "${TEST_ARGS[@]}" $TEST_SELECT 2>&1 | tee "$TEST_LOG" || /bin/true
|
2016-08-26 14:49:06 +02:00
|
|
|
if [ -n "$ENABLE_XUNIT" ] ; then
|
2019-03-11 05:39:28 +01:00
|
|
|
log "Generating xunit logs..."
|
|
|
|
go2xunit -fail -gocheck -input "$TEST_LOG" -output "$TEST_LOG.xml"
|
2016-08-26 14:49:06 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
export -n DOCKER_HOST
|