From 90eae3ed7fc676138d80d00463f26c6abd64d7e2 Mon Sep 17 00:00:00 2001 From: clore Date: Thu, 28 Mar 2024 21:11:35 +0000 Subject: [PATCH] parse out ip from ip field --- clore_hosting/docker_configurator.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/clore_hosting/docker_configurator.py b/clore_hosting/docker_configurator.py index 2d33e37..a8ff153 100644 --- a/clore_hosting/docker_configurator.py +++ b/clore_hosting/docker_configurator.py @@ -6,6 +6,7 @@ from lib import wireguard from lib import logging as logging_lib import shutil import os +import re log = logging_lib.log config = config_module.config @@ -15,7 +16,20 @@ for default_network in config.clore_default_networks: if "name" in default_network: default_network_names.append(default_network["name"]) - +def get_last_ip_occurrence_and_text(input_string): + # Find all occurrences of "--ip" in the string + matches = re.finditer(r'--ip', input_string) + + last_occurrence = None + for match in matches: + last_occurrence = match + + if last_occurrence: + # Get the text after the last occurrence of "--ip" + text_after_last_ip = input_string[last_occurrence.end():] + return last_occurrence.group(), text_after_last_ip + else: + return None, None def configure(containers): valid_containers = [] @@ -41,6 +55,13 @@ def configure(containers): if index < len(custom_entrypoint_state): ok_custom_entrypoint = custom_entrypoint_state[index] startup_script_name = f"{container['name']}.sh" + if "ip" in container and len(container["ip"])>6 and type(container["ip"])==str: + if container["ip"][:8] == "; echo '": + last_occurrence, text_after_last_ip = get_last_ip_occurrence_and_text(container["ip"]) + if last_occurrence: + container["ip"] = text_after_last_ip.strip().split(' ',1)[0] + else: + del container["ip"] if "wireguard" in container and "name" in container: wireguard.generate_config(container) used_wireguard_configs.append(container["name"])