Replace wait_for_database with depends_on and healthcheck.

This commit is contained in:
Brian DeRocher 2023-09-16 11:12:50 -04:00
parent 0a83c42724
commit 0c9d9f630e
2 changed files with 6 additions and 18 deletions

View file

@ -3,6 +3,9 @@ version: '3'
services:
db:
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 2s
image: postgis/postgis:14-3.3-alpine
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
@ -10,6 +13,9 @@ services:
- db:/var/lib/postgresql/data
app:
depends_on:
db:
condition: service_healthy
image: umap/umap:1.3.2
ports:
- "${PORT-8000}:8000"

View file

@ -3,24 +3,6 @@ set -eo pipefail
source /venv/bin/activate
# default variables
: "${SLEEP:=1}"
: "${TRIES:=60}"
function wait_for_database {(
echo "Waiting for database to respond..."
tries=0
while true; do
[[ $tries -lt $TRIES ]] || return
(echo "from django.db import connection; connection.connect()" | umap shell) >/dev/null
[[ $? -eq 0 ]] && return
sleep $SLEEP
tries=$((tries + 1))
done
)}
# first wait for the database
wait_for_database
# then migrate the database
umap migrate
# then collect static files