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

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ venv
*.log *.log
*.pid *.pid
docker-compose.override.yml docker-compose.override.yml
.env

View File

@ -19,10 +19,8 @@ services:
postgres: postgres:
image: postgres:latest image: postgres:latest
container_name: postgres container_name: postgres
environment: env_file:
POSTGRES_DB: mumui - .env
POSTGRES_USER: test
POSTGRES_PASSWORD: test
networks: networks:
- mumui_network - mumui_network
volumes: volumes:
@ -31,6 +29,8 @@ services:
mumui: mumui:
image: mumui:local image: mumui:local
container_name: mumui container_name: mumui
env_file:
- .env
networks: networks:
- mumui_network - mumui_network
volumes: 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 For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/ https://docs.djangoproject.com/en/4.2/ref/settings/
""" """
import os
from pathlib import Path 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! # 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" 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! IS_PROD = os.getenv("ENV") == "prod"
DEBUG = True 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 # Application definition
@ -80,8 +84,8 @@ DATABASES = {
"default": { "default": {
"ENGINE": "django.db.backends.postgresql", "ENGINE": "django.db.backends.postgresql",
"NAME": "mumui", "NAME": "mumui",
"USER": "test", "USER": os.getenv("POSTGRES_USER", "test"),
"PASSWORD": "test", "PASSWORD": os.getenv("POSTGRES_PASSWORD", "test"),
"HOST": "postgres", "HOST": "postgres",
"PORT": "5432", "PORT": "5432",
} }
@ -135,4 +139,4 @@ LOGOUT_REDIRECT_URL = "home"
GRIP_URL = "http://pushpin:5561" GRIP_URL = "http://pushpin:5561"
EVENTSTREAM_CHANNELMANAGER_CLASS = "deployment.channel.DeploymentChannelManager" 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 migrate
python manage.py collectstatic --no-input 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 supervisord -c /app/supervisord.conf