update dockerfile
This commit is contained in:
parent
c1eea39519
commit
279c717fdd
@ -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"]
|
||||
@ -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...'))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user