From 9eaaadc0f2cefbe153fb77d8ddca0234e152ce1a Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Mon, 26 May 2025 17:36:22 -0400 Subject: [PATCH] Enhance entrypoint script with a helper function for environment variable retrieval; improve PostgreSQL connection logic. Update installer script to add spacing for readability in service wait function. --- backend/entrypoint.sh | 26 ++++++++++++++++++++++++-- install_adventurelog.sh | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/backend/entrypoint.sh b/backend/entrypoint.sh index 06adc3c..1031cb1 100644 --- a/backend/entrypoint.sh +++ b/backend/entrypoint.sh @@ -1,10 +1,32 @@ #!/bin/bash # Function to check PostgreSQL availability -check_postgres() { - PGPASSWORD=$PGPASSWORD psql -h "$PGHOST" -U "$PGUSER" -d "$PGDATABASE" -c '\q' >/dev/null 2>&1 +# Helper to get the first non-empty environment variable +get_env() { + for var in "$@"; do + value="${!var}" + if [ -n "$value" ]; then + echo "$value" + return + fi + done } +check_postgres() { + local db_host + local db_user + local db_name + local db_pass + + db_host=$(get_env PGHOST) + db_user=$(get_env PGUSER POSTGRES_USER) + db_name=$(get_env PGDATABASE POSTGRES_DB) + db_pass=$(get_env PGPASSWORD POSTGRES_PASSWORD) + + PGPASSWORD="$db_pass" psql -h "$db_host" -U "$db_user" -d "$db_name" -c '\q' >/dev/null 2>&1 +} + + # Wait for PostgreSQL to become available until check_postgres; do >&2 echo "PostgreSQL is unavailable - sleeping" diff --git a/install_adventurelog.sh b/install_adventurelog.sh index a629028..1d5890f 100755 --- a/install_adventurelog.sh +++ b/install_adventurelog.sh @@ -484,6 +484,7 @@ wait_for_services() { local max_attempts=30 local attempt=1 + while [ $attempt -le $max_attempts ]; do if curl -s -o /dev/null -w "%{http_code}" "$FRONTEND_ORIGIN" | grep -q "200\|404\|302"; then log_success "Frontend is responding"