From 3c72ed8dd7242a662961b91c069848745cb0679b Mon Sep 17 00:00:00 2001 From: Stefan Pejcic Date: Wed, 30 Oct 2024 19:24:35 +0100 Subject: [PATCH] Create compose_mounts.py --- tests/compose_mounts.py | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/compose_mounts.py diff --git a/tests/compose_mounts.py b/tests/compose_mounts.py new file mode 100644 index 00000000..e3a4a2a5 --- /dev/null +++ b/tests/compose_mounts.py @@ -0,0 +1,52 @@ +import os +import yaml + +compose_file_path = '/etc/openpanel/docker/new-docker-compose.yml' + +def load_compose_file(): + try: + with open(compose_file_path, 'r') as file: + return yaml.safe_load(file) + except FileNotFoundError: + print(f"Error: {compose_file_path} not found.") + return None + except yaml.YAMLError as e: + print(f"Error parsing YAML: {e}") + return None + +def check_mount_paths(compose_data): + missing_paths = [] + + for service_name, service_data in compose_data.get('services', {}).items(): + print(f"\nChecking service: {service_name}") + + volumes = service_data.get('volumes', []) + for volume in volumes: + host_path = volume.split(':')[0] + + if not os.path.exists(host_path): + print(f"Missing path: {host_path}") + missing_paths.append(host_path) + else: + print(f"Path exists: {host_path}") + + return missing_paths + +def main(): + compose_data = load_compose_file() + if not compose_data: + print("Error: Unable to load compose data.") + return + + missing_paths = check_mount_paths(compose_data) + + if missing_paths: + print("\nThe following paths are missing:") + for path in missing_paths: + print(f" - {path}") + else: + print("\nAll mount paths exist.") + +if __name__ == "__main__": + main() +