-
Notifications
You must be signed in to change notification settings - Fork 743
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update elasticsearch docker setup to use docker-compose
- Loading branch information
Showing
5 changed files
with
26 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
SCRIPT_DIR=$(dirname "$(realpath "$0")") | ||
|
||
# Create the Elasticsearch cluster and get the container id | ||
docker run -d --rm -p 9200:9200 -p 9300:9300 -e "xpack.security.enabled=false" -e "discovery.type=single-node" --name es-test docker.elastic.co/elasticsearch/elasticsearch:8.7.0 | ||
|
||
# Wait for Elasticsearch container to start | ||
echo "Waiting for Elasticsearch container to start..." | ||
sleep 1 | ||
|
||
url="http://localhost:9200/_cluster/health?wait_for_status=green&timeout=50s" | ||
status_code=0 | ||
retry_count=0 | ||
max_retries=6 | ||
|
||
# Check the cluster status repeatedly until it becomes live or maximum retries are reached | ||
while [ "$status_code" -ne 200 ] && [ "$retry_count" -lt "$max_retries" ]; do | ||
# Send a GET request to the cluster health API | ||
response=$(curl -s -o /dev/null -w "%{http_code}" "$url") | ||
status_code="$response" | ||
docker-compose -f "$SCRIPT_DIR"/docker-compose.yaml up --wait | ||
docker-compose -f "$SCRIPT_DIR"/docker-compose.yaml ps | ||
|
||
# Process the files only when the Elasticsearch cluster is live | ||
if [ "$status_code" -eq 200 ]; then | ||
echo "Cluster is live." | ||
python "$SCRIPT_DIR/create_and_fill_es.py" | ||
else | ||
((retry_count++)) | ||
echo "Cluster is not available. Retrying in 5 seconds... (Attempt $retry_count)" | ||
sleep 5 | ||
fi | ||
done | ||
|
||
# If the cluster has not become live, exit after a certain number of tries | ||
if [ "$status_code" -ne 200 ]; then | ||
echo "Cluster took an unusually long time to create (>25 seconds). Expected time is around 10 seconds. Exiting." | ||
fi | ||
echo "Cluster is live." | ||
"$SCRIPT_DIR"/create_and_fill_es.py |
2 changes: 2 additions & 0 deletions
2
scripts/elasticsearch-test-helpers/create_and_fill_es.py
100644 → 100755
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
services: | ||
elasticsearch: | ||
image: docker.elastic.co/elasticsearch/elasticsearch:8.7.0 | ||
container_name: es-test | ||
ports: | ||
- 9200:9200 | ||
- 9300:9300 | ||
environment: | ||
- xpack.security.enabled=false | ||
- discovery.type=single-node | ||
healthcheck: | ||
test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"] | ||
interval: 30s | ||
timeout: 30s | ||
retries: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters