diff --git a/.env b/.env deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/.env.example b/.env.example new file mode 100644 index 0000000000000000000000000000000000000000..463e6501685957e12934c121ac041a819d0a6265 --- /dev/null +++ b/.env.example @@ -0,0 +1,9 @@ +SECRET_KEY='7t^^#zw41ol8v*to-ti*jx7)iq@-=l9jquq1!5f!e02o!j2xyu' +DEBUG="True" +ALLOWED_HOSTS="*" +DB_NAME="realestate" +DB_USER="realestate" +DB_PASSWORD="password" +DB_HOST="localhost" +APP_HOST="localhost" +#SECURE_COOKIES="False" diff --git a/.gitignore b/.gitignore index 7f1c056f3eddb5989913f0be8cc1c765f7936ace..bf4197102534e30a9ec54bb8cb1b152ff766d08e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ ~* *.pyc .vagrant +.env diff --git a/Procfile b/Procfile index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..fe5d7ebe25b0266cee9c1b5500abda2a49dcd9ff 100644 --- a/Procfile +++ b/Procfile @@ -0,0 +1 @@ +app: gunicorn diff --git a/README.rst b/README.rst index 95999ce0387ef1c7c17fe1bee1e60e76a80ed1e2..c5c4052db6c46ed9b288149b7e211616fea89ef5 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,21 @@ django-realestate ***************** -A Django application for managing real estate listings. +A Django application for managing real estate listings. This is also an +excersice in building a 12-factor application. + +Requirements +------------ + +- Python3 + +Usage +----- + +TODO +---- + +- Provisioning (Fabric for DB hosts, App hosts, maybe Cache hosts, using + environment variables, SystemD service for App with setting under + /etc/default). +- Investigate default enviroment in Honcho. diff --git a/Realestate/Realestate/__init__.py b/Realestate/__init__.py similarity index 100% rename from Realestate/Realestate/__init__.py rename to Realestate/__init__.py diff --git a/Realestate/Realestate/settings.py b/Realestate/settings.py similarity index 80% rename from Realestate/Realestate/settings.py rename to Realestate/settings.py index 405ddab36bd5987240f25efd50af4caebc1a8b45..c9f078b3f7f73a3801093f62587384f78b64de13 100644 --- a/Realestate/Realestate/settings.py +++ b/Realestate/settings.py @@ -20,12 +20,18 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '7t^^#zw41ol8v*to-ti*jx7)iq@-=l9jquq1!5f!e02o!j2xyu' +SECRET_KEY = os.environ['SECRET_KEY'] # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +try: + DEBUG = bool(os.environ['DEBUG']) +except KeyError: + pass -ALLOWED_HOSTS = [] +try: + ALLOWED_HOSTS = os.environ['ALLOWED_HOSTS'].split(' ') +except KeyError: + pass # Application definition @@ -76,8 +82,11 @@ WSGI_APPLICATION = 'Realestate.wsgi.application' DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': os.environ['DB_NAME'], + 'USER': os.environ['DB_USER'], + 'PASSWORD': os.environ['DB_PASSWORD'], + 'HOST': os.environ['DB_HOST'] } } @@ -100,3 +109,9 @@ USE_TZ = True # https://docs.djangoproject.com/en/1.8/howto/static-files/ STATIC_URL = '/static/' + +try: + SESSION_COOKIE_SECURE = bool(os.environ['SECURE_COOKIES']) + CSRF_COOKIE_SECURE = bool(os.environ['SECURE_COOKIES']) +except KeyError: + pass diff --git a/Realestate/Realestate/urls.py b/Realestate/urls.py similarity index 100% rename from Realestate/Realestate/urls.py rename to Realestate/urls.py diff --git a/Realestate/Realestate/wsgi.py b/Realestate/wsgi.py similarity index 100% rename from Realestate/Realestate/wsgi.py rename to Realestate/wsgi.py diff --git a/Vagrantfile b/Vagrantfile index 35dece83e8ee3298ffea562a0b598ebb4b6b5b28..5cb32877c5b5adf31eda2191d36f2d80a2b1c8f0 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -3,15 +3,9 @@ Vagrant.configure(2) do |config| config.vm.box = "debian/jessie64" - if Vagrant.has_plugin?("landrush") - config.landrush.enabled = true - config.landrush.tld = "vagrant" - end config.vm.synced_folder ".", "/vagrant", disabled: true - config.vm.synced_folder "./", "/opt/realestate" config.vm.provision "shell", inline: <<-SHELL sudo apt-get update - sudo apt-get install -yf python3-pip python3-dev postgresql postgresql-client python3-psycopg2 - sudo pip3 install -r /opt/realestate/requirements.txt + sudo apt-get install -yf postgresql redis-server SHELL end diff --git a/fabfile.py b/fabfile.py new file mode 100755 index 0000000000000000000000000000000000000000..254bd524044b5f3f17a3efe100ae7f4a4dafc9eb --- /dev/null +++ b/fabfile.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 +from fabric.api import env, task, hosts +import os + + +env.use_ssh_config = True + + +@task +@hosts(os.environ['APP_HOST']) +def deploy(): + raise NotImplemented diff --git a/Realestate/manage.py b/manage.py similarity index 100% rename from Realestate/manage.py rename to manage.py diff --git a/requirements.txt b/requirements.txt index f80ddb06f9610bfc251eb0588ddd2320a1417bd1..4ab59e74faf6c0ef7966ff36628b0b705aa9f030 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ Django>=1.8 gunicorn honcho +fabric