registry/contrib/docker-integration/run.sh
Derek McGowan 1a6949134e Fix mismatched version error on integration tests
When running a different version of docker outside of the default in the integration image, then commands will fail with mismatched version unless the docker binary is specified to the correct version.

Add various cleanups to run script.
Run all commands interacting with docker inside the container in an exec.
Remove port binding to outside of container since all commands run inside.
Trap docker rm to exit in case of failure which prevents final command from running.
Do no copy images when $DOCKER_VOLUME is specified, this allows for faster runs when mounting a volume with a warm image cache.
Move exec and graph driver defaulting into run engine script.
Remove duplicated update of /etc/hosts.

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
2015-08-17 17:00:58 -07:00

75 lines
1.8 KiB
Bash
Executable file

#!/usr/bin/env bash
set -e
set -x
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
source helpers.bash
# Root directory of Distribution
DISTRIBUTION_ROOT=$(cd ../..; pwd -P)
volumeMount=""
if [ "$DOCKER_VOLUME" != "" ]; then
volumeMount="-v ${DOCKER_VOLUME}:/var/lib/docker"
fi
dockerMount=""
if [ "$DOCKER_BINARY" != "" ]; then
dockerMount="-v ${DOCKER_BINARY}:/usr/local/bin/docker"
else
DOCKER_BINARY=docker
fi
# Image containing the integration tests environment.
INTEGRATION_IMAGE=${INTEGRATION_IMAGE:-distribution/docker-integration}
if [ "$1" == "-d" ]; then
start_daemon
shift
fi
TESTS=${@:-.}
# Make sure we upgrade the integration environment.
docker pull $INTEGRATION_IMAGE
# Start a Docker engine inside a docker container
ID=$(docker run -d -it --privileged $volumeMount $dockerMount \
-v ${DISTRIBUTION_ROOT}:/go/src/github.com/docker/distribution \
-e "DOCKER_GRAPHDRIVER=$DOCKER_GRAPHDRIVER" \
-e "EXEC_DRIVER=$EXEC_DRIVER" \
${INTEGRATION_IMAGE} \
./run_engine.sh)
# Stop container on exit
trap "docker rm -f -v $ID" EXIT
# Wait for it to become reachable.
tries=10
until docker exec "$ID" docker version &> /dev/null; do
(( tries-- ))
if [ $tries -le 0 ]; then
echo >&2 "error: daemon failed to start"
exit 1
fi
sleep 1
done
# If no volume is specified, transfer images into the container from
# the outer docker instance
if [ "$DOCKER_VOLUME" == "" ]; then
# Make sure we have images outside the container, to transfer to the container.
# Not much will happen here if the images are already present.
docker-compose pull
docker-compose build
# Transfer images to the inner container.
for image in "$INTEGRATION_IMAGE" registry:0.9.1 dockerintegration_nginx dockerintegration_registryv2; do
docker save "$image" | docker exec -i "$ID" docker load
done
fi
# Run the tests.
docker exec -it "$ID" sh -c "./test_runner.sh $TESTS"