Add support for setting/overriding config from envvars
This is practical for environments like docker/kubernetes
This commit is contained in:
parent
35f89af98e
commit
75fecf6e6f
@ -143,3 +143,12 @@ remove every line starting with "pyaudio" in requirements.txt
|
||||
|
||||
$ sed -i '/# Packaged commands/,$d' anki/sound.py
|
||||
$ sed -i '/^pyaudio/d' requirements.txt
|
||||
|
||||
ENVVAR configuration overrides
|
||||
==============================
|
||||
|
||||
Configuration values can be set via environment variables using `ANKISYNCD_` prepended
|
||||
to the uppercase form of the configuration value. E.g. the environment variable,
|
||||
`ANKISYNCD_AUTH_DB_PATH` will set the configuration value `auth_db_path`
|
||||
|
||||
Environment variables override the values set in the `ankisyncd.conf`.
|
||||
|
||||
@ -11,6 +11,16 @@ paths = [
|
||||
os.path.join(dirname(dirname(realpath(__file__))), "ankisyncd.conf"),
|
||||
]
|
||||
|
||||
# Get values from ENV and update the config. To use this prepend `ANKISYNCD_`
|
||||
# to the uppercase form of the key. E.g, `ANKISYNCD_SESSION_MANAGER` to set
|
||||
# `session_manager`
|
||||
def load_from_env(conf):
|
||||
logging.debug("Loading/overriding config values from ENV")
|
||||
for env in os.environ:
|
||||
if env.startswith('ANKISYNCD_'):
|
||||
config_key = env[10:].lower()
|
||||
conf[config_key] = os.getenv(env)
|
||||
logging.info("Setting {} from ENV".format(config_key))
|
||||
|
||||
def load(path=None):
|
||||
choices = paths
|
||||
@ -23,6 +33,7 @@ def load(path=None):
|
||||
parser.read(path)
|
||||
conf = parser['sync_app']
|
||||
logging.info("Loaded config from {}".format(path))
|
||||
load_from_env(conf)
|
||||
return conf
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
Loading…
Reference in New Issue
Block a user