diff --git a/compose/production/django/entrypoint b/compose/production/django/entrypoint index 929744d..97cb174 100644 --- a/compose/production/django/entrypoint +++ b/compose/production/django/entrypoint @@ -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}" @@ -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 "$@" diff --git a/compose/production/elasticsearch/Dockerfile b/compose/production/elasticsearch/Dockerfile new file mode 100644 index 0000000..9c7523d --- /dev/null +++ b/compose/production/elasticsearch/Dockerfile @@ -0,0 +1 @@ +FROM elasticsearch:7.5.0 \ No newline at end of file diff --git a/config/settings/base.py b/config/settings/base.py index 1e8ee3a..e8089b6 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -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 diff --git a/local.yml b/local.yml index 89577a4..96b84cd 100644 --- a/local.yml +++ b/local.yml @@ -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: diff --git a/production.yml b/production.yml index 02240fb..a0059f1 100644 --- a/production.yml +++ b/production.yml @@ -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: