Skip to content
Snippets Groups Projects
Commit a2e923d1 authored by Michal Cyprian's avatar Michal Cyprian
Browse files

Add Platform.sh settings

parent 92609193
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,9 @@ https://docs.djangoproject.com/en/2.1/ref/settings/ ...@@ -11,6 +11,9 @@ https://docs.djangoproject.com/en/2.1/ref/settings/
""" """
import os import os
import json
import base64
from urllib.parse import urlparse
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
...@@ -118,3 +121,40 @@ USE_TZ = True ...@@ -118,3 +121,40 @@ USE_TZ = True
# https://docs.djangoproject.com/en/2.1/howto/static-files/ # https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = '/static/' STATIC_URL = '/static/'
# Import some Platform.sh settings from the environment.
STATIC_ROOT = os.path.join(os.getenv('PLATFORM_APP_DIR'), 'static')
entropy = os.getenv('PLATFORM_PROJECT_ENTROPY')
if entropy:
SECRET_KEY = entropy
routes = os.getenv('PLATFORM_ROUTES')
if routes:
routes = json.loads(base64.b64decode(routes).decode('utf-8'))
app_name = os.getenv('PLATFORM_APPLICATION_NAME')
for url, route in routes.items():
host = urlparse(url).netloc
if (host not in ALLOWED_HOSTS and route['type'] == 'upstream'
and route['upstream'] == app_name):
ALLOWED_HOSTS.append(host)
relationships = os.getenv('PLATFORM_RELATIONSHIPS')
if relationships:
relationships = json.loads(base64.b64decode(relationships).decode('utf-8'))
db_settings = relationships['database'][0]
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': db_settings['path'],
'USER': db_settings['username'],
'PASSWORD': db_settings['password'],
'HOST': db_settings['host'],
'PORT': db_settings['port'],
},
'sqlite': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment