set environment settings

This commit is contained in:
rmanach 2023-09-22 22:17:21 +02:00
parent 1aef5afe18
commit 89396ebac9
5 changed files with 29 additions and 12 deletions

12
.env.example Normal file
View File

@ -0,0 +1,12 @@
# 'dev' or whatever for dev environment, otherwise 'prod' to enable production environment
ENV=dev
# used only on production environment
HOST=
POSTGRES_DB=mumui
POSTGRES_USER=mumui
POSTGRES_PASSWORD=admin
# used at installation
ADMIN_PASSWORD=admin

3
.gitignore vendored
View File

@ -5,4 +5,5 @@ venv
/static
*.log
*.pid
docker-compose.override.yml
docker-compose.override.yml
.env

View File

@ -19,10 +19,8 @@ services:
postgres:
image: postgres:latest
container_name: postgres
environment:
POSTGRES_DB: mumui
POSTGRES_USER: test
POSTGRES_PASSWORD: test
env_file:
- .env
networks:
- mumui_network
volumes:
@ -31,6 +29,8 @@ services:
mumui:
image: mumui:local
container_name: mumui
env_file:
- .env
networks:
- mumui_network
volumes:

View File

@ -9,6 +9,7 @@ https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
import os
from pathlib import Path
@ -22,10 +23,13 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-_c56%%c8%g%@5(3&thxi7ku2a&wst8lik*8@l0=#)ar)s86g36"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
IS_PROD = os.getenv("ENV") == "prod"
HOST = "*" if not IS_PROD else os.getenv("HOST", "*")
ALLOWED_HOSTS = ["dev.thegux.fr"]
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = not IS_PROD
ALLOWED_HOSTS = ["*"] if not IS_PROD else [HOST.lstrip("https://")]
# Application definition
@ -80,8 +84,8 @@ DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "mumui",
"USER": "test",
"PASSWORD": "test",
"USER": os.getenv("POSTGRES_USER", "test"),
"PASSWORD": os.getenv("POSTGRES_PASSWORD", "test"),
"HOST": "postgres",
"PORT": "5432",
}
@ -135,4 +139,4 @@ LOGOUT_REDIRECT_URL = "home"
GRIP_URL = "http://pushpin:5561"
EVENTSTREAM_CHANNELMANAGER_CLASS = "deployment.channel.DeploymentChannelManager"
CSRF_TRUSTED_ORIGINS = ["https://dev.thegux.fr"]
CSRF_TRUSTED_ORIGINS = [HOST] if IS_PROD else ["http://localhost:8080"]

View File

@ -5,6 +5,6 @@ python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic --no-input
DJANGO_SUPERUSER_PASSWORD=admin python manage.py createsuperuser --noinput --username admin --email admin@admin.fr
DJANGO_SUPERUSER_PASSWORD=${ADMIN_PASSWORD} python manage.py createsuperuser --noinput --username admin --email admin@admin.fr
supervisord -c /app/supervisord.conf