Skip to content

Commit

Permalink
refactor(admin): assume database and superuser already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
angela-tran committed Feb 8, 2024
1 parent 9e310a7 commit ecdf040
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 74 deletions.
23 changes: 0 additions & 23 deletions bin/init.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
#!/usr/bin/env bash
set -eux

# make the path to the database file from environment or default
DB_DIR="${DJANGO_DB_DIR:-.}"
DB_FILE="${DB_DIR}/django.db"
DB_RESET="${DJANGO_DB_RESET:-true}"

# remove existing (old) database file
if [[ $DB_RESET = true && -f $DB_FILE ]]; then
# rename then delete the new file
# trying to avoid a file lock on the existing file
# after marking it for deletion
mv "${DB_FILE}" "${DB_FILE}.old"
rm "${DB_FILE}.old"
fi

# run database migrations

python manage.py migrate

# create a superuser account for backend admin access
# check DJANGO_ADMIN = true, default to false if empty or unset

if [[ ${DJANGO_ADMIN:-false} = true ]]; then
python manage.py createsuperuser --no-input
else
echo "superuser: Django not configured for Admin access"
fi

# generate language *.mo files for use by Django

python manage.py compilemessages
Expand Down
47 changes: 0 additions & 47 deletions docs/configuration/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,6 @@ writable by the Django process._

By default, the base project directory (i.e. the root of the repository).

### `DJANGO_DB_RESET`

!!! warning "Deployment configuration"

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

Boolean:

- `True` (default): deletes the existing database file and runs fresh Django migrations.
- `False`: Django uses the existing database file.

### `DJANGO_DEBUG`

!!! warning "Deployment configuration"
Expand Down Expand Up @@ -120,42 +109,6 @@ 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
4 changes: 0 additions & 4 deletions terraform/app_service.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,8 @@ resource "azurerm_linux_web_app" "main" {
"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 ecdf040

Please sign in to comment.