1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-21 05:49:37 +02:00
AdventureLog/backend/entrypoint.sh

38 lines
1 KiB
Bash
Raw Normal View History

2024-07-08 11:44:39 -04:00
#!/bin/bash
# Function to check PostgreSQL availability
check_postgres() {
PGPASSWORD=$PGPASSWORD psql -h "$PGHOST" -U "$PGUSER" -d "$PGDATABASE" -c '\q' >/dev/null 2>&1
}
# Wait for PostgreSQL to become available
until check_postgres; do
>&2 echo "PostgreSQL is unavailable - sleeping"
sleep 1
done
>&2 echo "PostgreSQL is up - continuing..."
# Apply Django migrations
python manage.py migrate
# Check for default data
python manage.py worldtravel-seed
# Create superuser if environment variables are set and there are no users present at all.
2024-07-08 11:44:39 -04:00
if [ -n "$DJANGO_ADMIN_USERNAME" ] && [ -n "$DJANGO_ADMIN_PASSWORD" ]; then
echo "Creating superuser..."
python manage.py shell << EOF
from django.contrib.auth import get_user_model
User = get_user_model()
if User.objects.count() == 0:
2024-07-08 11:44:39 -04:00
User.objects.create_superuser('$DJANGO_ADMIN_USERNAME', '$DJANGO_ADMIN_EMAIL', '$DJANGO_ADMIN_PASSWORD')
print("Superuser created successfully.")
else:
print("Superuser already exists.")
EOF
fi
# Start Django server
python manage.py runserver 0.0.0.0:8000