diff --git a/server/szurubooru/config.py b/server/szurubooru/config.py index 8f87642fe..f3f9007c6 100644 --- a/server/szurubooru/config.py +++ b/server/szurubooru/config.py @@ -21,7 +21,7 @@ def _merge(left: Dict, right: Dict) -> Dict: return left -def _docker_config() -> Dict: +def _container_config() -> Dict: if "TEST_ENVIRONMENT" not in os.environ: for key in ["POSTGRES_USER", "POSTGRES_PASSWORD", "POSTGRES_HOST"]: if key not in os.environ: @@ -49,6 +49,15 @@ def _file_config(filename: str) -> Dict: return yaml.load(handle.read(), Loader=yaml.SafeLoader) or {} +def _running_inside_container() -> bool: + env = os.environ.keys() + return ( + os.path.exists("/.dockerenv") + or "KUBERNETES_SERVICE_HOST" in env + or "container" in env # set by lxc/podman + ) + + def _read_config() -> Dict: ret = _file_config("config.yaml.dist") if os.path.isfile("config.yaml"): @@ -57,8 +66,8 @@ def _read_config() -> Dict: logger.warning( "'config.yaml' should be a file, not a directory, skipping" ) - if os.path.exists("/.dockerenv"): - ret = _merge(ret, _docker_config()) + if _running_inside_container(): + ret = _merge(ret, _container_config()) return ret