forked from mozilla/ichnaea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_env.sh
executable file
·115 lines (98 loc) · 3.16 KB
/
test_env.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
# Script that sets up the docker environment to run the tests in and runs the
# tests.
# Pass --shell to run a shell in the test container.
# Failures should cause setup to fail
set -v -e -x
# Set PS4 so it's easier to differentiate between this script and run_tests.sh
# running
PS4="+ (test_env.sh): "
DC="$(which docker-compose)"
ICHNAEA_UID=${ICHNAEA_UID:-"10001"}
ICHNAEA_GID=${ICHNAEA_GID:-"10001"}
ICHNAEA_DOCKER_DB_ENGINE=${ICHNAEA_DOCKER_DB_ENGINE:-"mysql_5_7"}
# Use the same image we use for building docker images because it's cached.
# Otherwise this doesn't make any difference.
BASEIMAGENAME="python:3.11.3-slim"
TESTIMAGE="local/ichnaea_app"
# Start services in background (this is idempotent)
echo "Starting services needed by tests in the background..."
${DC} up -d db redis
# If we're running a shell, then we start up a test container with . mounted
# to /app.
if [ "$1" == "--shell" ]; then
echo "Running shell..."
docker run \
--rm \
--user "${ICHNAEA_UID}" \
--volume "$(pwd)":/app \
--workdir /app \
--network ichnaea_default \
--link ichnaea_db_1 \
--link ichnaea_redis_1 \
--env-file ./docker/config/local_dev.env \
--env-file ./docker/config/test.env \
--tty \
--interactive \
--entrypoint="" \
"${TESTIMAGE}" /bin/bash
exit $?
fi
# Create a data container to hold the repo directory contents and copy the
# contents into it--reuse if possible
if [ "$(docker container ls --all | grep ichnaea-repo)" == "" ]; then
echo "Creating ichnaea-repo container..."
docker create \
-v /app \
--user "${ICHNAEA_UID}" \
--name ichnaea-repo \
"${BASEIMAGENAME}" /bin/true
fi
echo "Copying contents..."
# Wipe whatever might be in there from past runs and verify files are gone
docker run \
--user root \
--volumes-from ichnaea-repo \
--workdir /app \
--entrypoint="" \
"${TESTIMAGE}" sh -c "rm -rf /app/* && ls -l /app/"
# Copy the repo root into /app
docker cp . ichnaea-repo:/app
# Fix file permissions in data container
docker run \
--user root \
--volumes-from ichnaea-repo \
--workdir /app \
--entrypoint="" \
"${TESTIMAGE}" chown -R "${ICHNAEA_UID}:${ICHNAEA_GID}" /app
# Check that database server is ready for tests
docker run \
--rm \
--user "${ICHNAEA_UID}" \
--volumes-from ichnaea-repo \
--workdir /app \
--network ichnaea_default \
--link ichnaea_db_1 \
--link ichnaea_redis_1 \
--env-file ./docker/config/local_dev.env \
--tty \
--interactive \
--entrypoint= \
"${TESTIMAGE}" /app/docker/run_check_db.sh
# Run tests in that environment and then remove the container
echo "Running tests..."
docker run \
--rm \
--user "${ICHNAEA_UID}" \
--volumes-from ichnaea-repo \
--workdir /app \
--network ichnaea_default \
--link ichnaea_db_1 \
--link ichnaea_redis_1 \
--env-file ./docker/config/local_dev.env \
--env-file ./docker/config/test.env \
--tty \
--interactive \
--entrypoint= \
"${TESTIMAGE}" /app/docker/run_tests.sh "$@"
echo "Done!"