Files
IoT_PreTester_V46_Demo/docker/entrypoint-backend.sh
T
2026-08-19 08:04:59 +02:00

46 lines
1.3 KiB
Bash

#!/bin/sh
set -eu
echo "Starting IoT PreTester 4.6 Demo backend"
mkdir -p /app/data /app/files/uploads /app/logs /app/django_project/staticfiles
cd /app/django_project
python manage.py migrate --noinput
python manage.py collectstatic --noinput
# Keep the configured demo administrator reproducible across container restarts.
python manage.py shell <<'PY'
import os
from django.contrib.auth import get_user_model
from django.utils.timezone import now
User = get_user_model()
username = os.environ.get("DJANGO_SUPERUSER_USERNAME", "admin")
email = os.environ.get("DJANGO_SUPERUSER_EMAIL", "admin@example.com")
password = os.environ["DJANGO_SUPERUSER_PASSWORD"]
user, created = User.objects.get_or_create(username=username, defaults={"email": email})
user.email = email
user.is_superuser = True
user.is_staff = True
user.is_active = True
user.set_password(password)
user.last_login = now()
user.save()
print("Demo administrator created" if created else "Demo administrator synchronized")
PY
if [ "${INIT_DATABASE:-true}" = "true" ]; then
python create_models.py
fi
exec gunicorn IoTPreTester.wsgi:application \
--bind 0.0.0.0:8000 \
--workers "${GUNICORN_WORKERS:-4}" \
--timeout "${GUNICORN_TIMEOUT:-120}" \
--access-logfile /app/logs/access.log \
--error-logfile /app/logs/error.log \
--log-level "${LOG_LEVEL:-info}"