github.com/mika/distribution@v2.2.2-0.20160108133430-a75790e3d8e0+incompatible/contrib/docker-integration/run.sh (about) 1 #!/usr/bin/env bash 2 set -e 3 set -x 4 5 cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" 6 7 source helpers.bash 8 9 # Root directory of Distribution 10 DISTRIBUTION_ROOT=$(cd ../..; pwd -P) 11 12 volumeMount="" 13 if [ "$DOCKER_VOLUME" != "" ]; then 14 volumeMount="-v ${DOCKER_VOLUME}:/var/lib/docker" 15 fi 16 17 dockerMount="" 18 if [ "$DOCKER_BINARY" != "" ]; then 19 dockerMount="-v ${DOCKER_BINARY}:/usr/local/bin/docker" 20 else 21 DOCKER_BINARY=docker 22 fi 23 24 # Image containing the integration tests environment. 25 INTEGRATION_IMAGE=${INTEGRATION_IMAGE:-distribution/docker-integration} 26 27 if [ "$1" == "-d" ]; then 28 start_daemon 29 shift 30 fi 31 32 TESTS=${@:-.} 33 34 # Make sure we upgrade the integration environment. 35 docker pull $INTEGRATION_IMAGE 36 37 # Start a Docker engine inside a docker container 38 ID=$(docker run -d -it --privileged $volumeMount $dockerMount \ 39 -v ${DISTRIBUTION_ROOT}:/go/src/github.com/docker/distribution \ 40 -e "DOCKER_GRAPHDRIVER=$DOCKER_GRAPHDRIVER" \ 41 ${INTEGRATION_IMAGE} \ 42 ./run_engine.sh) 43 44 # Stop container on exit 45 trap "docker rm -f -v $ID" EXIT 46 47 48 # Wait for it to become reachable. 49 tries=10 50 until docker exec "$ID" docker version &> /dev/null; do 51 (( tries-- )) 52 if [ $tries -le 0 ]; then 53 echo >&2 "error: daemon failed to start" 54 exit 1 55 fi 56 sleep 1 57 done 58 59 # If no volume is specified, transfer images into the container from 60 # the outer docker instance 61 if [ "$DOCKER_VOLUME" == "" ]; then 62 # Make sure we have images outside the container, to transfer to the container. 63 # Not much will happen here if the images are already present. 64 docker-compose pull 65 docker-compose build 66 67 # Transfer images to the inner container. 68 for image in "$INTEGRATION_IMAGE" registry:0.9.1 dockerintegration_nginx dockerintegration_registryv2; do 69 docker save "$image" | docker exec -i "$ID" docker load 70 done 71 fi 72 73 # Run the tests. 74 docker exec -it "$ID" sh -c "./test_runner.sh $TESTS" 75