-
Notifications
You must be signed in to change notification settings - Fork 38
/
test-with-docker.sh
executable file
·64 lines (58 loc) · 1.64 KB
/
test-with-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
#!/bin/bash
if [ -n "$DOCKER_HOST" ]; then
DOCKER_HOST_IP=$(echo $DOCKER_HOST | sed 's/^.*\/\/\(.*\):[0-9][0-9]*$/\1/g')
else
DOCKER_HOST_IP="127.0.0.1"
fi
# Redis
echo
echo "# Running redis..."
export COTOAMI_REDIS_HOST=$DOCKER_HOST_IP
export COTOAMI_REDIS_PORT=16379
export DOCKER_REDIS_ID=$(docker run -d -p $COTOAMI_REDIS_PORT:6379 redis:alpine)
# PostgreSQL
echo
echo "# Running postgres..."
export COTOAMI_TEST_REPO_HOST=$DOCKER_HOST_IP
export COTOAMI_TEST_REPO_PORT=15432
export DOCKER_POSTGRES_ID=$(docker run -d \
-p $COTOAMI_TEST_REPO_PORT:5432 \
-e POSTGRES_PASSWORD=postgres \
postgres:9.5-alpine)
echo " waiting for postgres to be launched..."
while ! nc -z $DOCKER_HOST_IP $COTOAMI_TEST_REPO_PORT; do
sleep 1s
done
# Neo4j
echo
echo "# Running neo4j..."
NEO4J_VERSION=3.2.2
export COTOAMI_NEO4J_HOST=$DOCKER_HOST_IP
export COTOAMI_NEO4J_PORT=17687
export DOCKER_NEO4J_ID=$(docker run -d \
-p $COTOAMI_NEO4J_PORT:7687 \
-e NEO4J_AUTH=none \
neo4j:$NEO4J_VERSION)
echo " waiting for neo4j to be launched..."
while ! nc -z $DOCKER_HOST_IP $COTOAMI_NEO4J_PORT; do
sleep 1s
done
# Make sure to tear down the backend containers
function tear_down_containers() {
echo
echo "# Tearing down containers..."
docker stop $DOCKER_REDIS_ID && docker rm $DOCKER_REDIS_ID
docker stop $DOCKER_POSTGRES_ID && docker rm $DOCKER_POSTGRES_ID
docker stop $DOCKER_NEO4J_ID && docker rm $DOCKER_NEO4J_ID
}
trap tear_down_containers 0 1 2 3 15
# Run tests
echo
echo "# Running tests..."
export MIX_ENV="test"
if [[ $* == *-s* ]]; then
echo "skip getting dependencies..."
mix do compile, test
else
mix do deps.get, deps.compile, compile, test
fi