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)
This commit is contained in:
Derek McGowan 2015-08-17 17:00:58 -07:00
parent 77c6d9deb9
commit 1a6949134e
3 changed files with 23 additions and 29 deletions

View file

@ -1,10 +1,6 @@
#!/bin/sh #!/bin/sh
set -e set -e
# Set IP address in /etc/hosts for localregistry
IP=$(ifconfig eth0|grep "inet addr:"| cut -d: -f2 | awk '{ print $1}')
echo "$IP localregistry" >> /etc/hosts
hostname=$1 hostname=$1
if [ "$hostname" = "" ]; then if [ "$hostname" = "" ]; then
hostname="localhost" hostname="localhost"

View file

@ -2,19 +2,13 @@
set -e set -e
set -x set -x
source helpers.bash
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
# Port used by engine under test source helpers.bash
ENGINE_PORT=5216
# Root directory of Distribution # Root directory of Distribution
DISTRIBUTION_ROOT=$(cd ../..; pwd -P) DISTRIBUTION_ROOT=$(cd ../..; pwd -P)
DOCKER_GRAPHDRIVER=${DOCKER_GRAPHDRIVER:-overlay}
EXEC_DRIVER=${EXEC_DRIVER:-native}
volumeMount="" volumeMount=""
if [ "$DOCKER_VOLUME" != "" ]; then if [ "$DOCKER_VOLUME" != "" ]; then
volumeMount="-v ${DOCKER_VOLUME}:/var/lib/docker" volumeMount="-v ${DOCKER_VOLUME}:/var/lib/docker"
@ -41,17 +35,19 @@ TESTS=${@:-.}
docker pull $INTEGRATION_IMAGE docker pull $INTEGRATION_IMAGE
# Start a Docker engine inside a docker container # Start a Docker engine inside a docker container
ID=$(docker run -d -it -p $ENGINE_PORT:$ENGINE_PORT --privileged $volumeMount $dockerMount \ ID=$(docker run -d -it --privileged $volumeMount $dockerMount \
-v ${DISTRIBUTION_ROOT}:/go/src/github.com/docker/distribution \ -v ${DISTRIBUTION_ROOT}:/go/src/github.com/docker/distribution \
-e "ENGINE_PORT=$ENGINE_PORT" \
-e "DOCKER_GRAPHDRIVER=$DOCKER_GRAPHDRIVER" \ -e "DOCKER_GRAPHDRIVER=$DOCKER_GRAPHDRIVER" \
-e "EXEC_DRIVER=$EXEC_DRIVER" \ -e "EXEC_DRIVER=$EXEC_DRIVER" \
${INTEGRATION_IMAGE} \ ${INTEGRATION_IMAGE} \
./run_engine.sh) ./run_engine.sh)
# Stop container on exit
trap "docker rm -f -v $ID" EXIT
# Wait for it to become reachable. # Wait for it to become reachable.
tries=10 tries=10
until "$DOCKER_BINARY" -H "127.0.0.1:$ENGINE_PORT" version &> /dev/null; do until docker exec "$ID" docker version &> /dev/null; do
(( tries-- )) (( tries-- ))
if [ $tries -le 0 ]; then if [ $tries -le 0 ]; then
echo >&2 "error: daemon failed to start" echo >&2 "error: daemon failed to start"
@ -60,21 +56,20 @@ until "$DOCKER_BINARY" -H "127.0.0.1:$ENGINE_PORT" version &> /dev/null; do
sleep 1 sleep 1
done done
# Make sure we have images outside the container, to transfer to the container. # If no volume is specified, transfer images into the container from
# Not much will happen here if the images are already present. # the outer docker instance
docker-compose pull if [ "$DOCKER_VOLUME" == "" ]; then
docker-compose build # 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. # Transfer images to the inner container.
for image in "$INTEGRATION_IMAGE" registry:0.9.1 dockerintegration_nginx dockerintegration_registryv2; do for image in "$INTEGRATION_IMAGE" registry:0.9.1 dockerintegration_nginx dockerintegration_registryv2; do
docker save "$image" | "$DOCKER_BINARY" -H "127.0.0.1:$ENGINE_PORT" load docker save "$image" | docker exec -i "$ID" docker load
done done
fi
#DOCKER_HOST="tcp://127.0.0.1:$ENGINE_PORT" docker-compose pull
#DOCKER_HOST="tcp://127.0.0.1:$ENGINE_PORT" docker-compose build
# Run the tests. # Run the tests.
docker exec -it "$ID" sh -c "DOCKER_HOST=tcp://127.0.0.1:$ENGINE_PORT ./test_runner.sh $TESTS" docker exec -it "$ID" sh -c "./test_runner.sh $TESTS"
# Stop container
docker rm -f -v "$ID"

View file

@ -2,11 +2,14 @@
set -e set -e
set -x set -x
DOCKER_GRAPHDRIVER=${DOCKER_GRAPHDRIVER:-overlay}
EXEC_DRIVER=${EXEC_DRIVER:-native}
# Set IP address in /etc/hosts for localregistry # Set IP address in /etc/hosts for localregistry
IP=$(ifconfig eth0|grep "inet addr:"| cut -d: -f2 | awk '{ print $1}') IP=$(ifconfig eth0|grep "inet addr:"| cut -d: -f2 | awk '{ print $1}')
echo "$IP localregistry" >> /etc/hosts echo "$IP localregistry" >> /etc/hosts
sh install_certs.sh localregistry sh install_certs.sh localregistry
docker --daemon -H "0.0.0.0:$ENGINE_PORT" --log-level=panic \ docker --daemon --log-level=panic \
--storage-driver="$DOCKER_GRAPHDRIVER" --exec-driver="$EXEC_DRIVER" --storage-driver="$DOCKER_GRAPHDRIVER" --exec-driver="$EXEC_DRIVER"