Add YAML env variables support to platform app
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
14
HISTORY.rst
14
HISTORY.rst
@@ -18,12 +18,16 @@
|
|||||||
nested dictionaries in the configuration. Requires manual
|
nested dictionaries in the configuration. Requires manual
|
||||||
update of existing config.yml files.
|
update of existing config.yml files.
|
||||||
- Support user specified locations for the configuration file with the
|
- Support user specified locations for the configuration file with the
|
||||||
CONFIGURATION_FILEPATH (MAYAN_CONFIGURATION_FILEPATH environment variable), and
|
CONFIGURATION_FILEPATH (MAYAN_CONFIGURATION_FILEPATH environment variable),
|
||||||
CONFIGURATION_LAST_GOOD_FILEPATH
|
and CONFIGURATION_LAST_GOOD_FILEPATH
|
||||||
(MAYAN_CONFIGURATION_LAST_GOOD_FILEPATH environment variable) settings.
|
(MAYAN_CONFIGURATION_LAST_GOOD_FILEPATH environment variable) settings.
|
||||||
- Move bootstrapped settings code to their own module in the smart_settings apps.
|
- Move bootstrapped settings code to their own module in the smart_settings
|
||||||
- Remove individual database configuration options. All database configuration
|
apps.
|
||||||
is now done using MAYAN_DATABASES to mirror Django way of doing database setup.
|
- 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)
|
3.2.5 (2019-07-05)
|
||||||
==================
|
==================
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ Changes
|
|||||||
- Move bootstrapped settings code to their own module in the smart_settings apps.
|
- Move bootstrapped settings code to their own module in the smart_settings apps.
|
||||||
- Remove individual database configuration options. All database configuration
|
- Remove individual database configuration options. All database configuration
|
||||||
is now done using MAYAN_DATABASES to mirror Django way of doing database setup.
|
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
|
Removals
|
||||||
--------
|
--------
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import os
|
|||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
try:
|
try:
|
||||||
from yaml import CSafeLoader as SafeLoader
|
from yaml import CSafeLoader as SafeLoader, CSafeDumper as SafeDumper
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from yaml import SafeLoader
|
from yaml import SafeLoader, SafeDumper
|
||||||
|
|
||||||
from django.template import loader
|
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.encoding import force_text, python_2_unicode_compatible
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
@@ -24,9 +25,25 @@ class Variable(object):
|
|||||||
self.default = default
|
self.default = default
|
||||||
self.environment_name = environment_name
|
self.environment_name = environment_name
|
||||||
|
|
||||||
def get_value(self):
|
def _get_value(self):
|
||||||
return os.environ.get(self.environment_name, self.default)
|
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
|
@python_2_unicode_compatible
|
||||||
class PlatformTemplate(object):
|
class PlatformTemplate(object):
|
||||||
@@ -106,10 +123,6 @@ class PlatformTemplate(object):
|
|||||||
|
|
||||||
|
|
||||||
class PlatformTemplateSupervisord(PlatformTemplate):
|
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.')
|
label = _('Template for Supervisord.')
|
||||||
name = 'supervisord'
|
name = 'supervisord'
|
||||||
settings = (
|
settings = (
|
||||||
@@ -124,16 +137,32 @@ class PlatformTemplateSupervisord(PlatformTemplate):
|
|||||||
name='GUNICORN_TIMEOUT', default=120,
|
name='GUNICORN_TIMEOUT', default=120,
|
||||||
environment_name='MAYAN_GUNICORN_TIMEOUT'
|
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(
|
Variable(
|
||||||
name='INSTALLATION_PATH', default='/opt/mayan-edms',
|
name='INSTALLATION_PATH', default='/opt/mayan-edms',
|
||||||
environment_name='MAYAN_INSTALLATION_PATH'
|
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',
|
name='MEDIA_ROOT', default='/opt/mayan-edms/media',
|
||||||
environment_name='MAYAN_MEDIA_ROOT'
|
environment_name='MAYAN_MEDIA_ROOT'
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,17 +1,12 @@
|
|||||||
[supervisord]
|
[supervisord]
|
||||||
environment=
|
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_CELERY_RESULT_BACKEND="{{ CELERY_RESULT_BACKEND }}",
|
||||||
MAYAN_BROKER_URL="{{ BROKER_URL }}",
|
MAYAN_BROKER_URL="{{ BROKER_URL }}",
|
||||||
PYTHONPATH={{ INSTALLATION_PATH }}/lib/python2.7/site-packages:{{ MEDIA_ROOT }}/mayan_settings,
|
MAYAN_DATABASES="{{ DATABASES }}"
|
||||||
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
|
|
||||||
|
|
||||||
[program:mayan-gunicorn]
|
[program:mayan-gunicorn]
|
||||||
autorestart = true
|
autorestart = true
|
||||||
|
|||||||
Reference in New Issue
Block a user