diff --git a/requirements/production.txt b/requirements/production.txt new file mode 100644 index 0000000..a12fd45 --- /dev/null +++ b/requirements/production.txt @@ -0,0 +1,4 @@ +-r base.txt + +python-dotenv==0.12.0 +gunicorn==20.0.4 diff --git a/src/newsreader/conf/base.py b/src/newsreader/conf/base.py index 41e1669..2147a71 100644 --- a/src/newsreader/conf/base.py +++ b/src/newsreader/conf/base.py @@ -3,16 +3,13 @@ import os from pathlib import Path -BASE_DIR = Path(__file__).resolve().parent.parent +BASE_DIR = Path(__file__).resolve().parent.parent.parent.parent +DJANGO_PROJECT_DIR = os.path.join(BASE_DIR, "src", "newsreader") # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "^!7a2jq5j!exc-55vf$anx9^6ff6=u_ub5=5p1(1x47fix)syh" - # SECURITY WARNING: don"t run with debug turned on in production! -DEBUG = False +DEBUG = True ALLOWED_HOSTS = ["127.0.0.1"] INTERNAL_IPS = ["127.0.0.1"] @@ -59,7 +56,7 @@ ROOT_URLCONF = "newsreader.urls" TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [os.path.join(BASE_DIR, "templates")], + "DIRS": [os.path.join(DJANGO_PROJECT_DIR, "templates")], "APP_DIRS": True, "OPTIONS": { "context_processors": [ @@ -86,6 +83,17 @@ DATABASES = { } } +CACHES = { + "default": { + "BACKEND": "django.core.cache.backends.memcached.MemcachedCache", + "LOCATION": "localhost:11211", + }, + "axes": { + "BACKEND": "django.core.cache.backends.memcached.MemcachedCache", + "LOCATION": "localhost:11211", + }, +} + # Password validation # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ @@ -112,8 +120,8 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.2/howto/static-files/ STATIC_URL = "/static/" - -STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")] +STATIC_ROOT = os.path.join(BASE_DIR, "static") +STATICFILES_DIRS = [os.path.join(DJANGO_PROJECT_DIR, "static")] # https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-STATICFILES_FINDERS STATICFILES_FINDERS = [ diff --git a/src/newsreader/conf/dev.py b/src/newsreader/conf/dev.py index 16cf03b..7f4b5da 100644 --- a/src/newsreader/conf/dev.py +++ b/src/newsreader/conf/dev.py @@ -1,7 +1,7 @@ from .base import * # isort:skip -DEBUG = True +SECRET_KEY = "mv4&5#+)-=abz3^&1r^nk_ca6y54--p(4n4cg%z*g&rb64j%wl" MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"] @@ -9,16 +9,21 @@ EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" INSTALLED_APPS += ["debug_toolbar", "django_extensions"] -CACHES = { - "default": { - "BACKEND": "django.core.cache.backends.memcached.MemcachedCache", - "LOCATION": "localhost:11211", - }, - "axes": { - "BACKEND": "django.core.cache.backends.memcached.MemcachedCache", - "LOCATION": "localhost:11211", - }, -} +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [os.path.join(DJANGO_PROJECT_DIR, "templates")], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + ] + }, + } +] try: from .local import * # noqa diff --git a/src/newsreader/conf/docker.py b/src/newsreader/conf/docker.py index 5643937..3584b30 100644 --- a/src/newsreader/conf/docker.py +++ b/src/newsreader/conf/docker.py @@ -1,5 +1,8 @@ from .dev import * # isort:skip + +SECRET_KEY = "=q(ztyo)b6noom#a164g&s9vcj1aawa^g#ing_ir99=_zl4g&$" + # Celery # https://docs.celeryproject.org/en/latest/userguide/configuration.html BROKER_URL = "amqp://guest:guest@rabbitmq:5672//" diff --git a/src/newsreader/conf/gitlab.py b/src/newsreader/conf/gitlab.py index ee11c59..67a20dd 100644 --- a/src/newsreader/conf/gitlab.py +++ b/src/newsreader/conf/gitlab.py @@ -1,7 +1,7 @@ from .base import * # isort:skip -DEBUG = True +SECRET_KEY = "29%lkw+&n%^w4k#@_db2mo%*tc&xzb)x7xuq*(0$eucii%4r0c" EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" diff --git a/src/newsreader/conf/production.py b/src/newsreader/conf/production.py new file mode 100644 index 0000000..3b6be2a --- /dev/null +++ b/src/newsreader/conf/production.py @@ -0,0 +1,39 @@ +import os + +from dotenv import load_dotenv + + +from .base import * # isort:skip + + +load_dotenv() + +DEBUG = False +ALLOWED_HOSTS = ["rss.fudiggity.nl"] + +SECRET_KEY = os.environ["DJANGO_SECRET_KEY"] + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.postgresql", + "HOST": os.environ["POSTGRES_HOST"], + "NAME": os.environ["POSTGRES_NAME"], + "USER": os.environ["POSTGRES_USER"], + "PASSWORD": os.environ["POSTGRES_PASSWORD"], + } +} + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [os.path.join(DJANGO_PROJECT_DIR, "templates")], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + ] + }, + } +] diff --git a/src/newsreader/news/collection/tests/test_views.py b/src/newsreader/news/collection/tests/test_views.py index a9b07d0..0acd3ed 100644 --- a/src/newsreader/news/collection/tests/test_views.py +++ b/src/newsreader/news/collection/tests/test_views.py @@ -161,7 +161,7 @@ class OPMLImportTestCase(TestCase): self.url = reverse("import") def _get_file_path(self, name): - file_dir = os.path.join(settings.BASE_DIR, "utils", "tests", "files") + file_dir = os.path.join(settings.DJANGO_PROJECT_DIR, "utils", "tests", "files") return os.path.join(file_dir, name) def test_simple(self): diff --git a/src/newsreader/wsgi.py b/src/newsreader/wsgi.py index ffe4b3e..5872a04 100644 --- a/src/newsreader/wsgi.py +++ b/src/newsreader/wsgi.py @@ -12,6 +12,6 @@ import os from django.core.wsgi import get_wsgi_application -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "newsreader.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "newsreader.conf.production") application = get_wsgi_application()