Skip to content

Commit 0294d39

Browse files
committed
Use docker-compose exec when waiting for Elasticsearch
1 parent 9b69ff2 commit 0294d39

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
- run:
4848
command: |
4949
pushd metacpan-docker/src/metacpan-api
50-
./wait-for-es.sh http://localhost:9200
50+
./wait-for-es.sh elasticsearch_test http://localhost:9200
5151
name: wait for ES
5252
- run:
5353
command: |

wait-for-es.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55

66
set -ux
77

8-
host="$1"
8+
container="$1"
9+
host="$2"
10+
11+
preamble="docker-compose exec $container"
912

1013
while true; do
11-
response=$(curl --write-out '%{http_code}' --silent --fail --output /dev/null "$host")
14+
response=$($preamble curl --write-out '%{http_code}' --silent --fail --output /dev/null "$host")
1215
if [[ "$response" -eq "200" ]]; then
1316
break
1417
fi
@@ -24,15 +27,13 @@ set -e
2427
while true; do
2528
## Wait for ES status to turn to yellow.
2629
## TODO: Ideally we'd be waiting for green, but we need multiple nodes for that.
27-
health="$(curl -fsSL "$host/_cat/health?h=status")"
28-
health="$(echo "$health" | xargs)" # trim whitespace (otherwise we'll have "green ")
29-
if [[ $health == 'yellow' || $health == 'green' ]]; then
30+
health=$($preamble curl -fsSL "$host/_cat/health?format=JSON" | jq '.[0].status == "yellow" or .[0].status == "green"')
31+
if [[ $health == 'true' ]]; then
3032
break
3133
fi
3234
echo "Elastic Search is unavailable ($health) - sleeping" >&2
3335
sleep 1
3436
done
3537

3638
echo "Elastic Search is up" >&2
37-
shift
38-
exec "$@"
39+
exit 0

0 commit comments

Comments
 (0)