Read the secret key from the persisted key file when unset

docker compose exec skips the entrypoint, so commands run that way had no
DJANGO_SECRET_KEY. Fall back to the file the entrypoint writes.
This commit is contained in:
sajeyks 2026-09-30 15:33:02 +03:00
commit 17bf42c895

View file

@ -79,6 +79,13 @@ EMAIL_PORT = int_env("EMAIL_PORT", 25)
EMAIL_USE_TLS = bool_env("EMAIL_USE_TLS")
SECRET_KEY = env('DJANGO_SECRET_KEY')
if not SECRET_KEY:
# the docker entrypoint persists a generated key here; this lets
# "docker compose exec" commands, which skip the entrypoint, find it
_key_file = env('SECRET_KEY_FILE', '/data/secret-key')
if os.path.exists(_key_file):
with open(_key_file) as _f:
SECRET_KEY = _f.read().strip()
# Application definition