moved db check to docker compose file

This commit is contained in:
Thomas Nahuel Rusiecki 2025-02-18 16:37:49 -03:00
parent 3c1681caa8
commit 2a36ce3ece
2 changed files with 18 additions and 20 deletions

View file

@ -15,13 +15,21 @@ services:
- DEMO_IDHUB_PREDEFINED_TOKEN=${IDHUB_PREDEFINED_TOKEN:-}
- PREDEFINED_TOKEN=${PREDEFINED_TOKEN:-}
- DPP=${DPP:-false}
- DB_PORT=${DB_PORT:-5432}
- DB_HOST=${DB_HOST:-devicehub-postgres}
- DB_NAME=${DB_NAME}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
# TODO manage volumes dev vs prod
volumes:
- .:/opt/devicehub-django
ports:
- ${DEVICEHUB_PORT:-8000}:${DEVICEHUB_PORT:-8000}
#https://docs.docker.com/compose/how-tos/startup-order/
depends_on:
- devicehub-postgres
devicehub-postgres:
condition: service_healthy
restart: true
devicehub-postgres:
image: postgres:17
@ -31,6 +39,13 @@ services:
- POSTGRES_PASSWORD=${DB_PASSWORD}
volumes:
- pg_data:/var/lib/postgresql/data
healthcheck:
# https://docs.docker.com/compose/how-tos/startup-order/
test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
start_period: 1s
interval: 1s
timeout: 10s
retries: 10
#ports:
# - ${DB_PORT}:${DB_PORT}

View file

@ -5,18 +5,6 @@ set -u
# DEBUG
set -x
program_dir='/opt/devicehub-django'
#source .env
. "${program_dir}/.env"
wait_for_postgres() {
# thanks https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-and-nginx/
while ! nc -z "$DB_HOST" "$DB_PORT" ; do
sleep 0.5
done
}
# TODO there is a conflict between two shared vars
# 1. from the original docker compose devicehub-teal
# 2. from the new docker compose that integrates all dpp services
@ -46,12 +34,6 @@ gen_env_vars() {
ADMIN='True'
PREDEFINED_TOKEN="${PREDEFINED_TOKEN:-}"
DB_NAME="${DB_NAME:-devicehub}"
DB_USER="${DB_USER:-ereuse}"
DB_PASSWORD="${DB_PASSWORD:-ereuse}"
DB_HOST="${DB_HOST:-localhost}"
DB_PORT="${DB_PORT:-5432}"
# specific dpp env vars
if [ "${DPP:-}" = 'true' ]; then
# fill env vars in this docker entrypoint
@ -260,9 +242,10 @@ runserver() {
}
main() {
program_dir='/opt/devicehub-django'
cd "${program_dir}"
gen_env_vars
wait_for_postgres
deploy
runserver
}