github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/scripts/test/e2e/run (about) 1 #!/usr/bin/env bash 2 # Run integration tests against the latest docker-ce dind 3 set -eu -o pipefail 4 5 function container_ip { 6 local cid=$1 7 local network=$2 8 docker inspect \ 9 -f "{{.NetworkSettings.Networks.${network}.IPAddress}}" "$cid" 10 } 11 12 function fetch_images { 13 ./scripts/test/e2e/load-image fetch-only 14 } 15 16 function setup { 17 local project=$1 18 local file=$2 19 20 test "${DOCKERD_EXPERIMENTAL:-}" -eq "1" && file="${file}:./e2e/compose-env.experimental.yaml" 21 22 if [[ "${TEST_CONNHELPER:-}" = "ssh" ]];then 23 test ! -f "${HOME}/.ssh/id_rsa" && ssh-keygen -t rsa -C docker-e2e-dummy -N "" -f "${HOME}/.ssh/id_rsa" -q 24 grep "^StrictHostKeyChecking no" "${HOME}/.ssh/config" > /dev/null 2>&1 || echo "StrictHostKeyChecking no" > "${HOME}/.ssh/config" 25 TEST_CONNHELPER_SSH_ID_RSA_PUB=$(cat "${HOME}/.ssh/id_rsa.pub") 26 export TEST_CONNHELPER_SSH_ID_RSA_PUB 27 file="${file}:./e2e/compose-env.connhelper-ssh.yaml" 28 fi 29 COMPOSE_PROJECT_NAME=$project COMPOSE_FILE=$file docker-compose up --build -d >&2 30 31 local network="${project}_default" 32 # TODO: only run if inside a container 33 docker network connect "$network" "$(hostname)" 34 35 engine_ip="$(container_ip "${project}_engine_1" "$network")" 36 engine_host="tcp://$engine_ip:2375" 37 if [[ "${TEST_CONNHELPER:-}" = "ssh" ]];then 38 engine_host="ssh://penguin@${engine_ip}" 39 fi 40 ( 41 export DOCKER_HOST="$engine_host" 42 timeout 200 ./scripts/test/e2e/wait-on-daemon 43 ./scripts/test/e2e/load-image 44 is_swarm_enabled || docker swarm init 45 ) >&2 46 echo "$engine_host" 47 } 48 49 function is_swarm_enabled { 50 docker info 2> /dev/null | grep -q 'Swarm: active' 51 } 52 53 function cleanup { 54 local project=$1 55 local network="${project}_default" 56 docker network disconnect "$network" "$(hostname)" 57 COMPOSE_PROJECT_NAME=$1 COMPOSE_FILE=$2 docker-compose down -v --rmi local >&2 58 } 59 60 function runtests { 61 local engine_host=$1 62 63 # shellcheck disable=SC2086 64 env -i \ 65 TEST_DOCKER_HOST="$engine_host" \ 66 TEST_DOCKER_CERT_PATH="${DOCKER_CERT_PATH-}" \ 67 TEST_KUBECONFIG="${KUBECONFIG-}" \ 68 TEST_REMOTE_DAEMON="${REMOTE_DAEMON-}" \ 69 TEST_SKIP_PLUGIN_TESTS="${SKIP_PLUGIN_TESTS-}" \ 70 GOPATH="$GOPATH" \ 71 PATH="$PWD/build/:/usr/bin" \ 72 "$(which go)" test -v ./e2e/... ${TESTFLAGS-} 73 } 74 75 export unique_id="${E2E_UNIQUE_ID:-cliendtoendsuite}" 76 compose_env_file=./e2e/compose-env.yaml 77 78 cmd=${1-} 79 80 case "$cmd" in 81 setup) 82 setup "$unique_id" "$compose_env_file" 83 exit 84 ;; 85 cleanup) 86 cleanup "$unique_id" "$compose_env_file" 87 exit 88 ;; 89 fetch-images) 90 fetch_images 91 exit 92 ;; 93 test) 94 engine_host=${2-} 95 if [[ -z "${engine_host}" ]]; then 96 echo "missing parameter docker engine host" 97 echo "Usage: $0 test ENGINE_HOST" 98 exit 3 99 fi 100 runtests "$engine_host" 101 ;; 102 run|"") 103 engine_host="$(setup "$unique_id" "$compose_env_file")" 104 testexit=0 105 runtests "$engine_host" || testexit=$? 106 cleanup "$unique_id" "$compose_env_file" 107 exit $testexit 108 ;; 109 shell) 110 $SHELL 111 ;; 112 *) 113 echo "Unknown command: $cmd" 114 echo "Usage: " 115 echo " $0 [setup | cleanup | test | run] [engine_host]" 116 exit 1 117 ;; 118 esac