From 279c717fdd4d31b3e478b424854d509a8abeeed5 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Thu, 29 Jan 2026 17:42:36 +0000 Subject: [PATCH] update dockerfile --- Dockerfile | 5 +++-- core/management/commands/wait_for_db.py | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9af1520..accc30d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,10 +10,12 @@ WORKDIR /app # Install system dependencies # WeasyPrint needs: libpango-1.0-0 libpangoft2-1.0-0 libharfbuzz-subset0 libjpeg-dev libopenjp2-7-dev libxcb1 # MySQLclient needs: default-libmysqlclient-dev gcc pkg-config +# MariaDB Client is added to ensure all authentication plugins (like mysql_native_password) are available for MariaDB 11 RUN apt-get update && apt-get install -y \ gcc \ pkg-config \ default-libmysqlclient-dev \ + mariadb-client \ libpango-1.0-0 \ libpangoft2-1.0-0 \ libharfbuzz-subset0 \ @@ -38,5 +40,4 @@ RUN chmod +x /app/entrypoint.sh EXPOSE 8000 # Entrypoint -ENTRYPOINT ["/app/entrypoint.sh"] - +ENTRYPOINT ["/app/entrypoint.sh"] \ No newline at end of file diff --git a/core/management/commands/wait_for_db.py b/core/management/commands/wait_for_db.py index f0747a8..cee1a06 100644 --- a/core/management/commands/wait_for_db.py +++ b/core/management/commands/wait_for_db.py @@ -2,7 +2,7 @@ import time from django.db import connections from django.db.utils import OperationalError from django.core.management.base import BaseCommand - +from django.conf import settings class Command(BaseCommand): """Django command to pause execution until database is available""" @@ -12,6 +12,10 @@ class Command(BaseCommand): requires_system_checks = [] def handle(self, *args, **options): + # Print the connection details (masked password) for debugging + db_conf = settings.DATABASES['default'] + self.stdout.write(f"Debug Info - Host: {db_conf.get('HOST')}, Port: {db_conf.get('PORT')}, Name: {db_conf.get('NAME')}, User: {db_conf.get('USER')}") + self.stdout.write('Waiting for database...') db_conn = None for i in range(30): # Retry for 30 seconds @@ -22,7 +26,16 @@ class Command(BaseCommand): self.stdout.write(self.style.SUCCESS('Database available!')) return except OperationalError as e: - self.stdout.write(f'Database unavailable ({e}), waiting 1 second...') + # Check for specific "Unknown database" error (MySQL code 1049) + error_str = str(e) + if "1049" in error_str or "Unknown database" in error_str: + self.stdout.write(self.style.ERROR(f"CRITICAL ERROR: The database '{db_conf.get('NAME')}' does not exist on the server.")) + self.stdout.write(self.style.ERROR("Solution: Check your DB_NAME environment variable. It usually defaults to 'default' or the service name.")) + # Fail immediately for this specific error as it won't resolve itself + return + + # Print the full error message + self.stdout.write(f'Database unavailable (Error: {e}), waiting 1 second...') time.sleep(1) except Exception as e: self.stdout.write(self.style.WARNING(f'Database error: {e}, waiting 1 second...'))