-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·61 lines (51 loc) · 1.74 KB
/
test
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
#!/usr/bin/env bash
set -ex
NAME_NETWORK=hintr_network
NAME_LOADBALANCER=hintr_loadbalancer
NAME_REDIS=hintr_redis
NAME_HINTR=hintr
function cleanup {
echo "Cleaning up"
docker kill $NAME_REDIS >/dev/null || true
docker kill $NAME_HINTR >/dev/null || true
docker kill $NAME_LOADBALANCER >/dev/null || true
docker network rm $NAME_NETWORK >/dev/null || true
}
trap cleanup EXIT
docker network create $NAME_NETWORK
docker run --rm -d --network=$NAME_NETWORK --network-alias=redis \
--name $NAME_REDIS redis
docker run --rm -d --network=$NAME_NETWORK \
-e REDIS_URL=redis://redis:6379 \
--name $NAME_HINTR \
mrcide/hintr:master
docker run --rm -d --network=$NAME_NETWORK \
-p 8888:8888 \
--name $NAME_LOADBALANCER \
"$TAG_BRANCH"
## Data API is running
sleep 2
docker exec $NAME_LOADBALANCER configure_backend -p 8888 --address $NAME_HINTR
## curl command will error with message
## curl: (56) Recv failure: Connection reset by peer
## if you try to get status before server is ready to
## accept connections. Ideally we would use curl --retry-all-errors
## but this only available in 7.71.0 which is not available
## in standard ubuntu package sources yet
function retry() {
local -r -i max_attempts="$1"
shift
local -i attempt_num=1
until [[ $($@) == '{"status":"success","errors":null,"data":"Welcome to hintr"}' ]]; do
if ((attempt_num == max_attempts)); then
echo "Attempt $attempt_num failed and there are no more attempts left!"
return 1
else
echo "Attempt $attempt_num failed! Trying again in $attempt_num seconds..."
sleep $((attempt_num++))
fi
done
echo "SUCCESS"
exit 0
}
retry 10 curl --silent http://localhost:8888