Accepting request 688119 from Virtualization:containers

OBS-URL: https://build.opensuse.org/request/show/688119
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/docker?expand=0&rev=88
This commit is contained in:
Dominique Leuenberger 2019-03-26 21:28:10 +00:00 committed by Git OBS Bridge
commit 9cd06bb880
7 changed files with 337 additions and 277 deletions

View File

@ -3,8 +3,8 @@
<param name="url">https://github.com/docker/docker-ce.git</param>
<param name="scm">git</param>
<param name="exclude">.git</param>
<param name="versionformat">18.09.1_ce.%h</param>
<param name="revision">v18.09.1</param>
<param name="versionformat">18.09.3_ce.%h</param>
<param name="revision">v18.09.3</param>
<param name="filename">docker</param>
</service>
<service name="recompress" mode="disabled">

View File

@ -0,0 +1,121 @@
From 87416bfab7420bb5d0b18269909eb71dcb8632c6 Mon Sep 17 00:00:00 2001
From: Aleksa Sarai <asarai@suse.de>
Date: Tue, 12 Mar 2019 18:37:31 +1100
Subject: [PATCH] integration-cli: don't build -test images if they already
exist
There's no need to try to re-build the test images if they already
exist. This change makes basically no difference to the upstream
integration test-suite running, but for users who want to run the
integration-cli suite on a host machine (such as distributions doing
tests) this change allows images to be pre-loaded such that compilers
aren't needed on the test machine.
However, this does remove the accidental re-compilation of nnp-test, as
well as handling errors far more cleanly (previously if an error
occurred during a test build, further tests won't attempt to rebuild
it).
SUSE-Bugs: bsc#1128746
Signed-off-by: Aleksa Sarai <asarai@suse.de>
---
.../fixtures_linux_daemon_test.go | 21 +++++++++--------
.../internal/test/environment/environment.go | 23 +++++++++++++++++++
2 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/components/engine/integration-cli/fixtures_linux_daemon_test.go b/components/engine/integration-cli/fixtures_linux_daemon_test.go
index 2387a9ebee2b..0a770a76a2a9 100644
--- a/components/engine/integration-cli/fixtures_linux_daemon_test.go
+++ b/components/engine/integration-cli/fixtures_linux_daemon_test.go
@@ -8,7 +8,6 @@ import (
"path/filepath"
"runtime"
"strings"
- "sync"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/internal/test/fixtures/load"
@@ -24,17 +23,13 @@ type logT interface {
Logf(string, ...interface{})
}
-var ensureSyscallTestOnce sync.Once
-
func ensureSyscallTest(c *check.C) {
- var doIt bool
- ensureSyscallTestOnce.Do(func() {
- doIt = true
- })
- if !doIt {
+ defer testEnv.ProtectImage(c, "syscall-test:latest")
+
+ // If the image already exists, there's nothing left to do.
+ if testEnv.HasExistingImage(c, "syscall-test:latest") {
return
}
- defer testEnv.ProtectImage(c, "syscall-test:latest")
// if no match, must build in docker, which is significantly slower
// (slower mostly because of the vfs graphdriver)
@@ -93,6 +88,14 @@ func ensureSyscallTestBuild(c *check.C) {
func ensureNNPTest(c *check.C) {
defer testEnv.ProtectImage(c, "nnp-test:latest")
+
+ // If the image already exists, there's nothing left to do.
+ if testEnv.HasExistingImage(c, "nnp-test:latest") {
+ return
+ }
+
+ // if no match, must build in docker, which is significantly slower
+ // (slower mostly because of the vfs graphdriver)
if testEnv.OSType != runtime.GOOS {
ensureNNPTestBuild(c)
return
diff --git a/components/engine/internal/test/environment/environment.go b/components/engine/internal/test/environment/environment.go
index 74c8e2ce0ad7..e1c8a49ea8cb 100644
--- a/components/engine/internal/test/environment/environment.go
+++ b/components/engine/internal/test/environment/environment.go
@@ -8,9 +8,12 @@ import (
"strings"
"github.com/docker/docker/api/types"
+ "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client"
+ "github.com/docker/docker/internal/test"
"github.com/docker/docker/internal/test/fixtures/load"
"github.com/pkg/errors"
+ "gotest.tools/assert"
)
// Execution contains information about the current test execution and daemon
@@ -145,6 +148,26 @@ func (e *Execution) APIClient() client.APIClient {
return e.client
}
+// HasExistingImage checks whether there is an image with the given reference.
+// Note that this is done by filtering and then checking whether there were any
+// results -- so ambiguous references might result in false-positives.
+func (e *Execution) HasExistingImage(t testingT, reference string) bool {
+ if ht, ok := t.(test.HelperT); ok {
+ ht.Helper()
+ }
+ client := e.APIClient()
+ filter := filters.NewArgs()
+ filter.Add("dangling", "false")
+ filter.Add("reference", reference)
+ imageList, err := client.ImageList(context.Background(), types.ImageListOptions{
+ All: true,
+ Filters: filter,
+ })
+ assert.NilError(t, err, "failed to list images")
+
+ return len(imageList) > 0
+}
+
// EnsureFrozenImagesLinux loads frozen test images into the daemon
// if they aren't already loaded
func EnsureFrozenImagesLinux(testEnv *Execution) error {
--
2.21.0

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:977edd36e90089a63712975d63bdce7b99d6b5ac8cddaa54b71c216c1ed75020
size 9334972

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f31da73c7540416c0043f3614e96ea927a37911af0c33bcca3b1377fb8fe910e
size 9492176

View File

@ -1,7 +1,22 @@
-------------------------------------------------------------------
Fri Mar 22 09:19:28 UTC 2019 - Sascha Grunert <sgrunert@suse.com>
- Update to Docker 18.09.3-ce. See upstream changelog in the packaged
/usr/share/doc/packages/docker/CHANGELOG.md.
-------------------------------------------------------------------
Sun Mar 10 21:12:09 UTC 2019 - Aleksa Sarai <asarai@suse.com>
- docker-test: improvements to test packaging (we don't need to ship around the
entire source tree, and we also need to build the born-again integration/
tests which contain a suite-per-directory). We also need a new patch which
fixes the handling of *-test images. bsc#1128746
+ bsc1128746-0001-integration-cli-don-t-build-test-images-if-they-alre.patch
-------------------------------------------------------------------
Tue Feb 26 09:39:57 UTC 2019 - Michal Jura <mjura@suse.com>
- Move daemon.json file to /etc/docker directory, bsc#1114832
- Move daemon.json file to /etc/docker directory, bsc#1114832
-------------------------------------------------------------------
Sat Feb 9 13:54:03 UTC 2019 - Aleksa Sarai <asarai@suse.com>

View File

@ -42,17 +42,17 @@
# helpfully injects into our build environment from the changelog). If you want
# to generate a new git_commit_epoch, use this:
# $ date --date="$(git show --format=fuller --date=iso $COMMIT_ID | grep -oP '(?<=^CommitDate: ).*')" '+%s'
%define git_version 4c52b901c6cb
%define git_commit_epoch 1547060456
%define git_version 774a1f4eee66
%define git_commit_epoch 1551333049
# These are the git commits required. We verify them against the source to make
# sure we didn't miss anything important when doing upgrades.
%define required_containerd 9754871865f7fe2f4e74d43e2fc7ccd237edcbce
%define required_dockerrunc 96ec2177ae841256168fcf76954f7177af9446eb
%define required_containerd e6b3f5632f50dbc4e9cb6288d911bf4f5e95b18e
%define required_dockerrunc 6635b4f0c6af3810594d2770f662f34ddc15b40d
%define required_libnetwork 2cfbf9b1f98162a55829a21cc603c76072a75382
Name: %{realname}%{name_suffix}
Version: 18.09.1_ce
Version: 18.09.3_ce
Release: 0
Summary: The Linux container runtime
License: Apache-2.0
@ -90,11 +90,13 @@ Patch405: bsc1001161-0002-cli-add-a-separate-domainname-flag.patch
# SUSE-FEATURE: Add support to mirror inofficial/private registries
# (https://github.com/docker/docker/pull/34319)
Patch500: private-registry-0001-Add-private-registry-mirror-support.patch
# SUSE-BACKPORT: Backport of test-only patch https://github.com/moby/moby/pull/38853. bsc1128746
Patch900: bsc1128746-0001-integration-cli-don-t-build-test-images-if-they-alre.patch
BuildRequires: audit
BuildRequires: bash-completion
BuildRequires: ca-certificates
BuildRequires: device-mapper-devel >= 1.2.68
BuildRequires: glibc-devel-static
BuildRequires: fdupes
BuildRequires: libapparmor-devel
BuildRequires: libbtrfs-devel >= 3.8
BuildRequires: libseccomp-devel >= 2.2
@ -217,17 +219,13 @@ Zsh command line completion support for %{name}.
%package test
%global __requires_exclude ^libgo.so.*$
Summary: Test package for docker
# Needed for test-suite.
Group: System/Management
BuildRequires: fdupes
Requires: apparmor-parser
Requires: bash-completion
Requires: device-mapper-devel >= 1.2.68
Requires: glibc-devel-static
Requires: libapparmor-devel
Requires: libbtrfs-devel >= 3.8
Requires: procps
Requires: sqlite3-devel
Requires: golang(API) = 1.8
Requires: curl
Requires: go
Requires: iputils
Requires: jq
Requires: net-tools-deprecated
# KUBIC-SPECIFIC: This was required when upgrading from the original kubic
# packaging, when everything was renamed to -kubic. It also is
# used to ensure that nothing complains too much when using
@ -279,9 +277,10 @@ docker container runtime configuration for kubeadm
# PATCH-SUSE: Mirror patch.
%patch500 -p1
%endif
# bsc#1128746
%patch900 -p1
cp %{SOURCE7} .
cp %{SOURCE9} .
%build
BUILDTAGS="exclude_graphdriver_aufs apparmor selinux seccomp pkcs11"
@ -317,19 +316,32 @@ mkdir -p src/github.com/docker/
ln -s $(pwd)/components/cli $(pwd)/src/github.com/docker/cli
export GOPATH=$GOPATH:$(pwd)
# DOCKER ENGINE
###################
## DOCKER ENGINE ##
###################
pushd components/engine/
# ignore the warning that we compile outside a Docker container
# Ignore the warning that we compile outside a Docker container.
./hack/make.sh dynbinary
# build the tests binary
GOPATH=$(pwd)/vendor:$(pwd)/.gopath/ go test \
-buildmode=pie \
-tags "$DOCKER_BUILDTAGS daemon autogen" \
-c github.com/docker/docker/integration-cli -o tests.main
# Build test binaries (integration-cli and integration/*). They are all stored
# within the testdir -- we will only end up installing these test files for
# docker-test.
for testdir in {integration-cli,integration/*/}
do
( find "$testdir" -name '*_test.go' | grep -q '.' ) || continue
GOPATH=$(pwd)/vendor:$(pwd)/.gopath/ go test \
-buildmode=pie \
-tags "$DOCKER_BUILDTAGS daemon autogen" \
-c "github.com/docker/docker/$testdir" -o "$testdir/tests.main"
done
popd
# DOCKER CLIENT
pushd components/cli
###################
## DOCKER CLIENT ##
###################
pushd components/cli/
./scripts/build/dynbinary
mkdir -p ./man/man1
@ -354,7 +366,6 @@ grep 'CONTAINERD_COMMIT=%{required_containerd}' hack/dockerfile/install/containe
grep 'LIBNETWORK_COMMIT=%{required_libnetwork}' hack/dockerfile/install/proxy.installer
%install
install -d %{buildroot}%{go_contribdir}
install -d %{buildroot}%{_bindir}
install -D -m755 components/cli/build/docker %{buildroot}/%{_bindir}/docker
install -D -m755 components/engine/bundles/latest/dynbinary-daemon/dockerd %{buildroot}/%{_bindir}/dockerd
@ -365,10 +376,6 @@ install -Dd -m 0755 \
install -D -m0644 components/cli/contrib/completion/bash/docker "%{buildroot}%{_sysconfdir}/bash_completion.d/%{realname}"
install -D -m0644 components/cli/contrib/completion/zsh/_docker "%{buildroot}%{_sysconfdir}/zsh_completion.d/%{realname}"
# copy all for the test package
install -d %{buildroot}%{_prefix}/src/docker/
cp -a components/engine/. %{buildroot}%{_prefix}/src/docker/engine
cp -a components/cli/. %{buildroot}%{_prefix}/src/docker/cli
#
# systemd service
@ -402,6 +409,18 @@ install -p -m 644 components/cli/man/man5/Dockerfile.5 %{buildroot}%{_mandir}/ma
install -d %{buildroot}%{_mandir}/man8
install -p -m 644 components/cli/man/man8/*.8 %{buildroot}%{_mandir}/man8
# install docker-test files -- we want to avoid installing the entire source tree.
install -d %{buildroot}%{_prefix}/src/docker/
install -D -m0755 %{SOURCE9} %{buildroot}%{_prefix}/src/docker/tests.sh
# We need hack/, contrib/, profiles/, and the integration*/ trees.
cp -a components/engine/{hack,contrib,profiles,integration{,-cli}} %{buildroot}%{_prefix}/src/docker/
echo "%{version}" > %{buildroot}%{_prefix}/src/docker/VERSION
# And now we can remove all *_test.go files -- since we already have test
# binaries. Due to a lot of hacks within the Docker integration tests, we can't
# really do a bigger cleanup than this.
find %{buildroot}%{_prefix}/src/docker \
-type f -name '*_test.go' -delete
%if "%flavour" == "kubic"
# place kubelet.env in fillupdir (for kubeadm-criconfig)
install -D -m 0644 %{SOURCE5} %{buildroot}%{_fillupdir}/sysconfig.kubelet
@ -473,14 +492,6 @@ getent group docker >/dev/null || groupadd -r docker
%files test
%defattr(-,root,root)
%{_prefix}/src/docker/
# exclude binaries
%exclude %{_prefix}/src/docker/engine/bundles/
%exclude %{_prefix}/src/docker/cli/build/
# exclude init configurations other than systemd
%exclude %{_prefix}/src/docker/engine/contrib/init/openrc
%exclude %{_prefix}/src/docker/engine/contrib/init/sysvinit-debian
%exclude %{_prefix}/src/docker/engine/contrib/init/sysvinit-redhat
%exclude %{_prefix}/src/docker/engine/contrib/init/upstart
%if "%flavour" == "kubic"
%files kubeadm-criconfig

377
tests.sh
View File

@ -1,292 +1,205 @@
#!/bin/bash
#
# Script for launching the Docker integration tests
# XXX: We currently only support running integration-cli.
#
#set -x
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
set -Eeuo pipefail
DOCKER_DIR=/usr/src/docker
SCRIPTS_DIR=$DOCKER_DIR/hack
TESTS_EXE=$SCRIPTS_DIR/tests.main
VERSION=$(cat $DOCKER_DIR/VERSION)
SCRIPTS_DIR="$DOCKER_DIR/hack"
VERSION="$(cat "$DOCKER_DIR/VERSION")"
# working dirs
TESTS_DIR=/tmp/docker-int-tests
BUNDLES_DIR=$TESTS_DIR/run/bundles
FAKE_GOPATH=$TESTS_DIR/go
FROZEN_IMAGES_DIR="/tmp/docker-frozen-images"
FROZEN_IMAGES_LINK=/docker-frozen-images
# some test expect the containerd socket here
CONTAINERD_SOCK=/run/containerd/containerd.sock
EXPECTED_CONTAINERD_SOCK=/var/run/docker/libcontainerd/docker-containerd.sock
# ... and some programs
CONTAINERD_CTR=/usr/sbin/containerd-ctr
EXPECTED_CONTAINERD_CTR=/usr/local/bin/docker-containerd-ctr
CHECK_TIMEOUT="${CHECK_TIMEOUT:-5m}"
TEST_TIMEOUT="${TEST_TIMEOUT:-60m}"
TEST_ARGS="-check.vv -check.timeout=${CHECK_TIMEOUT} -test.timeout=${TEST_TIMEOUT}"
readarray -t TESTS < <(find "$DOCKER_DIR/integration-cli" -type f -executable -name 'tests.main')
CHECK_TIMEOUT="${CHECK_TIMEOUT:-15m}"
TEST_TIMEOUT="${TEST_TIMEOUT:-0}"
TEST_ARGS=("-check.v" "-check.timeout=${CHECK_TIMEOUT}" "-test.timeout=${TEST_TIMEOUT}")
TEST_SELECT=
TEST_LOG=/tmp/docker-tests.log
ENABLE_XUNIT=${ENABLE_XUNIT:-yes}
KEEPBUNDLE="${KEEPBUNDLE:-}"
# the sysconfig file for Docker
SYSCFG_DOCKER=/etc/sysconfig/docker
# some vars from the Dockerfile
ENABLE_NOTARY=${ENABLE_NOTARY:-}
ENABLE_REGISTRY=${ENABLE_REGISTRY:-}
REGISTRY_COMMIT_SCHEMA1=ec87e9b6971d831f0eff752ddb54fb64693e51cd
REGISTRY_COMMIT=47a064d4195a9b56133891bbb13620c3ac83a827
NOTARY_VERSION=v0.3.0
# the config file for Docker
CFG_DOCKER=/etc/docker/daemon.json
################################################################################
log() { echo ">>> $@" ; }
warn() { log "WARNING: $@" ; }
error() { log "ERROR: $@" ; }
abort() { log "FATAL: $@" ; exit 1 ; }
usage() { echo "$USAGE" ; }
abort_usage() { usage ; abort $@ ; }
log() { echo ">>> $@" ; }
warn() { log "WARNING: $@" ; }
error() { log "ERROR: $@" ; }
abort() { log "FATAL: $@" ; exit 1 ; }
usage() { echo "$USAGE" ; }
abort_usage() { usage ; abort "$@" ; }
bundle() {
local bundle="$1"; shift
log "Making bundle: $(basename "$bundle") (in $DEST)"
source "$SCRIPTS_DIR/make/$bundle" "$@"
local bundle="$1"; shift
log "Making bundle: $(basename "$bundle") (in $PWD)"
local oldFlags="$-"
set +Eeu
source "$SCRIPTS_DIR/make/$bundle" "$@"
set "-$oldFlags"
}
set_opts() {
OPT="$1"
VALUE="$2"
FILE=$3
perl -pi -e "s/^$OPT=.*$//g" $FILE
echo "$OPT=\"$VALUE\"" >> $FILE
}
set_docker_opts() { set_opts "DOCKER_OPTS" "$DOCKER_OPTS" /etc/sysconfig/docker ; }
set_containerd_opts() { set_opts "CONTAINERD_OPTS" "$CONTAINERD_OPTS" /etc/sysconfig/containerd ; }
fix_expected() {
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)
}
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
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
}
restore_backup() {
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
for x in $@ ; do
if [ -f "$x.nbak" ] ; then
rm -f "$x.nbak"
elif [ -f "$x.bak" ] ; then
mv -f "$x.bak" "$x"
fi
done
}
require_go() { go version >/dev/null 2>&1 ; }
require_git() { git version >/dev/null 2>&1 ; }
require_go() { go version >/dev/null 2>&1 ; }
require_git() { git version >/dev/null 2>&1 ; }
################################################################################
[ -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"
[ -e $CONTAINERD_SOCK ] || abort "containerd socket not found at $CONTAINERD_SOCK"
[ -x $CONTAINERD_CTR ] || abort "containerd-ctr not found at $CONTAINERD_CTR"
[ "${#TESTS[@]}" -gt 0 ] || abort "integration tests executable not found in $DOCKER_DIR"
[ "$EUID" -eq 0 ] || abort "this script must be run as root"
[ -n "$VERSION" ] || abort "could not obtain version"
if [ $# -gt 0 ] ; then
# run only some specific tests
TEST_SELECT="-check.f=$(echo $@ | tr ' ' '|')"
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.
mkdir -p $BUNDLES_DIR
if [ -e "$BUNDLES_DIR/$VERSION" ] && [ -z "$KEEPBUNDLE" ]; then
log "$BUNDLES_DIR/$VERSION already exists. Removing."
rm -fr "$BUNDLES_DIR/$VERSION" && mkdir "$BUNDLES_DIR/$VERSION" || exit 1
echo
fi
DEST="$BUNDLES_DIR/$VERSION/"
mkdir -p "$DEST"
export DEST=$(realpath $DEST)
# create a fake go path
rm -rf $FAKE_GOPATH
mkdir -p $FAKE_GOPATH/src/github.com/docker
(cd $FAKE_GOPATH/src/github.com/docker && ln -sf $DOCKER_DIR docker)
if [ -n "$ENABLE_REGISTRY" ] ; then
# build the Docker registry
if [ ! -x /usr/local/bin/registry-v2 ] ; then
log "Building registry (commit:$REGISTRY_COMMIT)"
require_git || abort "git is not installed"
require_go || abort "the Go compiler is not installed"
export GOPATH="$(mktemp -d)"
git clone https://github.com/docker/distribution.git "$GOPATH/src/github.com/docker/distribution"
(cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT")
GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \
go build -o /usr/local/bin/registry-v2 github.com/docker/distribution/cmd/registry
(cd "$GOPATH/src/github.com/docker/distribution" && git checkout -q "$REGISTRY_COMMIT_SCHEMA1")
GOPATH="$GOPATH/src/github.com/docker/distribution/Godeps/_workspace:$GOPATH" \
go build -o /usr/local/bin/registry-v2-schema1 github.com/docker/distribution/cmd/registry
chmod 755 /usr/local/bin/registry-v2
[ -x /usr/local/bin/registry-v2 ] || abort "registry-v2 could not be built"
rm -rf "$GOPATH"
export -n GOPATH
fi
fi
if [ -n "$ENABLE_NOTARY" ] ; then
# build the Docker notary
if [ ! -x /usr/local/bin/notary-server ] ; then
export GO15VENDOREXPERIMENT=1
export GOPATH="$(mktemp -d)"
require_git || abort "git is not installed"
require_go || abort "the Go compiler is not installed"
log "Building notary (version:$NOTARY_VERSION)"
git clone https://github.com/docker/notary.git "$GOPATH/src/github.com/docker/notary"
(cd "$GOPATH/src/github.com/docker/notary" && git checkout -q "$NOTARY_VERSION")
GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \
go build -o /usr/local/bin/notary-server github.com/docker/notary/cmd/notary-server
GOPATH="$GOPATH/src/github.com/docker/notary/vendor:$GOPATH" \
go build -o /usr/local/bin/notary github.com/docker/notary/cmd/notary
chmod 755 /usr/local/bin/notary-server
[ -x /usr/local/bin/notary-server ] || abort "notary could not be built"
export -n GO15VENDOREXPERIMENT
rm -rf "$GOPATH"
export -n GOPATH
fi
fi
if [ -n "$ENABLE_XUNIT" ] ; then
if [ ! -x /usr/local/bin/go2xunit ] ; then
echo >&2 "Installing go2xunit."
require_go || abort "the Go compiler is not installed"
export GOPATH="$(mktemp -d)"
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"
rm -rf "$GOPATH"
export -n GOPATH
fi
if [ "$#" -gt 0 ] ; then
# run only some specific tests
TEST_ARGS+=( "-check.f=$(echo $@ | tr ' ' '|')" )
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...
fix_expected $TESTS_DIR/contrib $DOCKER_DIR/contrib
fix_expected $DEST/fixtures $DOCKER_DIR/integration-cli/fixtures
fix_expected $EXPECTED_CONTAINERD_SOCK $CONTAINERD_SOCK
fix_expected $EXPECTED_CONTAINERD_CTR $CONTAINERD_CTR
export DOCKER_TEST_HOST="tcp://127.0.0.1:2375"
export PATH=/usr/local/bin:$PATH
export PATH="/usr/local/bin:$PATH"
export TZ=utc
export GOPATH="$FAKE_GOPATH"
export DOCKER_GRAPHDRIVER="${DOCKER_GRAPHDRIVER:-vfs}"
export DOCKER_USERLANDPROXY="${DOCKER_USERLANDPROXY:-true}"
#export DOCKER_REMAP_ROOT=default
export DOCKER_STORAGE_OPTS="${DOCKER_STORAGE_OPTS:-}"
export DOCKER_REMAP_ROOT="${DOCKER_REMAP_ROOT:-}" # "default" uses dockremap
# example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G"
storage_params=""
# Example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G".
storage_opts=()
if [ -n "$DOCKER_STORAGE_OPTS" ]; then
IFS=','
for i in ${DOCKER_STORAGE_OPTS}; do
storage_params="--storage-opt $i $storage_params"
done
unset IFS
IFS=','
for i in ${DOCKER_STORAGE_OPTS}; do
storage_opts+=("$i")
done
unset IFS
fi
# example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G"
extra_params=""
# deal with remapping
save_backup /etc/subuid /etc/subgid
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
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
# make sure Docker is stopped, set our config file and then start again
save_backup $SYSCFG_DOCKER
cat <<SYSCFG_DOCKER_EOF > $SYSCFG_DOCKER
DOCKER_OPTS="--log-level=debug \
--pidfile=$DEST/docker.pid \
-H tcp://127.0.0.1:2375 \
--storage-driver=$DOCKER_GRAPHDRIVER \
--userland-proxy=$DOCKER_USERLANDPROXY"
DOCKER_NETWORK_OPTIONS=""
SYSCFG_DOCKER_EOF
systemctl reload-or-restart docker.service
save_backup "$CFG_DOCKER"
cat <<CFG_DOCKER_EOF >"$CFG_DOCKER"
{
"log-level": "debug",
"log-driver": "json-file",
"log-opts": {
"max-size": "50m",
"max-file": "5"
},
"userns-remap": "$DOCKER_REMAP_ROOT",
"hosts": [
"tcp://127.0.0.1:2375"
],
"storage-driver": "$DOCKER_GRAPHDRIVER",
"storage-opts": [
$(printf '"%s",' "${storage_opts[@]}" | sed 's/"",//g;$s/,$//')
],
"userland-proxy": $DOCKER_USERLANDPROXY
}
CFG_DOCKER_EOF
systemctl restart docker.service
cleanup() {
log "Restoring the Docker service..."
restore_backup $SYSCFG_DOCKER
systemctl reload-or-restart docker.service
log "Restoring configuration files..."
restore_backup /etc/subuid /etc/subgid "$CFG_DOCKER"
rm -f "$FROZEN_IMAGES_LINK"
log "Removing extra files and restoring backups..."
restore_backup /etc/subuid /etc/subgid
rm -f $TESTS_DIR/contrib \
$DEST/fixtures \
$EXPECTED_CONTAINERD_SOCK \
$EXPECTED_CONTAINERD_CTR
log "Removing images and containers..."
export DOCKER_HOST="$DOCKER_TEST_HOST"
docker ps -aq | xargs docker rm -f &>/dev/null || :
docker images -q | xargs docker rmi -f &>/dev/null || :
log "Restarting the Docker service in a pristine state..."
systemctl restart docker.service
}
trap cleanup EXIT
cd $DOCKER_DIR
cd "$DOCKER_DIR"
export MAKEDIR="$SCRIPTS_DIR/make"
export DOCKER_HOST="$DOCKER_TEST_HOST"
# Clean up all images on the host -- this is key to avoid test run failures.
log "Cleaning the environment..."
docker ps -aq | xargs docker rm -f &>/dev/null || :
docker images -q | xargs docker rmi -f &>/dev/null || :
log "Preparing the environment..."
bundle .integration-daemon-start
bundle .integration-daemon-setup
log "Running integration tests..."
export DOCKER_HOST=$DOCKER_TEST_HOST
cd $DEST && $TESTS_EXE $TEST_ARGS $TEST_SELECT | tee $TEST_LOG || /bin/true
if [ -n "$ENABLE_XUNIT" ] ; then
log "Generating xunit logs..."
go2xunit -fail -gocheck -input $TEST_LOG -output $TEST_LOG.xml
fi
# 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_DIR"
ln -sf "$FROZEN_IMAGES_DIR" "$FROZEN_IMAGES_LINK"
"$DOCKER_DIR/contrib/download-frozen-image-v2.sh" "$FROZEN_IMAGES_DIR" \
buildpack-deps:jessie@sha256:dd86dced7c9cd2a724e779730f0a53f93b7ef42228d4344b25ce9a42a1486251 \
busybox:latest@sha256:bbc3a03235220b170ba48a157dd097dd1379299370e1ed99ce976df0355d24f0 \
busybox:glibc@sha256:0b55a30394294ab23b9afd58fab94e61a923f5834fba7ddbae7f8e0c11ba85e6 \
debian:jessie@sha256:287a20c5f73087ab406e6b364833e3fb7b3ae63ca0eb3486555dc27ed32c6e60 \
hello-world:latest@sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
# The code within integration-cli which handles building *-test images doesn't
# appear to work within our setup, not to mention we don't want to Require: a
# bunch of build tools so we just use the provided Dockerfile and
# buildpack-deps.
tar -cC "$FROZEN_IMAGES_DIR" . | docker load
for dir in "$DOCKER_DIR"/contrib/*-test
do
log "Building *-test images ($dir)..."
docker build -t "$(basename "$dir")" "$dir"
done
# For some reason, dockerd appears to put the containerd.sock in the wrong
# place under systemd. So we just manually add a symlink for it.
[ -e "/var/run/docker/containerd/containerd.sock" ] || \
ln -s docker-containerd.sock /var/run/docker/containerd/containerd.sock
# And there appears to be an issue with daemon.json as a configuration format,
# so we need to hide our generated configuration. The original will be restored
# in cleanup().
rm -f "$CFG_DOCKER"
# Run all of our tests.
rm -f "$TEST_LOG"
for TEST in "${TESTS[@]}"
do
cd "$(dirname "$TEST")"
log "Running integration test ($TEST)..." | tee -a "$TEST_LOG"
"$TEST" "${TEST_ARGS[@]}" 2>&1 | tee -a "$TEST_LOG" || :
done
export -n DOCKER_HOST
bundle .integration-daemon-stop