Skip to content

Commit

Permalink
update Elasticsearch container:
Browse files Browse the repository at this point in the history
-> add Dockerfile
-> Django container wait for Elasticsearch
  • Loading branch information
linuxluigi committed Dec 10, 2019
1 parent 40b4a87 commit 1072e61
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
31 changes: 30 additions & 1 deletion compose/production/django/entrypoint
Expand Up @@ -6,7 +6,7 @@ set -o nounset




# postgres
if [ -z "${POSTGRES_USER}" ]; then
base_postgres_image_default_user='postgres'
export POSTGRES_USER="${base_postgres_image_default_user}"
Expand Down Expand Up @@ -39,4 +39,33 @@ until postgres_ready; do
done
>&2 echo 'PostgreSQL is available'

# elasticsearch
elasticsearch_ready() {
python << END
import os
from requests.models import Response
import requests
import sys
elasticsearch_url: str = "http://{}:{}".format(os.environ["http.host"], os.environ["http.port"])
elasticsearch_health_url: str = "{}/_cluster/health?wait_for_status=yellow&timeout=50s".format(elasticsearch_url)
try:
response: Response = requests.get(elasticsearch_health_url)
except (ConnectionRefusedError, requests.exceptions.ConnectionError):
sys.exit(-1)
if response.status_code == 200:
sys.exit(0)
sys.exit(-1)
END
}
until elasticsearch_ready; do
>&2 echo 'Waiting for Elasticsearch to become available...'
sleep 1
done
>&2 echo 'Elasticsearch is available'


exec "$@"
1 change: 1 addition & 0 deletions compose/production/elasticsearch/Dockerfile
@@ -0,0 +1 @@
FROM elasticsearch:7.5.0
2 changes: 1 addition & 1 deletion config/settings/base.py
Expand Up @@ -248,7 +248,7 @@

# Wagtail
# ------------------------------------------------------------------------------
WAGTAIL_SITE_NAME = "Meetup Data Scraper"
WAGTAIL_SITE_NAME = "MeetupDataScraper"
WAGTAILAPI_LIMIT_MAX = 100

# https://docs.wagtail.io/en/v2.7/topics/search/backends.html#elasticsearch-backend
Expand Down
5 changes: 4 additions & 1 deletion local.yml
Expand Up @@ -36,7 +36,10 @@ services:
- ./.envs/.local/.postgres

elasticsearch:
image: elasticsearch:7.5.0
build:
context: .
dockerfile: ./compose/production/elasticsearch/Dockerfile
image: meetup_data_scraper_production_elasticsearch
volumes:
- local_elasticsearch_data:/usr/share/elasticsearch/data
env_file:
Expand Down
5 changes: 4 additions & 1 deletion production.yml
Expand Up @@ -50,7 +50,10 @@ services:
image: redis:5.0

elasticsearch:
image: elasticsearch:7.5.0
build:
context: .
dockerfile: ./compose/production/elasticsearch/Dockerfile
image: meetup_data_scraper_production_elasticsearch
volumes:
- production_elasticsearch_data:/usr/share/elasticsearch/data
env_file:
Expand Down

0 comments on commit 1072e61

Please sign in to comment.