Обновления в docker: entrypoint.sh и инструкции по развертыванию

This commit is contained in:
2026-01-08 22:16:39 +03:00
parent f94af70f7f
commit 4f57d594c9
2 changed files with 45 additions and 50 deletions

View File

@@ -148,32 +148,33 @@ run_migrations() {
python /app/docker/create_public_tenant.py
}
# Создание суперпользователя если не существует
create_superuser() {
echo "Creating superuser if not exists..."
# Создание PlatformAdmin если не существует
create_platform_admin() {
echo "Creating PlatformAdmin if not exists..."
python manage.py shell << EOF
from django.contrib.auth import get_user_model
from django.db import connection
from django_tenants.utils import schema_context
from platform_admin.models import PlatformAdmin
import os
User = get_user_model()
# Создаём PlatformAdmin из переменных окружения
email = os.environ.get('PLATFORM_ADMIN_EMAIL', 'admin@platform.com')
password = os.environ.get('PLATFORM_ADMIN_PASSWORD')
name = os.environ.get('PLATFORM_ADMIN_NAME', 'Platform Admin')
# Создаём суперпользователя в public схеме из переменных окружения
with schema_context('public'):
email = os.environ.get('TENANT_ADMIN_EMAIL', 'admin@example.com')
password = os.environ.get('TENANT_ADMIN_PASSWORD', 'changeme')
first_name = os.environ.get('TENANT_ADMIN_NAME', 'Admin')
if not User.objects.filter(email=email).exists():
user = User.objects.create_superuser(
if not password:
print('WARNING: PLATFORM_ADMIN_PASSWORD not set. Skipping PlatformAdmin creation.')
print('Create PlatformAdmin manually via Django shell:')
print(' from platform_admin.models import PlatformAdmin')
print(' PlatformAdmin.objects.create_superuser(email="...", name="...", password="...")')
else:
if not PlatformAdmin.objects.filter(email=email).exists():
admin = PlatformAdmin.objects.create_superuser(
email=email,
password=password,
name=first_name
name=name,
password=password
)
print(f'Superuser {email} created successfully!')
print(f'PlatformAdmin {email} created successfully!')
else:
print(f'Superuser {email} already exists.')
print(f'PlatformAdmin {email} already exists.')
EOF
}
@@ -199,7 +200,7 @@ case "$1" in
wait_for_redis
setup_directories
run_migrations
create_superuser
create_platform_admin
echo "Starting Gunicorn..."
exec gunicorn myproject.wsgi:application \
--bind 0.0.0.0:8000 \
@@ -228,7 +229,7 @@ case "$1" in
migrate)
wait_for_postgres
run_migrations
create_superuser
create_platform_admin
;;
collectstatic)
wait_for_postgres