/
run_tests_in_docker.sh
executable file
·105 lines (89 loc) · 3.16 KB
/
run_tests_in_docker.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
#!/bin/bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# 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="+ (run_tests_in_docker.sh): "
DC="$(which docker-compose)"
APP_UID="10001"
APP_GID="10001"
# Use the same image we use for building docker images because it'll be cached
# already
BASEIMAGENAME="python:2.7.13-slim"
# Start services in background (this is idempotent)
echo "Starting services in the background..."
${DC} up -d elasticsearch
${DC} up -d postgresql
${DC} up -d rabbitmq
# 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 "${APP_UID}" \
--volume "$(pwd)":/app \
--workdir /app \
--network socorro_default \
--link socorro_elasticsearch_1 \
--link socorro_postgresql_1 \
--link socorro_rabbitmq_1 \
--env-file ./docker/config/docker_common.env \
--env-file ./docker/config/test.env \
--tty \
--interactive \
local/socorro_webapp /bin/bash
else
# Create a data container to hold the repo directory contents and copy the
# contents into it
if [ "$(docker container ls --all | grep socorro-repo)" == "" ]; then
echo "Creating socorro-repo container..."
docker create \
-v /app \
--user "${APP_UID}" \
--name socorro-repo \
${BASEIMAGENAME} /bin/true
fi
echo "Copying contents..."
# Wipe whatever might be in there from past runs
docker run \
--user root \
--volumes-from socorro-repo \
--workdir /app \
local/socorro_webapp sh -c "rm -rf /app/*"
# Verify files are gone
docker run \
--user root \
--volumes-from socorro-repo \
--workdir /app \
local/socorro_webapp ls -l /app/
# Copy the repo root into /app
docker cp . socorro-repo:/app
# Fix permissions in data container
docker run \
--user root \
--volumes-from socorro-repo \
--workdir /app \
local/socorro_webapp chown -R "${APP_UID}:${APP_GID}" /app
# Run cmd in that environment and then remove the container
echo "Running tests..."
docker run \
--rm \
--user "${APP_UID}" \
--volumes-from socorro-repo \
--workdir /app \
--network socorro_default \
--link socorro_elasticsearch_1 \
--link socorro_postgresql_1 \
--link socorro_rabbitmq_1 \
--env-file ./docker/config/docker_common.env \
--env-file ./docker/config/test.env \
local/socorro_webapp /app/docker/run_tests.sh
echo "Done!"
fi