diff --git a/api/Dockerfile b/api/Dockerfile index eac955cea..c1a50ed34 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -6,7 +6,7 @@ # https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact ARG PHP_VERSION=8.1 ARG CADDY_VERSION=2.6.4 -ARG OPENSEARCH2_VERSION=2.11.0 +ARG OPENSEARCH2_VERSION=2.13.0 ARG ELASTIC7_VERSION=7.16.3 ARG ELASTIC8_VERSION=8.10.4 # ARG XDEBUG_VERSION=3.1.2 diff --git a/api/docker/php/docker-entrypoint.sh b/api/docker/php/docker-entrypoint.sh index eca2f52bb..4c6768733 100755 --- a/api/docker/php/docker-entrypoint.sh +++ b/api/docker/php/docker-entrypoint.sh @@ -50,6 +50,33 @@ if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then php bin/console doctrine:migrations:migrate --no-interaction fi + + if grep -q ELASTICSEARCH_URL= .env; then + echo "Waiting for search engine to be ready..." + ATTEMPTS_LEFT_TO_REACH_SEARCH=60 + export $(grep 'ELASTICSEARCH_URL=' .env | xargs) + until [ $ ATTEMPTS_LEFT_TO_REACH_SEARCH -eq 0 ] || SEARCH_ERROR=$(curl -s ${ELASTICSEARCH_URL}); do + sleep 1 + ATTEMPTS_LEFT_TO_REACH_SEARCH=$((ATTEMPTS_LEFT_TO_REACH_SEARCH - 1)) + echo "Still waiting for search engine to be ready... Or maybe the search engine is not reachable. $ATTEMPTS_LEFT_TO_REACH_SEARCH attempts left." + done + + if [ $ATTEMPTS_LEFT_TO_REACH_SEARCH -eq 0 ]; then + echo "The search engine is not up or not reachable:" + echo "$SEARCH_ERROR" + exit 1 + else + echo "The search engine is now reachable" + fi + + curl -s "${ELASTICSEARCH_URL}_cluster/health?wait_for_status=green&timeout=30s" + echo "The search engine is now ready" + + if php bin/console list gally --raw | grep -q gally:vector-search:upload-model; then + echo "Load ml model in opensearch" + php bin/console gally:vector-search:upload-model + fi + fi fi exec docker-php-entrypoint "$@"