feat: change env settings and create superuser script
This commit is contained in:
+12
-7
@@ -1,12 +1,17 @@
|
||||
DJANGO_SETTINGS_MODULE=config.settings.development
|
||||
DJANGO_SECRET_KEY=django-insecure-replace-this-with-a-real-secret-key-in-production
|
||||
DEBUG=True
|
||||
ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0
|
||||
DJANGO_SETTINGS_MODULE=config.settings.production
|
||||
DJANGO_SECRET_KEY=uqgb2wi9@1dr8alhhx$rp_tx!%_en$k7w6yjbu7wz-qr3$&3-w
|
||||
DEBUG=False
|
||||
ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0,radiuma.com,www.radiuma.com
|
||||
CSRF_TRUSTED_ORIGINS=localhost,127.0.0.1,0.0.0.0,radiuma.com,www.radiuma.com
|
||||
|
||||
POSTGRES_DB=tecvico
|
||||
POSTGRES_USER=tecvico_user
|
||||
POSTGRES_PASSWORD=tecvico_password
|
||||
POSTGRES_DB=radiuma
|
||||
POSTGRES_USER=radiuma_user
|
||||
POSTGRES_PASSWORD=eS4_WYJH97gywyoHjP6v
|
||||
POSTGRES_HOST=db
|
||||
POSTGRES_PORT=5432
|
||||
|
||||
SECURE_SSL_REDIRECT=False
|
||||
|
||||
DJANGO_SUPERUSER_USERNAME=admin
|
||||
DJANGO_SUPERUSER_EMAIL=admin@yourdomain.com
|
||||
DJANGO_SUPERUSER_PASSWORD=bS7_U_uRTmivj7W-lCR5
|
||||
|
||||
@@ -20,8 +20,6 @@ RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN python manage.py collectstatic --noinput
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import os
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Create a superuser from environment variables if one does not already exist."
|
||||
|
||||
def handle(self, *args, **options):
|
||||
User = get_user_model()
|
||||
|
||||
username = os.environ.get("DJANGO_SUPERUSER_USERNAME", "admin")
|
||||
email = os.environ.get("DJANGO_SUPERUSER_EMAIL", "admin@radiuma.com")
|
||||
password = os.environ.get("DJANGO_SUPERUSER_PASSWORD")
|
||||
|
||||
if not password:
|
||||
self.stdout.write(
|
||||
self.style.WARNING(
|
||||
"DJANGO_SUPERUSER_PASSWORD is not set — skipping superuser creation."
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
if User.objects.filter(username=username).exists():
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f"Superuser '{username}' already exists — skipping.")
|
||||
)
|
||||
return
|
||||
|
||||
User.objects.create_superuser(username=username, email=email, password=password)
|
||||
self.stdout.write(self.style.SUCCESS(f"Superuser '{username}' created successfully."))
|
||||
+2
-2
@@ -27,11 +27,11 @@ services:
|
||||
DJANGO_SETTINGS_MODULE: config.settings.production
|
||||
POSTGRES_HOST: db
|
||||
volumes:
|
||||
- media_data:/app/media
|
||||
- ./media:/app/media
|
||||
- ./staticfiles:/app/staticfiles
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
media_data:
|
||||
|
||||
@@ -22,8 +22,14 @@ done
|
||||
|
||||
echo "PostgreSQL is ready."
|
||||
|
||||
echo "Collecting static files..."
|
||||
python manage.py collectstatic --noinput
|
||||
|
||||
echo "Running database migrations..."
|
||||
python manage.py migrate --noinput
|
||||
|
||||
echo "Creating superuser if not exists..."
|
||||
python manage.py ensure_superuser
|
||||
|
||||
echo "Starting application..."
|
||||
exec "$@"
|
||||
|
||||
Reference in New Issue
Block a user