run 3.4 KB

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