Skip to content

Instantly share code, notes, and snippets.

@austinkelleher
Last active May 16, 2018 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save austinkelleher/ae592eed024328bb738e3bef4dc0af4c to your computer and use it in GitHub Desktop.
Save austinkelleher/ae592eed024328bb738e3bef4dc0af4c to your computer and use it in GitHub Desktop.
version: '3'
services:
test:
image: node:8.10
environment:
- AWS_REGION=us-east-1
- AWS_ACCESS_KEY_ID=some-id
- AWS_SECRET_ACCESS_KEY=some-key
- ELASTIC_SEARCH_HOST=elasticsearch:9200
- WAIT_START_CMD=yarn jest
- WAIT_SLEEP=10
- WAIT_LOOPS=6
depends_on:
- elasticsearch
volumes:
- ../:/opt/work
working_dir: /opt/work
command: ./tools/bin/wait_for_elasticsearch_ready
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4
...
Waiting for Elasticsearch in Docker to become ready...
Elasticsearch status code: 000
Elasticsearch is not ready yet...
Tue May 15 19:50:48 UTC 2018 - waiting to be ready
Elasticsearch status code: 000
Elasticsearch is not ready yet...
Tue May 15 19:50:58 UTC 2018 - waiting to be ready
Elasticsearch status code: 000
Elasticsearch is not ready yet...
Tue May 15 19:51:08 UTC 2018 - waiting to be ready
Elasticsearch status code: 000
Elasticsearch is not ready yet...
Tue May 15 19:51:18 UTC 2018 - waiting to be ready
Elasticsearch status code: 000
Elasticsearch is not ready yet...
Tue May 15 19:51:28 UTC 2018 - waiting to be ready
Elasticsearch status code: 000
Elasticsearch is not ready yet...
Tue May 15 19:51:38 UTC 2018 - still not ready, giving up
...
#!/bin/bash
PROJECT_NAME="some-project"
docker-compose --log-level DEBUG -p ${PROJECT_NAME} run test
EXIT_CODE=${?}
docker-compose -p ${PROJECT_NAME} down
exit ${EXIT_CODE}
#!/bin/bash
echo "Waiting for Elasticsearch in Docker to become ready..."
URL=http://elasticsearch:9200/_cat/health?h=st
is_ready() {
STATUS_CODE=$(curl --write-out %{http_code} --silent --output /dev/null $URL)
echo "Elasticsearch status code: $STATUS_CODE"
if [ $STATUS_CODE -eq "200" ]; then
echo "Elasticsearch is ready!"
return 0
else
echo "Elasticsearch is not ready yet..."
return 1
fi
}
i=0
while ! is_ready; do
i=`expr $i + 1`
if [ $i -ge $WAIT_LOOPS ]; then
echo "$(date) - still not ready, giving up"
exit 1
fi
echo "$(date) - waiting to be ready"
sleep $WAIT_SLEEP
done
exec $WAIT_START_CMD
@austinkelleher
Copy link
Author

I was able to solve the connection issue by adding environment: ['transport.host=127.0.0.1'] to the elasticsearch service:

version: '3'

services:
  test:
    image: node:8.10
    environment:
      - AWS_REGION=us-east-1
      - AWS_ACCESS_KEY_ID=some-id
      - AWS_SECRET_ACCESS_KEY=some-key
      - ELASTIC_SEARCH_HOST=elasticsearch:9200
      - WAIT_START_CMD=yarn jest
      - WAIT_SLEEP=10
      - WAIT_LOOPS=6
    depends_on:
      - elasticsearch
    volumes:
      - ../:/opt/work
    working_dir: /opt/work
    command: ./tools/bin/wait_for_elasticsearch_ready
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4
    environment: ['transport.host=127.0.0.1']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment