bramw_baserow/e2e-tests/wait-for-services.sh

45 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -Eeo pipefail
# This script waits 60 seconds by default for the backend and web-frontend services
# to become healthy.
# Keep in sync with src/baserow/config/settings/base.py:594
DEFAULT_APPLICATION_TEMPLATE="Project Tracker"
baserow_ready() {
curlf() {
HTTP_CODE=$(curl --silent -o /dev/null --write-out "%{http_code}" --max-time 10 "$@")
if [[ ${HTTP_CODE} -lt 200 || ${HTTP_CODE} -gt 299 ]] ; then
return 22
fi
return 0
}
templates_ready(){
TEMPLATES_JSON=$(curl --silent --max-time 10 "${PUBLIC_BACKEND_URL:-http://backend:8000}/api/templates/")
if [[ ${TEMPLATES_JSON} == *"$DEFAULT_APPLICATION_TEMPLATE"* ]] ; then
return 0
fi
return 22
}
if curlf "${PUBLIC_WEB_FRONTEND_URL:-http://web-frontend:3000}/_health/" && curlf "${PUBLIC_BACKEND_URL:-http://backend:8000}/api/_health/" && templates_ready; then
return 0
else
return 1
fi
}
for _ in $(seq 1 "${BASEROW_E2E_STARTUP_MAX_WAIT_TIME_SECONDS:-60}")
do
echo 'Waiting for backend, web-frontend and synced templates to be ready'
if baserow_ready; then
echo 'Baserow is ready! Exiting with success code.'
exit 0
fi
sleep 1
done
echo 'E2E services failed to startup in time, crashing the test.'
exit 1