Unverified Commit 6eaa821d authored by William Tucker's avatar William Tucker Committed by GitHub
Browse files

Merge pull request #235 from ESGF/auth-service-fix

Removed unused init scripts from auth-service image
parents 71cd4320 aee2471f
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ RUN mkdir -p /etc/django/settings.d

# Install init scripts and serving script
COPY django-serve.sh /usr/local/bin/
COPY init.d/* /docker-init.d/

# Use ONBUILD instructions to install and configure the application
COPY --from=python-build /build/wheelhouse /build/wheelhouse
+0 −25
Original line number Diff line number Diff line
#!/opt/conda/bin/python

"""
This script runs database migrations, but only if there are databases configured.
"""

import django
from django.conf import settings
from django.core import management


def main():
    # First, make sure we have run the Django setup
    django.setup()

    # Then run the migrations if required
    if settings.DATABASES:
        print(f"[info] Running database migrations")
        management.call_command('migrate', interactive = False)
    else:
        print(f"[warn] Skipping database migrations - no databases configured")


if __name__ == "__main__":
    main()
+0 −55
Original line number Diff line number Diff line
#!/opt/conda/bin/python

"""
This script configures a Django superuser.
"""

def main():
    import os

    # Only create the superuser if a username is specified
    if 'DJANGO_SUPERUSER_USERNAME' not in os.environ:
        print("[info] Skipping Django superuser configuration - no superuser specified")
        return

    # Configure Django before attempting to read a model
    import django
    django.setup()

    from django.core.exceptions import ObjectDoesNotExist
    from django.contrib.auth import get_user_model

    username = os.environ['DJANGO_SUPERUSER_USERNAME']
    print(f"[info] Configuring Django superuser - {username}")

    # Create or update the superuser
    User = get_user_model()
    try:
        user = User.objects.get(username = username)
    except ObjectDoesNotExist:
        user = User.objects.create_superuser(username)
    else:
        if not user.is_staff or not user.is_superuser:
            user.is_staff = True
            user.is_superuser = True
            user.save()

    # Update the password if specified
    # We allow it to come either from a file specified by an environment variable,
    # or directly from the environment
    superuser_password = None
    if 'DJANGO_SUPERUSER_PASSWORD' in os.environ:
        superuser_password = os.environ['DJANGO_SUPERUSER_PASSWORD'].strip()
    elif 'DJANGO_SUPERUSER_PASSWORD_FILE' in os.environ:
        with open(os.environ['DJANGO_SUPERUSER_PASSWORD_FILE']) as fh:
            superuser_password = fh.read().strip()
    if superuser_password:
        print("[info] Setting Django superuser password")
        user.set_password(superuser_password)
        user.save()
    else:
        print("[info] No Django superuser password specified")


if __name__ == "__main__":
    main()