forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_wrapper.sh
executable file
·71 lines (60 loc) · 1.92 KB
/
docker_wrapper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
#
# Wraps a test invocation in docker.
set -e
IMAGE=$1
RUN_REMOTE=$2
LOCAL_MOUNT=$3
DOCKER_ENV=$4
TEST_PATH=$(realpath "$5")
shift 5
if [ "${RUN_REMOTE}" == "yes" ]; then
echo "Using docker environment from ${DOCKER_ENV}:"
cat "${DOCKER_ENV}"
fi
# shellcheck disable=SC1090
. "${DOCKER_ENV}"
CONTAINER_NAME="envoy-test-runner"
ENVFILE=$(mktemp -t "bazel-test-env.XXXXXX")
function cleanup() {
rm -f "${ENVFILE}"
if [ "${RUN_REMOTE}" == "yes" ]; then
docker rm -f "${CONTAINER_NAME}" || true # We don't really care if it fails.
fi
}
trap cleanup EXIT
cat > "${ENVFILE}" <<EOF
TEST_WORKSPACE=/tmp/workspace
TEST_SRCDIR=/tmp/src
ENVOY_IP_TEST_VERSIONS=v4only
EOF
CMDLINE="set -a && . /env && env && /test $*"
LIB_PATHS="/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/ /lib64/"
if [ "${RUN_REMOTE}" != "yes" ]; then
# We're running locally. If told to, mount the library directories locally.
LIB_MOUNTS=()
if [ "${LOCAL_MOUNT}" == "yes" ]
then
for path in $LIB_PATHS; do
LIB_MOUNTS+=(-v "${path}:${path}:ro")
done
fi
docker run --rm --privileged -v "${TEST_PATH}:/test" "${LIB_MOUNTS[@]}" -i -v "${ENVFILE}:/env" \
"${IMAGE}" bash -c "${CMDLINE}"
else
# In this case, we need to create the container, then make new layers on top of it, since we
# can't mount everything into it.
docker create -t --privileged --name "${CONTAINER_NAME}" "${IMAGE}" \
bash -c "${CMDLINE}"
docker cp "$TEST_PATH" "${CONTAINER_NAME}:/test"
docker cp "$ENVFILE" "${CONTAINER_NAME}:/env"
# If some local libraries are necessary, copy them over.
if [ "${LOCAL_MOUNT}" == "yes" ]; then
for path in ${LIB_PATHS}; do
# $path. gives us a path ending it /. This means that we will copy the contents into the
# destination directory, not overwrite the entire directory.
docker cp -L "${path}." "${CONTAINER_NAME}:${path}"
done
fi
docker start -a "${CONTAINER_NAME}"
fi