Skip to content

Commit

Permalink
Feat: Unattended superuser creation (#1778)
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaveman authored Nov 9, 2023
2 parents c5f1972 + b9d2ecb commit 08b52c1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bin/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ python manage.py migrate
# check DJANGO_ADMIN = true, default to false if empty or unset

if [[ ${DJANGO_ADMIN:-false} = true ]]; then
python manage.py createsuperuser
python manage.py createsuperuser --no-input
else
echo "superuser: Django not configured for Admin access"
fi
Expand Down
36 changes: 36 additions & 0 deletions docs/configuration/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,42 @@ By default the application sends logs to `stdout`.

Django's primary secret, keep this safe!

### `DJANGO_SUPERUSER_EMAIL`

!!! warning "Deployment configuration"

You may change this setting when deploying the app to a non-localhost domain

!!! danger "Required configuration"

This setting is required when `DJANGO_ADMIN` is `true`

The email address of the Django Admin superuser created during initialization.

### `DJANGO_SUPERUSER_PASSWORD`

!!! warning "Deployment configuration"

You may change this setting when deploying the app to a non-localhost domain

!!! danger "Required configuration"

This setting is required when `DJANGO_ADMIN` is `true`

The password of the Django Admin superuser created during initialization.

### `DJANGO_SUPERUSER_USERNAME`

!!! warning "Deployment configuration"

You may change this setting when deploying the app to a non-localhost domain

!!! danger "Required configuration"

This setting is required when `DJANGO_ADMIN` is `true`

The username of the Django Admin superuser created during initialization.

### `DJANGO_TRUSTED_ORIGINS`

!!! warning "Deployment configuration"
Expand Down
15 changes: 9 additions & 6 deletions terraform/app_service.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ resource "azurerm_linux_web_app" "main" {
"REQUESTS_READ_TIMEOUT" = "${local.secret_prefix}requests-read-timeout)",

# Django settings
"DJANGO_ADMIN" = (local.is_prod || local.is_test) ? null : "${local.secret_prefix}django-admin)",
"DJANGO_ALLOWED_HOSTS" = "${local.secret_prefix}django-allowed-hosts)",
"DJANGO_DB_DIR" = "${local.secret_prefix}django-db-dir)",
"DJANGO_DB_RESET" = "${local.secret_prefix}django-db-reset)",
"DJANGO_DEBUG" = local.is_prod ? null : "${local.secret_prefix}django-debug)",
"DJANGO_LOG_LEVEL" = "${local.secret_prefix}django-log-level)",
"DJANGO_ADMIN" = "${local.secret_prefix}django-admin)",
"DJANGO_ALLOWED_HOSTS" = "${local.secret_prefix}django-allowed-hosts)",
"DJANGO_DB_DIR" = "${local.secret_prefix}django-db-dir)",
"DJANGO_DB_RESET" = "${local.secret_prefix}django-db-reset)",
"DJANGO_DEBUG" = local.is_prod ? null : "${local.secret_prefix}django-debug)",
"DJANGO_LOG_LEVEL" = "${local.secret_prefix}django-log-level)",
"DJANGO_SUPERUSER_EMAIL" = "${local.secret_prefix}django-superuser-email)",
"DJANGO_SUPERUSER_PASSWORD" = "${local.secret_prefix}django-superuser-password)",
"DJANGO_SUPERUSER_USERNAME" = "${local.secret_prefix}django-superuser-username)",

"DJANGO_RECAPTCHA_SECRET_KEY" = local.is_dev ? null : "${local.secret_prefix}django-recaptcha-secret-key)",
"DJANGO_RECAPTCHA_SITE_KEY" = local.is_dev ? null : "${local.secret_prefix}django-recaptcha-site-key)",
Expand Down

0 comments on commit 08b52c1

Please sign in to comment.