github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/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          GO111MODULE=auto \
    75          "$(command -v gotestsum)" -- ${TESTDIRS:-./e2e/...} ${TESTFLAGS-}
    76  }
    77  
    78  export unique_id="${E2E_UNIQUE_ID:-cliendtoendsuite}"
    79  compose_env_file=./e2e/compose-env.yaml
    80  
    81  cmd=${1-}
    82  
    83  case "$cmd" in
    84      setup)
    85          setup "$unique_id" "$compose_env_file"
    86          exit
    87          ;;
    88      cleanup)
    89          cleanup "$unique_id" "$compose_env_file"
    90          exit
    91          ;;
    92      fetch-images)
    93          fetch_images
    94          exit
    95          ;;
    96      test)
    97          engine_host=${2-}
    98          if [ -z "${engine_host}" ]; then
    99              echo "missing parameter docker engine host"
   100              echo "Usage: $0 test ENGINE_HOST"
   101              exit 3
   102          fi
   103          runtests "$engine_host"
   104          ;;
   105      run|"")
   106          engine_host="$(setup "$unique_id" "$compose_env_file")"
   107          testexit=0
   108          runtests "$engine_host" || testexit=$?
   109          cleanup "$unique_id" "$compose_env_file"
   110          exit $testexit
   111          ;;
   112      shell)
   113          $SHELL
   114          ;;
   115      *)
   116          echo "Unknown command: $cmd"
   117          echo "Usage: "
   118          echo "    $0 [setup | cleanup | test | run] [engine_host]"
   119          exit 1
   120          ;;
   121  esac