| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | # Run integration tests against the latest docker-ce dind |
| 3 | set -eu -o pipefail |
| 4 | |
| 5 | source ./scripts/build/.variablesscip-shell source . . `./scripts/build/.variables`. |
| 6 | |
| 7 | container_ipscip-shell shell shell-project 0.0.0 container_ip().() { |
| 8 | local cid=$1 |
| 9 | local network=$2 |
| 10 | docker inspect \ |
| 11 | -f "{{.NetworkSettings.Networks.${network}.IPAddress}}" "$cid" |
| 12 | } |
| 13 | |
| 14 | fetch_imagesscip-shell shell shell-project 0.0.0 fetch_images().() { |
| 15 | ./scripts/test/e2e/load-image fetch-only |
| 16 | } |
| 17 | |
| 18 | setupscip-shell shell shell-project 0.0.0 setup().() { |
| 19 | local project=$1 |
| 20 | local file=$2 |
| 21 | |
| 22 | if [scip-shell system . . `[`. "${TEST_CONNHELPER:-}" = "ssh" ];then |
| 23 | testscip-shell system . . test. ! -f "${HOME}/.ssh/id_rsa" && ssh-keygenscip-shell system . . ssh-keygen. -t rsa -C docker-e2e-dummy -N "" -f "${HOME}/.ssh/id_rsa" -q |
| 24 | grepscip-shell system . . grep. "^StrictHostKeyChecking no" "${HOME}/.ssh/config" > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || echoscip-shell system . . echo. "StrictHostKeyChecking no" > "${HOME}/.ssh/config" |
| 25 | TEST_CONNHELPER_SSH_ID_RSA_PUB=$(catscip-shell system . . 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" "$(hostnamescip-shell system . . hostname.)" |
| 34 | |
| 35 | engine_ip="$(container_ipscip-shell shell shell-project 0.0.0 container_ip(). "${project}-engine-1" "$network")" |
| 36 | engine_host="tcp://$engine_ip:2375" |
| 37 | if [scip-shell system . . `[`. "${TEST_CONNHELPER:-}" = "ssh" ];then |
| 38 | engine_host="ssh://penguin@${engine_ip}" |
| 39 | fi |
| 40 | ( |
| 41 | export DOCKER_HOST="$engine_host" |
| 42 | timeoutscip-shell system . . timeout. 200 ./scripts/test/e2e/wait-on-daemon |
| 43 | ./scripts/test/e2e/load-image |
| 44 | is_swarm_enabledscip-shell shell shell-project 0.0.0 is_swarm_enabled(). || docker swarm init |
| 45 | ) >&2 |
| 46 | echoscip-shell system . . echo. "$engine_host" |
| 47 | } |
| 48 | |
| 49 | is_swarm_enabledscip-shell shell shell-project 0.0.0 is_swarm_enabled().() { |
| 50 | docker info 2> /dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. -q 'Swarm: active' |
| 51 | } |
| 52 | |
| 53 | cleanupscip-shell shell shell-project 0.0.0 cleanup().() { |
| 54 | local project=$1 |
| 55 | local network="${project}_default" |
| 56 | docker network disconnect "$network" "$(hostnamescip-shell system . . hostname.)" |
| 57 | COMPOSE_PROJECT_NAME=$1 COMPOSE_FILE=$2 docker compose down -v --rmi local >&2 |
| 58 | } |
| 59 | |
| 60 | runtestsscip-shell shell shell-project 0.0.0 runtests().() { |
| 61 | local engine_host=$1 |
| 62 | |
| 63 | # shellcheck disable=SC2086 |
| 64 | enscip-shell system . . env.vscip-shell system . . env. -i \ |
| 65 | TEST_DOCKER_HOST="$engine_host" \ |
| 66 | TEST_DOCKER_CERT_PATH="${DOCKER_CERT_PATH-}" \ |
| 67 | TEST_REMOTE_DAEMON="${REMOTE_DAEMON-}" \ |
| 68 | TEST_SKIP_PLUGIN_TESTS="${SKIP_PLUGIN_TESTS-}" \ |
| 69 | GOPATH="$GOPATH" \ |
| 70 | PATH="$PWD/build/:/usr/bin:/usr/local/bin:/usr/local/go/bin" \ |
| 71 | HOME="$HOME" \ |
| 72 | DOCKER_CLI_E2E_PLUGINS_EXTRA_DIRS="$PWD/build/plugins-linux-${GOARCH}" \ |
| 73 | GO111MODULE=auto \ |
| 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 | setupscip-shell shell shell-project 0.0.0 setup(). "$unique_id" "$compose_env_file" |
| 85 | exit |
| 86 | ;; |
| 87 | cleanup) |
| 88 | cleanupscip-shell shell shell-project 0.0.0 cleanup(). "$unique_id" "$compose_env_file" |
| 89 | exit |
| 90 | ;; |
| 91 | fetch-images) |
| 92 | fetch_imagesscip-shell shell shell-project 0.0.0 fetch_images(). |
| 93 | exit |
| 94 | ;; |
| 95 | test) |
| 96 | engine_host=${2-} |
| 97 | if [scip-shell system . . `[`. -z "${engine_host}" ]; then |
| 98 | echoscip-shell system . . echo. "missing parameter docker engine host" |
| 99 | echoscip-shell system . . echo. "Usage: $0 test ENGINE_HOST" |
| 100 | exit 3 |
| 101 | fi |
| 102 | runtestsscip-shell shell shell-project 0.0.0 runtests(). "$engine_host" |
| 103 | ;; |
| 104 | run|"") |
| 105 | engine_host="$(setupscip-shell shell shell-project 0.0.0 setup(). "$unique_id" "$compose_env_file")" |
| 106 | testexit=0 |
| 107 | runtestsscip-shell shell shell-project 0.0.0 runtests(). "$engine_host" || testexit=$? |
| 108 | cleanupscip-shell shell shell-project 0.0.0 cleanup(). "$unique_id" "$compose_env_file" |
| 109 | exit $testexit |
| 110 | ;; |
| 111 | shell) |
| 112 | $SHELL |
| 113 | ;; |
| 114 | *) |
| 115 | echoscip-shell system . . echo. "Unknown command: $cmd" |
| 116 | echoscip-shell system . . echo. "Usage: " |
| 117 | echoscip-shell system . . echo. " $0 [setup | cleanup | test | run] [engine_host]" |
| 118 | exit 1 |
| 119 | ;; |
| 120 | esac |