Allow overriding container env vars
This commit is contained in:
parent
fdfb28fc47
commit
9dabf01051
|
@ -9,6 +9,9 @@ class Config:
|
|||
self.password = os.environ.get('RESTIC_REPOSITORY')
|
||||
self.docker_base_url = os.environ.get('DOCKER_BASE_URL') or "unix://tmp/docker.sock"
|
||||
|
||||
# Log
|
||||
self.log_level = os.environ.get('LOG_LEVEL')
|
||||
|
||||
# forget / keep
|
||||
self.keep_daily = os.environ.get('KEEP_DAILY') or "7"
|
||||
self.keep_weekly = os.environ.get('KEEP_WEEKLY') or "4"
|
||||
|
|
|
@ -63,7 +63,7 @@ class Container:
|
|||
@property
|
||||
def environment(self) -> list:
|
||||
"""All configured env vars for the container as a list"""
|
||||
return self.get_config('Env', default=[])
|
||||
return self.get_config('Env')
|
||||
|
||||
def get_config_env(self, name) -> str:
|
||||
"""Get a config environment variable by name"""
|
||||
|
@ -71,6 +71,17 @@ class Container:
|
|||
data = {i[0:i.find('=')]: i[i.find('=')+1:] for i in self.environment}
|
||||
return data.get(name)
|
||||
|
||||
def set_config_env(self, name, value):
|
||||
"""Set an environment variable"""
|
||||
env = self.environment
|
||||
new_value = f'{name}={value}'
|
||||
for i, entry in enumerate(env):
|
||||
if f'{name}=' in entry:
|
||||
env[i] = new_value
|
||||
break
|
||||
else:
|
||||
env.append(new_value)
|
||||
|
||||
@property
|
||||
def volumes(self) -> dict:
|
||||
"""
|
||||
|
|
|
@ -15,10 +15,6 @@ LOG_LEVELS = {
|
|||
|
||||
def setup(level: str = 'warning'):
|
||||
"""Set up logging"""
|
||||
# Get log level from env if not set directly
|
||||
if level is None:
|
||||
level = os.environ.get('LOG_LEVEL')
|
||||
|
||||
level = level or ""
|
||||
level = LOG_LEVELS.get(level.lower(), DEFAULT_LOG_LEVEL)
|
||||
logger.setLevel(level)
|
||||
|
|
Loading…
Reference in New Issue