github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/cli/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 container_ip() { 6 local cid=$1 7 local network=$2 8 docker inspect \ 9 -f "{{.NetworkSettings.Networks.${network}.IPAddress}}" "$cid" 10 } 11 12 fetch_images() { 13 ./scripts/test/e2e/load-image fetch-only 14 } 15 16 setup() { 17 local project=$1 18 local file=$2 19 20 test "${DOCKERD_EXPERIMENTAL:-0}" -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 is_swarm_enabled() { 50 docker info 2> /dev/null | grep -q 'Swarm: active' 51 } 52 53 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 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:/usr/local/bin:/usr/local/go/bin" \ 72 HOME="$HOME" \ 73 DOCKER_CLI_E2E_PLUGINS_EXTRA_DIRS="$PWD/build/plugins-linux-amd64" \ 74 "$(command -v gotestsum)" -- ${TESTDIRS:-./e2e/...} ${TESTFLAGS-} 75 } 76 77 export unique_id="${E2E_UNIQUE_ID:-cliendtoendsuite}" 78 compose_env_file=./e2e/compose-env.yaml 79 80 cmd=${1-} 81 82 case "$cmd" in 83 setup) 84 setup "$unique_id" "$compose_env_file" 85 exit 86 ;; 87 cleanup) 88 cleanup "$unique_id" "$compose_env_file" 89 exit 90 ;; 91 fetch-images) 92 fetch_images 93 exit 94 ;; 95 test) 96 engine_host=${2-} 97 if [ -z "${engine_host}" ]; then 98 echo "missing parameter docker engine host" 99 echo "Usage: $0 test ENGINE_HOST" 100 exit 3 101 fi 102 runtests "$engine_host" 103 ;; 104 run|"") 105 engine_host="$(setup "$unique_id" "$compose_env_file")" 106 testexit=0 107 runtests "$engine_host" || testexit=$? 108 cleanup "$unique_id" "$compose_env_file" 109 exit $testexit 110 ;; 111 shell) 112 $SHELL 113 ;; 114 *) 115 echo "Unknown command: $cmd" 116 echo "Usage: " 117 echo " $0 [setup | cleanup | test | run] [engine_host]" 118 exit 1 119 ;; 120 esac