diff --git a/.gitignore b/.gitignore index 59579cc..14e03bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ # Created by https://www.gitignore.io +bin +gunicorn_config.py ### OSX ### .DS_Store diff --git a/candy_shop/config/common.py b/candy_shop/config/common.py index 62df9a8..7fd7a1a 100644 --- a/candy_shop/config/common.py +++ b/candy_shop/config/common.py @@ -2,6 +2,7 @@ from os.path import join from distutils.util import strtobool from configurations import Configuration +import dj_database_url BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -40,6 +41,13 @@ class Common(Configuration): ('Author', 'tsanda.artyom@gmail.com'), ) + DATABASES = { + 'default': dj_database_url.config( + default='postgres://postgres:@postgres:5432/postgres', + conn_max_age=int(os.getenv('POSTGRES_CONN_MAX_AGE', 600)) + ) + } + # General APPEND_SLASH = False TIME_ZONE = 'UTC' diff --git a/candy_shop/config/local.py b/candy_shop/config/local.py index 0f4e307..c2c8c56 100644 --- a/candy_shop/config/local.py +++ b/candy_shop/config/local.py @@ -16,14 +16,3 @@ class Local(Common): EMAIL_PORT = 1025 EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' - DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'candy_shop', - 'USER': 'postgres', - 'PASSWORD': 'postgres', - 'HOST': 'localhost', - 'PORT': '5432', - } - } - diff --git a/candy_shop/config/production.py b/candy_shop/config/production.py index e9515f6..7a7a32a 100644 --- a/candy_shop/config/production.py +++ b/candy_shop/config/production.py @@ -1,5 +1,4 @@ import os -import dj_database_url from .common import Common @@ -11,31 +10,3 @@ class Production(Common): ALLOWED_HOSTS = ["*"] INSTALLED_APPS += ("gunicorn", ) - # Static files (CSS, JavaScript, Images) - # https://docs.djangoproject.com/en/2.0/howto/static-files/ - # http://django-storages.readthedocs.org/en/latest/index.html - INSTALLED_APPS += ('storages',) - DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' - STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' - AWS_ACCESS_KEY_ID = os.getenv('DJANGO_AWS_ACCESS_KEY_ID') - AWS_SECRET_ACCESS_KEY = os.getenv('DJANGO_AWS_SECRET_ACCESS_KEY') - AWS_STORAGE_BUCKET_NAME = os.getenv('DJANGO_AWS_STORAGE_BUCKET_NAME') - AWS_DEFAULT_ACL = 'public-read' - AWS_AUTO_CREATE_BUCKET = True - AWS_QUERYSTRING_AUTH = False - MEDIA_URL = f'https://s3.amazonaws.com/{AWS_STORAGE_BUCKET_NAME}/' - - # https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching#cache-control - # Response can be cached by browser and any intermediary caches (i.e. it is "public") for up to 1 day - # 86400 = (60 seconds x 60 minutes x 24 hours) - AWS_HEADERS = { - 'Cache-Control': 'max-age=86400, s-maxage=86400, must-revalidate', - } - - # Postgres - DATABASES = { - 'default': dj_database_url.config( - default='postgres://postgres:@postgres:5432/postgres', - conn_max_age=int(os.getenv('POSTGRES_CONN_MAX_AGE', 600)) - ) - } diff --git a/candy_shop/wsgi.py b/candy_shop/wsgi.py index 0d01440..a6f3b9e 100644 --- a/candy_shop/wsgi.py +++ b/candy_shop/wsgi.py @@ -5,9 +5,12 @@ https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/gunicorn/ """ import os +import dotenv os.environ.setdefault("DJANGO_SETTINGS_MODULE", "candy_shop.config") os.environ.setdefault("DJANGO_CONFIGURATION", "Production") +dotenv.read_dotenv(os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env')) + from configurations.wsgi import get_wsgi_application application = get_wsgi_application() diff --git a/manage.py b/manage.py index ab32f85..e665ac1 100644 --- a/manage.py +++ b/manage.py @@ -2,9 +2,12 @@ """Django's command-line utility for administrative tasks.""" import os import sys +import dotenv def main(): + dotenv.read_dotenv() + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "candy_shop.config") os.environ.setdefault("DJANGO_CONFIGURATION", "Local")