diff --git a/monitoring/docker-exporter/exporter.py b/monitoring/docker-exporter/exporter.py index 1be0bdc..1a98d42 100644 --- a/monitoring/docker-exporter/exporter.py +++ b/monitoring/docker-exporter/exporter.py @@ -261,12 +261,17 @@ def expand_compose_path(path_value, project_root): raw = raw.replace("${PROJECT_ROOT}", project_root).replace("$PROJECT_ROOT", project_root) return os.path.expandvars(raw) +def get_project_root_from_script(script_path): + if not script_path: + return os.getcwd() + return os.path.dirname(os.path.abspath(script_path)) + # --- Compose parsing --- def get_compose_files_from_script(script_path): files = [] if not os.path.exists(script_path): return files - base_dir = os.path.dirname(script_path) + base_dir = get_project_root_from_script(script_path) try: with open(script_path) as f: content = f.read() @@ -378,7 +383,7 @@ def check_containers(): CONTAINER_UPDATE.clear() project_name = parse_project_name_from_script(SERVICES_UP_SCRIPT) - project_root = os.path.dirname(SERVICES_UP_SCRIPT) + project_root = get_project_root_from_script(SERVICES_UP_SCRIPT) compose_files = get_compose_files_from_script(SERVICES_UP_SCRIPT) svc_map = parse_compose_services(compose_files, project_name, project_root) @@ -413,7 +418,7 @@ def check_containers(): def dump_service_image_mapping(): project_name = parse_project_name_from_script(SERVICES_UP_SCRIPT) - project_root = os.path.dirname(SERVICES_UP_SCRIPT) + project_root = get_project_root_from_script(SERVICES_UP_SCRIPT) compose_files = get_compose_files_from_script(SERVICES_UP_SCRIPT) svc_map = parse_compose_services(compose_files, project_name, project_root) mapping = {name: data["image"] for name, data in sorted(svc_map.items())}