From 7d23ee6044c9722dc8a02a9c1ab524cc55008121 Mon Sep 17 00:00:00 2001 From: redfast00 Date: Sat, 25 Jul 2020 13:32:38 +0200 Subject: [PATCH] Move env variables to envfile --- KeRS/settings.py | 9 +++------ docker-compose.yml | 19 +++++++------------ users/forms.py | 4 ++-- web.env | 11 +++++++++++ 4 files changed, 23 insertions(+), 20 deletions(-) create mode 100644 web.env diff --git a/KeRS/settings.py b/KeRS/settings.py index bdacb97..6f1b8da 100644 --- a/KeRS/settings.py +++ b/KeRS/settings.py @@ -12,9 +12,6 @@ https://docs.djangoproject.com/en/3.0/ref/settings/ import os -from django.core.exceptions import ImproperlyConfigured - - # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -22,12 +19,12 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '2r@t7^g4-@980!oo-v!1+wj+0o^s&m(+yyyt#2&k2e!ao*b$g5' +SECRET_KEY = os.getenv('SECRET_KEY', '2r@t7^g4-@980!oo-v!1+wj+0o^s&m(+yyyt#2&k2e!ao*b$g5') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = os.getenv('DEBUG', '1') == '1' -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', '').split(',') # Application definition diff --git a/docker-compose.yml b/docker-compose.yml index 4ca39cf..5676586 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,10 +4,8 @@ services: build: . ports: - "8000:8000" - environment: - DATABASE_HOST: 'database' - CELERY_BROKER: 'redis://redis:6379/0' - CELERY_BACKEND: 'redis://redis:6379/1' + env_file: 'web.env' + restart: on-failure depends_on: - database command: > @@ -17,10 +15,8 @@ services: celery-worker: build: . - environment: - DATABASE_HOST: 'database' - CELERY_BROKER: 'redis://redis:6379/0' - CELERY_BACKEND: 'redis://redis:6379/1' + env_file: 'web.env' + restart: on-failure depends_on: - web - redis @@ -30,10 +26,8 @@ services: celery-beat: build: . - environment: - DATABASE_HOST: 'database' - CELERY_BROKER: 'redis://redis:6379/0' - CELERY_BACKEND: 'redis://redis:6379/1' + env_file: 'web.env' + restart: on-failure depends_on: - web - redis @@ -47,6 +41,7 @@ services: # Db stuff database: image: mariadb:10.5.4-focal + restart: on-failure environment: MYSQL_ROOT_PASSWORD: example MYSQL_DATABASE: kers diff --git a/users/forms.py b/users/forms.py index c2e94ae..39eda64 100644 --- a/users/forms.py +++ b/users/forms.py @@ -22,8 +22,8 @@ class UserMetaForm(ModelForm): model = CustomUser fields = ['real_name', 'student_number'] widgets = { - 'real_name': TextInput(attrs={'placeholder': 'Robbe Van Herck'}), - 'student_number': TextInput(attrs={'placeholder': '01701111'}) + 'real_name': TextInput(attrs={'placeholder': 'Robbe Van Herck'}), + 'student_number': TextInput(attrs={'placeholder': '001700000', 'pattern': '[0-9]*'}) } diff --git a/web.env b/web.env new file mode 100644 index 0000000..621b5e0 --- /dev/null +++ b/web.env @@ -0,0 +1,11 @@ +DATABASE_HOST=database +CELERY_BROKER=redis://redis:6379/0 +CELERY_BACKEND=redis://redis:6379/1 +SECRET_KEY=REPLACEME +DEBUG=1 +SERVER_URL=http://localhost:8000 +OAUTH_CLIENT_ID=REPLACEME +OAUTH_CLIENT_SECRET=REPLACEME +KERS_ADMIN_USERNAME=replaceme +KERS_ADMIN_PASSWORD=replaceme +ALLOWED_HOSTS=localhost