From 765b017ac28ae5d39d475b59e67047cde212c817 Mon Sep 17 00:00:00 2001 From: pedro Date: Mon, 23 Sep 2024 13:09:48 -0300 Subject: [PATCH] good default django settings for deployments current docker deployment was not taking in account deployment with DOMAIN - domain is enforced, localhost by default - .env.example proposed (right now only with DOMAIN) --- .env.example | 1 + dhub/settings.py | 11 +++++++++-- docker-compose.yml | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..18f815d --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +DOMAIN=localhost diff --git a/dhub/settings.py b/dhub/settings.py index 3770353..1c6dce1 100644 --- a/dhub/settings.py +++ b/dhub/settings.py @@ -27,10 +27,17 @@ BASE_DIR = Path(__file__).resolve().parent.parent SECRET_KEY = "django-insecure-1p8rs@qf$$l^!vsbetagojw23kw@1ez(qi8^(s0t!wyh!l3" # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = config('DEBUG', default=False, cast=bool) -ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='[]', cast=Csv()) +DOMAIN = config("DOMAIN") +assert DOMAIN not in [None, ''], "DOMAIN var is MANDATORY" +# this var is very important, we print it +print("DOMAIN: " + DOMAIN) +ALLOWED_HOSTS = config('ALLOWED_HOSTS', default=DOMAIN, cast=Csv()) +assert DOMAIN in ALLOWED_HOSTS, "DOMAIN is not ALLOWED_HOST" + +CSRF_TRUSTED_ORIGINS = config('CSRF_TRUSTED_ORIGINS', default=f'https://{DOMAIN}', cast=Csv()) # Application definition diff --git a/docker-compose.yml b/docker-compose.yml index a106f6e..d0d6e44 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: dockerfile: docker/devicehub-django.Dockerfile environment: - DEBUG=true - - ALLOWED_HOSTS=* + - DOMAIN=${DOMAIN:-localhost} volumes: - .:/opt/devicehub-django ports: