mirror of
https://github.com/ChristianLight/tutor.git
synced 2025-01-07 16:04:02 +00:00
Read default settings from environment variables
Moreover, ACTIVATE_* variables are now made permanent. It is no longer necessary to re-declare them at each call of `make configure`.
This commit is contained in:
parent
df95a50ab5
commit
b0f2adb931
2
Makefile
2
Makefile
@ -31,7 +31,7 @@ all: configure $(post_configure_targets) update migrate assets daemonize
|
|||||||
|
|
||||||
configure: build-configurator
|
configure: build-configurator
|
||||||
docker run --rm -it --volume="$(PWD)/config:/openedx/config" \
|
docker run --rm -it --volume="$(PWD)/config:/openedx/config" \
|
||||||
-e USERID=$(USERID) -e SILENT=$(SILENT) -e ACTIVATE_HTTPS=$(ACTIVATE_HTTPS) -e ACTIVATE_XQUEUE=$(ACTIVATE_XQUEUE) \
|
-e USERID=$(USERID) -e SILENT=$(SILENT) -e SETTING_ACTIVATE_HTTPS=$(ACTIVATE_HTTPS) -e SETTING_ACTIVATE_XQUEUE=$(ACTIVATE_XQUEUE) \
|
||||||
regis/openedx-configurator:hawthorn bash -c "./configure.py interactive && \
|
regis/openedx-configurator:hawthorn bash -c "./configure.py interactive && \
|
||||||
./configure.py substitute ./config/openedx/templates/lms.env.json.templ ./config/openedx/lms.env.json && \
|
./configure.py substitute ./config/openedx/templates/lms.env.json.templ ./config/openedx/lms.env.json && \
|
||||||
./configure.py substitute ./config/openedx/templates/cms.env.json.templ ./config/openedx/cms.env.json && \
|
./configure.py substitute ./config/openedx/templates/cms.env.json.templ ./config/openedx/cms.env.json && \
|
||||||
|
@ -16,6 +16,12 @@ import jinja2
|
|||||||
class Configurator:
|
class Configurator:
|
||||||
|
|
||||||
def __init__(self, **default_overrides):
|
def __init__(self, **default_overrides):
|
||||||
|
"""
|
||||||
|
Default values are read, in decreasing order of priority, from:
|
||||||
|
- SETTING_<name> environment variable
|
||||||
|
- Existing config file (in `default_overrides`)
|
||||||
|
- Value passed to add()
|
||||||
|
"""
|
||||||
self.__values = OrderedDict()
|
self.__values = OrderedDict()
|
||||||
self.__default_values = default_overrides
|
self.__default_values = default_overrides
|
||||||
try:
|
try:
|
||||||
@ -30,14 +36,29 @@ class Configurator:
|
|||||||
self.__input = None
|
self.__input = None
|
||||||
|
|
||||||
def add(self, name, question="", default=""):
|
def add(self, name, question="", default=""):
|
||||||
default = self.__default_values.get(name, default)
|
default = self.default_value(name) or default
|
||||||
value = default
|
|
||||||
message = question + " (default: \"{}\"): ".format(default) if question else None
|
message = question + " (default: \"{}\"): ".format(default) if question else None
|
||||||
value = self.ask(message, default)
|
value = self.ask(message, default)
|
||||||
self.set(name, value)
|
self.set(name, value)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def add_bool(self, name, question="", default=False):
|
||||||
|
self.add(name, question=question, default=default)
|
||||||
|
value = self.get(name)
|
||||||
|
if value in [1, '1']:
|
||||||
|
return self.set(name, True)
|
||||||
|
if value in [0, '0']:
|
||||||
|
return self.set(name, False)
|
||||||
|
return self
|
||||||
|
|
||||||
|
def default_value(self, name):
|
||||||
|
setting_name = 'SETTING_' + name.upper()
|
||||||
|
if setting_name in os.environ:
|
||||||
|
return os.environ[setting_name]
|
||||||
|
|
||||||
|
return self.__default_values.get(name)
|
||||||
|
|
||||||
def ask(self, message, default):
|
def ask(self, message, default):
|
||||||
if self.__input and message:
|
if self.__input and message:
|
||||||
return self.__input(message) or default
|
return self.__input(message) or default
|
||||||
@ -64,8 +85,6 @@ def main():
|
|||||||
"This is good for debugging and automation, but "
|
"This is good for debugging and automation, but "
|
||||||
"probably not what you want"
|
"probably not what you want"
|
||||||
))
|
))
|
||||||
parser_interactive.add_argument('--activate-https', action='store_true', default=False, help='Activate https feature flag')
|
|
||||||
parser_interactive.add_argument('--activate-xqueue', action='store_true', default=False, help='Activate xqueue feature flag')
|
|
||||||
parser_interactive.set_defaults(func=interactive)
|
parser_interactive.set_defaults(func=interactive)
|
||||||
|
|
||||||
parser_substitute = subparsers.add_parser('substitute')
|
parser_substitute = subparsers.add_parser('substitute')
|
||||||
@ -105,25 +124,25 @@ def interactive(args):
|
|||||||
).add(
|
).add(
|
||||||
'MYSQL_USERNAME', "", 'openedx'
|
'MYSQL_USERNAME', "", 'openedx'
|
||||||
).add(
|
).add(
|
||||||
'MYSQL_PASSWORD', "", random_string(8),
|
'MYSQL_PASSWORD', "", random_string(8)
|
||||||
).add(
|
).add(
|
||||||
'MONGODB_DATABASE', "", 'openedx'
|
'MONGODB_DATABASE', "", 'openedx'
|
||||||
).add(
|
).add(
|
||||||
'XQUEUE_AUTH_USERNAME', "", 'lms'
|
'XQUEUE_AUTH_USERNAME', "", 'lms'
|
||||||
).add(
|
).add(
|
||||||
'XQUEUE_AUTH_PASSWORD', "", random_string(8),
|
'XQUEUE_AUTH_PASSWORD', "", random_string(8)
|
||||||
).add(
|
).add(
|
||||||
'XQUEUE_MYSQL_DATABASE', "", 'xqueue',
|
'XQUEUE_MYSQL_DATABASE', "", 'xqueue',
|
||||||
).add(
|
).add(
|
||||||
'XQUEUE_MYSQL_USERNAME', "", 'xqueue',
|
'XQUEUE_MYSQL_USERNAME', "", 'xqueue',
|
||||||
).add(
|
).add(
|
||||||
'XQUEUE_MYSQL_PASSWORD', "", random_string(8),
|
'XQUEUE_MYSQL_PASSWORD', "", random_string(8)
|
||||||
).add(
|
).add(
|
||||||
'XQUEUE_SECRET_KEY', "", random_string(24),
|
'XQUEUE_SECRET_KEY', "", random_string(24)
|
||||||
).set(
|
).add_bool(
|
||||||
'ACTIVATE_HTTPS', bool(args.activate_https or os.environ.get('ACTIVATE_HTTPS'))
|
'ACTIVATE_HTTPS', "", False
|
||||||
).set(
|
).add_bool(
|
||||||
'ACTIVATE_XQUEUE', bool(args.activate_xqueue or os.environ.get('ACTIVATE_XQUEUE'))
|
'ACTIVATE_XQUEUE', "", False
|
||||||
)
|
)
|
||||||
|
|
||||||
# Save values
|
# Save values
|
||||||
|
Loading…
Reference in New Issue
Block a user