Little helper to run CNCF's k3s in Docker
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
k3d/tests/dind.sh

62 lines
1.8 KiB

5 years ago
#!/bin/bash
K3D_EXE=${EXE:-/bin/k3d}
K3D_IMAGE_TAG=$1
# define E2E_KEEP to non-empty for keeping the e2e runner container after running the tests
E2E_KEEP=${E2E_KEEP:-}
# Max. time to wait for the runner container to be up
RUNNER_START_TIMEOUT=${E2E_RUNNER_START_TIMEOUT:-10}
5 years ago
####################################################################################
5 years ago
# Start the runner container
TIMESTAMP=$(date "+%y%m%d%H%M%S")
5 years ago
k3de2e=$(docker run -d \
-v "$(pwd):/src" \
5 years ago
--privileged \
-e EXE="$K3D_EXE" \
-e CI="true" \
-e LOG_LEVEL="$LOG_LEVEL" \
-e E2E_INCLUDE="$E2E_INCLUDE" \
-e E2E_EXCLUDE="$E2E_EXCLUDE" \
-e E2E_EXTRA="$E2E_EXTRA" \
-e LOG_TIMESTAMPS="true" \
--add-host "k3d-registrytest-registry:127.0.0.1" \
5 years ago
--name "k3d-e2e-runner-$TIMESTAMP" \
"k3d:$K3D_IMAGE_TAG")
5 years ago
# setup exit trap (make sure that we always stop and remove the runner container)
5 years ago
finish() {
docker stop "$k3de2e" || /bin/true
if [ -z "$E2E_KEEP" ] ; then
docker rm "$k3de2e" || /bin/true
fi
}
trap finish EXIT
# wait for the runner container to be up or exit early
TIMEOUT=0
until docker inspect "$k3de2e" | jq ".[0].State.Running" && docker logs "$k3de2e" 2>&1 | grep -i "API listen on /var/run/docker.sock"; do
if [[ $TIMEOUT -eq $RUNNER_START_TIMEOUT ]]; then
echo "Failed to start E2E Runner Container in $RUNNER_START_TIMEOUT seconds"
exit 1
fi
sleep 1
(( TIMEOUT++ ))
done
# build helper container images
if [ -z "$E2E_HELPER_IMAGE_TAG" ]; then
docker exec --workdir /src "$k3de2e" make build-helper-images
# execute tests
echo "Start time outside runner: $(date)"
docker exec "$k3de2e" /src/tests/runner.sh
else
# execute tests
docker exec -e "K3D_HELPER_IMAGE_TAG=$E2E_HELPER_IMAGE_TAG" "$k3de2e" /src/tests/runner.sh
fi