editing deployment
This commit is contained in:
parent
04fa45e5f8
commit
212e4e71cc
31
core/management/commands/wait_for_db.py
Normal file
31
core/management/commands/wait_for_db.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import time
|
||||||
|
from django.db import connections
|
||||||
|
from django.db.utils import OperationalError
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
"""Django command to pause execution until database is available"""
|
||||||
|
|
||||||
|
# Critical: Disable system checks to prevent the command from crashing
|
||||||
|
# if the database is not yet available.
|
||||||
|
requires_system_checks = []
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
self.stdout.write('Waiting for database...')
|
||||||
|
db_conn = None
|
||||||
|
for i in range(30): # Retry for 30 seconds
|
||||||
|
try:
|
||||||
|
db_conn = connections['default']
|
||||||
|
# Try to actually connect
|
||||||
|
db_conn.cursor()
|
||||||
|
self.stdout.write(self.style.SUCCESS('Database available!'))
|
||||||
|
return
|
||||||
|
except OperationalError:
|
||||||
|
self.stdout.write('Database unavailable, waiting 1 second...')
|
||||||
|
time.sleep(1)
|
||||||
|
except Exception as e:
|
||||||
|
self.stdout.write(self.style.WARNING(f'Database error: {e}, waiting 1 second...'))
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
self.stdout.write(self.style.ERROR('Database unavailable after 30 seconds.'))
|
||||||
13
entrypoint.sh
Normal file → Executable file
13
entrypoint.sh
Normal file → Executable file
@ -3,6 +3,19 @@
|
|||||||
# Exit immediately if a command exits with a non-zero status
|
# Exit immediately if a command exits with a non-zero status
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
echo "Starting deployment script..."
|
||||||
|
echo "Environment Verification:"
|
||||||
|
echo "DB_ENGINE: ${DB_ENGINE:-'Not Set (will default to settings.py)'}"
|
||||||
|
echo "DB_HOST: ${DB_HOST:-'Not Set'}"
|
||||||
|
echo "DB_PORT: ${DB_PORT:-'Not Set'}"
|
||||||
|
echo "DB_NAME: ${DB_NAME:-'Not Set'}"
|
||||||
|
echo "DB_USER: ${DB_USER:-'Not Set'}"
|
||||||
|
# Do NOT print DB_PASS
|
||||||
|
|
||||||
|
# Wait for database to be ready
|
||||||
|
echo "Checking database connection..."
|
||||||
|
python manage.py wait_for_db
|
||||||
|
|
||||||
# Apply database migrations
|
# Apply database migrations
|
||||||
echo "Applying database migrations..."
|
echo "Applying database migrations..."
|
||||||
python manage.py migrate
|
python manage.py migrate
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user