Merge pull request #1314 from openbrian/docker-compose-app-depends-on-db

Replace wait_for_database with depends_on and healthcheck.
This commit is contained in:
Yohan Boniface 2023-09-21 10:11:56 +02:00 committed by GitHub
commit 5b7fec5f9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 17 deletions

View file

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

View file

@ -3,24 +3,8 @@ set -eo pipefail
source /venv/bin/activate 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 # first wait for the database
wait_for_database umap wait_for_database
# then migrate the database # then migrate the database
umap migrate umap migrate
# then collect static files # then collect static files

View file

@ -36,6 +36,7 @@ dependencies = [
"django-agnocomplete==2.2.0", "django-agnocomplete==2.2.0",
"django-compressor==4.3.1", "django-compressor==4.3.1",
"django-environ==0.10.0", "django-environ==0.10.0",
"django-probes==1.7.0",
"Pillow==9.5.0", "Pillow==9.5.0",
"psycopg2==2.9.6", "psycopg2==2.9.6",
"requests==2.31.0", "requests==2.31.0",

View file

@ -117,6 +117,7 @@ INSTALLED_APPS = (
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.gis', 'django.contrib.gis',
'django_probes',
'umap', 'umap',
'compressor', 'compressor',
'social_django', 'social_django',