- Add token-based admin login/logout/me endpoints - Bootstrap admin from ADMIN_USERNAME/ADMIN_PASSWORD in Docker entrypoint - Read ALLOWED_HOSTS and CORS from env only (no hardcoded server IPs) - Keep docs/Postman/tests free of real credentials - Cover login and auth flows with 31 local API tests Co-authored-by: Cursor <cursoragent@cursor.com>
48 lines
1.3 KiB
Bash
48 lines
1.3 KiB
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
DB_HOST="${POSTGRES_HOST:-db}"
|
|
DB_USER="${POSTGRES_USER:-postgres}"
|
|
DB_NAME="${POSTGRES_DB:-Zoneco_ORG}"
|
|
|
|
echo "Waiting for PostgreSQL to be ready at ${DB_HOST}..."
|
|
while ! pg_isready -h "${DB_HOST}" -U "${DB_USER}" -d "${DB_NAME}"; do
|
|
echo "PostgreSQL is unavailable - sleeping"
|
|
sleep 1
|
|
done
|
|
|
|
echo "PostgreSQL is up"
|
|
|
|
echo "Collecting static files..."
|
|
python manage.py collectstatic --noinput
|
|
|
|
echo "Running migrations..."
|
|
python manage.py migrate --noinput
|
|
|
|
# Create/update admin from environment variables (no hardcoded credentials).
|
|
# Set ADMIN_USERNAME and ADMIN_PASSWORD in the server .env / compose env.
|
|
if [ -n "${ADMIN_USERNAME:-}" ] && [ -n "${ADMIN_PASSWORD:-}" ]; then
|
|
echo "Ensuring admin user from environment variables..."
|
|
python manage.py shell <<EOF
|
|
from django.contrib.auth import get_user_model
|
|
User = get_user_model()
|
|
username = "${ADMIN_USERNAME}"
|
|
password = "${ADMIN_PASSWORD}"
|
|
user, created = User.objects.get_or_create(
|
|
username=username,
|
|
defaults={"is_staff": True, "is_superuser": True, "is_active": True},
|
|
)
|
|
user.is_staff = True
|
|
user.is_superuser = True
|
|
user.is_active = True
|
|
user.set_password(password)
|
|
user.save()
|
|
print("Admin user CREATED" if created else "Admin user UPDATED")
|
|
EOF
|
|
else
|
|
echo "ADMIN_USERNAME/ADMIN_PASSWORD not set — skipping admin bootstrap"
|
|
fi
|
|
|
|
echo "Starting application..."
|
|
exec "$@"
|