From ecdf040ce272baf0091da4eff6bbbf4f23f95db9 Mon Sep 17 00:00:00 2001 From: Angela Tran Date: Tue, 23 Jan 2024 20:26:56 +0000 Subject: [PATCH] refactor(admin): assume database and superuser already exist --- bin/init.sh | 23 ---------- docs/configuration/environment-variables.md | 47 --------------------- terraform/app_service.tf | 4 -- 3 files changed, 74 deletions(-) diff --git a/bin/init.sh b/bin/init.sh index 8a11d863e3..c2a283c2a5 100755 --- a/bin/init.sh +++ b/bin/init.sh @@ -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 diff --git a/docs/configuration/environment-variables.md b/docs/configuration/environment-variables.md index 7d5a478c2a..b699fd9091 100644 --- a/docs/configuration/environment-variables.md +++ b/docs/configuration/environment-variables.md @@ -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" @@ -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" diff --git a/terraform/app_service.tf b/terraform/app_service.tf index bc80047311..7caa103ea0 100644 --- a/terraform/app_service.tf +++ b/terraform/app_service.tf @@ -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)",