2017-08-14 15:47:06 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Run integration tests against the latest docker-ce dind
|
|
|
|
set -eu -o pipefail
|
|
|
|
|
2019-02-26 06:09:21 -05:00
|
|
|
container_ip() {
|
2017-08-14 15:47:06 -04:00
|
|
|
local cid=$1
|
|
|
|
local network=$2
|
|
|
|
docker inspect \
|
|
|
|
-f "{{.NetworkSettings.Networks.${network}.IPAddress}}" "$cid"
|
|
|
|
}
|
|
|
|
|
2019-02-26 06:09:21 -05:00
|
|
|
fetch_images() {
|
2018-05-17 07:11:59 -04:00
|
|
|
./scripts/test/e2e/load-image fetch-only
|
|
|
|
}
|
|
|
|
|
2019-02-26 06:09:21 -05:00
|
|
|
setup() {
|
2017-08-14 15:47:06 -04:00
|
|
|
local project=$1
|
2018-06-25 05:46:35 -04:00
|
|
|
local file=$2
|
|
|
|
|
2018-12-17 09:26:03 -05:00
|
|
|
test "${DOCKERD_EXPERIMENTAL:-0}" -eq "1" && file="${file}:./e2e/compose-env.experimental.yaml"
|
2018-09-06 01:38:01 -04:00
|
|
|
|
2019-02-26 06:09:21 -05:00
|
|
|
if [ "${TEST_CONNHELPER:-}" = "ssh" ];then
|
2018-09-06 01:38:01 -04:00
|
|
|
test ! -f "${HOME}/.ssh/id_rsa" && ssh-keygen -t rsa -C docker-e2e-dummy -N "" -f "${HOME}/.ssh/id_rsa" -q
|
|
|
|
grep "^StrictHostKeyChecking no" "${HOME}/.ssh/config" > /dev/null 2>&1 || echo "StrictHostKeyChecking no" > "${HOME}/.ssh/config"
|
|
|
|
TEST_CONNHELPER_SSH_ID_RSA_PUB=$(cat "${HOME}/.ssh/id_rsa.pub")
|
|
|
|
export TEST_CONNHELPER_SSH_ID_RSA_PUB
|
|
|
|
file="${file}:./e2e/compose-env.connhelper-ssh.yaml"
|
|
|
|
fi
|
2023-09-26 06:15:19 -04:00
|
|
|
COMPOSE_PROJECT_NAME=$project COMPOSE_FILE=$file docker compose up --build -d >&2
|
2017-08-14 15:47:06 -04:00
|
|
|
|
|
|
|
local network="${project}_default"
|
|
|
|
# TODO: only run if inside a container
|
|
|
|
docker network connect "$network" "$(hostname)"
|
|
|
|
|
2023-09-26 06:15:19 -04:00
|
|
|
engine_ip="$(container_ip "${project}-engine-1" "$network")"
|
2017-08-14 15:47:06 -04:00
|
|
|
engine_host="tcp://$engine_ip:2375"
|
2019-02-26 06:09:21 -05:00
|
|
|
if [ "${TEST_CONNHELPER:-}" = "ssh" ];then
|
2018-09-06 01:38:01 -04:00
|
|
|
engine_host="ssh://penguin@${engine_ip}"
|
|
|
|
fi
|
2017-08-14 15:47:06 -04:00
|
|
|
(
|
|
|
|
export DOCKER_HOST="$engine_host"
|
2018-05-17 07:11:59 -04:00
|
|
|
timeout 200 ./scripts/test/e2e/wait-on-daemon
|
|
|
|
./scripts/test/e2e/load-image
|
2017-08-14 15:47:06 -04:00
|
|
|
is_swarm_enabled || docker swarm init
|
|
|
|
) >&2
|
|
|
|
echo "$engine_host"
|
|
|
|
}
|
|
|
|
|
2019-02-26 06:09:21 -05:00
|
|
|
is_swarm_enabled() {
|
2017-08-14 15:47:06 -04:00
|
|
|
docker info 2> /dev/null | grep -q 'Swarm: active'
|
|
|
|
}
|
|
|
|
|
2019-02-26 06:09:21 -05:00
|
|
|
cleanup() {
|
2018-05-17 07:11:59 -04:00
|
|
|
local project=$1
|
|
|
|
local network="${project}_default"
|
|
|
|
docker network disconnect "$network" "$(hostname)"
|
2023-09-26 06:15:19 -04:00
|
|
|
COMPOSE_PROJECT_NAME=$1 COMPOSE_FILE=$2 docker compose down -v --rmi local >&2
|
2017-08-14 15:47:06 -04:00
|
|
|
}
|
|
|
|
|
2019-02-26 06:09:21 -05:00
|
|
|
runtests() {
|
2017-08-14 15:47:06 -04:00
|
|
|
local engine_host=$1
|
|
|
|
|
2017-09-01 17:52:41 -04:00
|
|
|
# shellcheck disable=SC2086
|
2017-08-14 15:47:06 -04:00
|
|
|
env -i \
|
|
|
|
TEST_DOCKER_HOST="$engine_host" \
|
2018-05-17 07:11:59 -04:00
|
|
|
TEST_DOCKER_CERT_PATH="${DOCKER_CERT_PATH-}" \
|
|
|
|
TEST_REMOTE_DAEMON="${REMOTE_DAEMON-}" \
|
|
|
|
TEST_SKIP_PLUGIN_TESTS="${SKIP_PLUGIN_TESTS-}" \
|
2017-08-14 15:47:06 -04:00
|
|
|
GOPATH="$GOPATH" \
|
2019-01-24 11:53:42 -05:00
|
|
|
PATH="$PWD/build/:/usr/bin:/usr/local/bin:/usr/local/go/bin" \
|
2019-03-04 14:09:34 -05:00
|
|
|
HOME="$HOME" \
|
2018-12-11 09:15:04 -05:00
|
|
|
DOCKER_CLI_E2E_PLUGINS_EXTRA_DIRS="$PWD/build/plugins-linux-amd64" \
|
2021-07-15 09:15:38 -04:00
|
|
|
GO111MODULE=auto \
|
2019-03-11 12:02:55 -04:00
|
|
|
"$(command -v gotestsum)" -- ${TESTDIRS:-./e2e/...} ${TESTFLAGS-}
|
2017-08-14 15:47:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export unique_id="${E2E_UNIQUE_ID:-cliendtoendsuite}"
|
|
|
|
compose_env_file=./e2e/compose-env.yaml
|
|
|
|
|
|
|
|
cmd=${1-}
|
|
|
|
|
|
|
|
case "$cmd" in
|
|
|
|
setup)
|
|
|
|
setup "$unique_id" "$compose_env_file"
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
cleanup)
|
|
|
|
cleanup "$unique_id" "$compose_env_file"
|
|
|
|
exit
|
|
|
|
;;
|
2018-05-17 07:11:59 -04:00
|
|
|
fetch-images)
|
|
|
|
fetch_images
|
|
|
|
exit
|
|
|
|
;;
|
2017-08-14 15:47:06 -04:00
|
|
|
test)
|
|
|
|
engine_host=${2-}
|
2019-02-26 06:09:21 -05:00
|
|
|
if [ -z "${engine_host}" ]; then
|
2017-08-14 15:47:06 -04:00
|
|
|
echo "missing parameter docker engine host"
|
|
|
|
echo "Usage: $0 test ENGINE_HOST"
|
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
runtests "$engine_host"
|
|
|
|
;;
|
|
|
|
run|"")
|
|
|
|
engine_host="$(setup "$unique_id" "$compose_env_file")"
|
|
|
|
testexit=0
|
|
|
|
runtests "$engine_host" || testexit=$?
|
|
|
|
cleanup "$unique_id" "$compose_env_file"
|
|
|
|
exit $testexit
|
|
|
|
;;
|
2017-10-10 17:04:32 -04:00
|
|
|
shell)
|
|
|
|
$SHELL
|
|
|
|
;;
|
2017-08-14 15:47:06 -04:00
|
|
|
*)
|
|
|
|
echo "Unknown command: $cmd"
|
|
|
|
echo "Usage: "
|
|
|
|
echo " $0 [setup | cleanup | test | run] [engine_host]"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|