Skip to content

Commit

Permalink
Added Postgresql config in production.
Browse files Browse the repository at this point in the history
Added Postgresql config if is present ENV => DATABASE_URL.

Added migrations.

Fixed path sqlite.

Added MAILTRAP.
  • Loading branch information
ryanfox1985 committed Jan 17, 2017
1 parent ef8cd3f commit cc3e0f1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn superlists.wsgi --log-file -
10 changes: 10 additions & 0 deletions bin/post_compile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# !/usr/bin/env bash
# File path should be ./bin/post_compile
# (.sh extension added in Gist just to enable shell syntax highlighting.
# https://discussion.heroku.com/t/django-automaticlly-run-syncdb-and-migrations-after-heroku-deploy-with-a-buildpack-or-otherwise/466/7

echo "=> Performing database migrations..."
python manage.py migrate

echo "=> Generating static files..."
python manage.py collectstatic --noinput
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
django==1.10.4
gunicorn==19.6.0
dj-database-url==0.4.1
psycopg2>=2.6.1
whitenoise==3.2.1
28 changes: 22 additions & 6 deletions superlists/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

import os
import dj_database_url

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand All @@ -25,7 +26,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['localhost', 'testing-example.herokuapp.com']


# Application definition
Expand Down Expand Up @@ -84,11 +85,22 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, '../database/db.sqlite3'),
'NAME': os.path.join(BASE_DIR, './database/db.sqlite3'),
}
}


if os.getenv('DATABASE_URL', '') != '':
# Update database configuration with $DATABASE_URL.
db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)

# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'


# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators

Expand Down Expand Up @@ -145,8 +157,12 @@
'root': {'level': 'INFO'},
}

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASSWORD')
EMAIL_USE_TLS = True
if os.getenv('MAILTRAP_ENABLED', '') != '':
EMAIL_HOST = 'mailtrap.io'
EMAIL_HOST_USER = os.getenv('MAILTRAP_USER', '')
EMAIL_HOST_PASSWORD = os.getenv('MAILTRAP_PASSWORD', '')
EMAIL_PORT = '2525'

else:
# It writes e-mails to standard out instead of sending them
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
3 changes: 2 additions & 1 deletion superlists/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import os

from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "superlists.settings")

application = get_wsgi_application()
application = DjangoWhiteNoise(get_wsgi_application())

0 comments on commit cc3e0f1

Please sign in to comment.