Django 5.2 with dev/test/prod settings, SQLite tuned for Litestream (WAL, IMMEDIATE transactions), ULID primary keys via a shared base model, and a custom User model ahead of the first migration. Minimal accessible base template with dark mode via color-scheme and an optional theme picker. /healthz answers before host validation so Fly checks pass. Dockerfile (dev and prod targets), compose for local dev, fly.toml with placeholder app/region, Litestream backups to B2, and a Forgejo Actions workflow. Migrations run in bin/start because Fly release machines don't mount volumes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
118 lines
3.8 KiB
Python
118 lines
3.8 KiB
Python
import os
|
|
from pathlib import Path
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
|
|
|
# Holds the SQLite database. A Fly volume in production, a Docker volume in compose.
|
|
DATA_DIR = Path(os.environ.get("INTENT_DATA_DIR", BASE_DIR / "data"))
|
|
|
|
SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY", "")
|
|
DEBUG = False
|
|
ALLOWED_HOSTS = []
|
|
|
|
INSTALLED_APPS = [
|
|
"django.contrib.admin",
|
|
"django.contrib.auth",
|
|
"django.contrib.contenttypes",
|
|
"django.contrib.sessions",
|
|
"django.contrib.messages",
|
|
"django.contrib.staticfiles",
|
|
"intent.core",
|
|
"intent.accounts",
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
# First, so health checks skip host validation and the HTTPS redirect.
|
|
"intent.core.middleware.HealthCheckMiddleware",
|
|
"django.middleware.security.SecurityMiddleware",
|
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
|
"django.middleware.common.CommonMiddleware",
|
|
"django.middleware.csrf.CsrfViewMiddleware",
|
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
|
"django.contrib.messages.middleware.MessageMiddleware",
|
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
|
]
|
|
|
|
ROOT_URLCONF = "config.urls"
|
|
WSGI_APPLICATION = "config.wsgi.application"
|
|
|
|
TEMPLATES = [
|
|
{
|
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
"DIRS": [BASE_DIR / "templates"],
|
|
"APP_DIRS": True,
|
|
"OPTIONS": {
|
|
"context_processors": [
|
|
"django.template.context_processors.request",
|
|
"django.contrib.auth.context_processors.auth",
|
|
"django.contrib.messages.context_processors.messages",
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
DATABASES = {
|
|
"default": {
|
|
"ENGINE": "django.db.backends.sqlite3",
|
|
"NAME": DATA_DIR / "db.sqlite3",
|
|
"OPTIONS": {
|
|
# Take the write lock at BEGIN so concurrent writers wait instead of failing.
|
|
"transaction_mode": "IMMEDIATE",
|
|
"timeout": 5,
|
|
# WAL is required by Litestream.
|
|
"init_command": "PRAGMA journal_mode=WAL; PRAGMA synchronous=NORMAL;",
|
|
},
|
|
}
|
|
}
|
|
|
|
AUTH_USER_MODEL = "accounts.User"
|
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
|
|
|
AUTH_PASSWORD_VALIDATORS = [
|
|
{"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"},
|
|
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
|
|
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
|
|
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
|
|
]
|
|
|
|
LANGUAGE_CODE = "en-us"
|
|
TIME_ZONE = "UTC"
|
|
USE_I18N = True
|
|
USE_TZ = True
|
|
|
|
STATIC_URL = "static/"
|
|
STATIC_ROOT = BASE_DIR / "staticfiles"
|
|
STATICFILES_DIRS = [BASE_DIR / "static"]
|
|
|
|
# Uploaded files go to S3-compatible storage (Tigris) when a bucket is configured,
|
|
# otherwise to the local filesystem. `fly storage create` sets these variable names.
|
|
if os.environ.get("BUCKET_NAME"):
|
|
_default_storage = {
|
|
"BACKEND": "storages.backends.s3.S3Storage",
|
|
"OPTIONS": {
|
|
"bucket_name": os.environ["BUCKET_NAME"],
|
|
"endpoint_url": os.environ.get("AWS_ENDPOINT_URL_S3"),
|
|
"region_name": os.environ.get("AWS_REGION", "auto"),
|
|
"default_acl": None,
|
|
"querystring_auth": True,
|
|
"querystring_expire": 300,
|
|
"file_overwrite": False,
|
|
},
|
|
}
|
|
else:
|
|
_default_storage = {
|
|
"BACKEND": "django.core.files.storage.FileSystemStorage",
|
|
"OPTIONS": {"location": DATA_DIR / "media"},
|
|
}
|
|
|
|
STORAGES = {
|
|
"default": _default_storage,
|
|
"staticfiles": {"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"},
|
|
}
|
|
|
|
LOGGING = {
|
|
"version": 1,
|
|
"disable_existing_loggers": False,
|
|
"handlers": {"console": {"class": "logging.StreamHandler"}},
|
|
"root": {"handlers": ["console"], "level": "INFO"},
|
|
}
|