Add YAML env variables support to platform app

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-07-10 00:34:09 -04:00
parent 91b0b2d9c3
commit 78a0189e1c
4 changed files with 58 additions and 28 deletions

View File

@@ -18,12 +18,16 @@
nested dictionaries in the configuration. Requires manual
update of existing config.yml files.
- Support user specified locations for the configuration file with the
CONFIGURATION_FILEPATH (MAYAN_CONFIGURATION_FILEPATH environment variable), and
CONFIGURATION_LAST_GOOD_FILEPATH
CONFIGURATION_FILEPATH (MAYAN_CONFIGURATION_FILEPATH environment variable),
and CONFIGURATION_LAST_GOOD_FILEPATH
(MAYAN_CONFIGURATION_LAST_GOOD_FILEPATH environment variable) settings.
- Move bootstrapped settings code to their own module in the smart_settings apps.
- Remove individual database configuration options. All database configuration
is now done using MAYAN_DATABASES to mirror Django way of doing database setup.
- Move bootstrapped settings code to their own module in the smart_settings
apps.
- Remove individual database configuration options. All database
configuration is now done using MAYAN_DATABASES to mirror Django way of
doing atabase etup.
- Added support for YAML encoded environment variables to the platform
templates apps.
3.2.5 (2019-07-05)
==================

View File

@@ -36,6 +36,8 @@ Changes
- Move bootstrapped settings code to their own module in the smart_settings apps.
- Remove individual database configuration options. All database configuration
is now done using MAYAN_DATABASES to mirror Django way of doing database setup.
- Added support for YAML encoded environment variables to the platform
templates apps.
Removals
--------

View File

@@ -4,11 +4,12 @@ import os
import yaml
try:
from yaml import CSafeLoader as SafeLoader
from yaml import CSafeLoader as SafeLoader, CSafeDumper as SafeDumper
except ImportError:
from yaml import SafeLoader
from yaml import SafeLoader, SafeDumper
from django.template import loader
from django.utils.html import mark_safe
from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
@@ -24,9 +25,25 @@ class Variable(object):
self.default = default
self.environment_name = environment_name
def get_value(self):
def _get_value(self):
return os.environ.get(self.environment_name, self.default)
def get_value(self):
return mark_safe(self._get_value())
class YAMLVariable(Variable):
def _get_value(self):
value = os.environ.get(self.environment_name)
if value:
value = yaml.load(stream=value, Loader=SafeLoader)
else:
value = self.default
return yaml.dump(
data=value, allow_unicode=True, default_flow_style=True, width=999, Dumper=SafeDumper
).replace('...\n', '').replace('\n', '')
@python_2_unicode_compatible
class PlatformTemplate(object):
@@ -106,10 +123,6 @@ class PlatformTemplate(object):
class PlatformTemplateSupervisord(PlatformTemplate):
context_defaults = {
'BROKER_URL': 'redis://127.0.0.1:6379/0',
'CELERY_RESULT_BACKEND': 'redis://127.0.0.1:6379/0',
}
label = _('Template for Supervisord.')
name = 'supervisord'
settings = (
@@ -124,16 +137,32 @@ class PlatformTemplateSupervisord(PlatformTemplate):
name='GUNICORN_TIMEOUT', default=120,
environment_name='MAYAN_GUNICORN_TIMEOUT'
),
Variable(
name='DATABASES',
default="{'default':{'ENGINE':'django.db.backends.postgresql','NAME':'mayan','PASSWORD':'mayanuserpass','USER':'mayan','HOST':'127.0.0.1'}}",
environment_name='MAYAN_DATABASES'
),
Variable(
name='INSTALLATION_PATH', default='/opt/mayan-edms',
environment_name='MAYAN_INSTALLATION_PATH'
),
Variable(
YAMLVariable(
name='ALLOWED_HOSTS',
default=['*'],
environment_name='MAYAN_ALLOWED_HOSTS'
),
YAMLVariable(
name='BROKER_URL',
default='redis://127.0.0.1:6379/0',
environment_name='MAYAN_BROKER_URL'
),
YAMLVariable(
name='CELERY_RESULT_BACKEND',
default='redis://127.0.0.1:6379/0',
environment_name='MAYAN_CELERY_RESULT_BACKEND'
),
YAMLVariable(
name='DATABASES',
default={'default':{'ENGINE':'django.db.backends.postgresql','NAME':'mayan','PASSWORD':'mayanuserpass','USER':'mayan','HOST':'127.0.0.1'}},
environment_name='MAYAN_DATABASES'
),
YAMLVariable
(
name='MEDIA_ROOT', default='/opt/mayan-edms/media',
environment_name='MAYAN_MEDIA_ROOT'
),

View File

@@ -1,17 +1,12 @@
[supervisord]
environment=
MAYAN_ALLOWED_HOSTS='["*"]', # Allow access to other network hosts other than localhost
PYTHONPATH={{ INSTALLATION_PATH }}/lib/python2.7/site-packages:{{ MEDIA_ROOT }}/mayan_settings,
DJANGO_SETTINGS_MODULE=mayan.settings.production,
MAYAN_MEDIA_ROOT="{{ MEDIA_ROOT }}",
MAYAN_ALLOWED_HOSTS="{{ ALLOWED_HOSTS }}",
MAYAN_CELERY_RESULT_BACKEND="{{ CELERY_RESULT_BACKEND }}",
MAYAN_BROKER_URL="{{ BROKER_URL }}",
PYTHONPATH={{ INSTALLATION_PATH }}/lib/python2.7/site-packages:{{ MEDIA_ROOT }}/mayan_settings,
MAYAN_MEDIA_ROOT={{ MEDIA_ROOT }},
MAYAN_DATABASE_ENGINE={{ DATABASE_ENGINE }},
MAYAN_DATABASE_HOST={{ DATABASE_HOST }},
MAYAN_DATABASE_NAME={{ DATABASE_NAME }},
MAYAN_DATABASE_PASSWORD={{ DATABASE_PASSWORD }},
MAYAN_DATABASE_USER={{ DATABASE_USER }},
MAYAN_DATABASE_CONN_MAX_AGE={{ DATABASE_CONN_MAX_AGE }},
DJANGO_SETTINGS_MODULE=mayan.settings.production
MAYAN_DATABASES="{{ DATABASES }}"
[program:mayan-gunicorn]
autorestart = true