From e5a970428f5e0f4224146453b66ae34fc9e0bf6e Mon Sep 17 00:00:00 2001 From: rebel onion <87634197+rebelonion@users.noreply.github.com> Date: Sat, 21 Jun 2025 16:14:29 -0500 Subject: [PATCH] script looks for open ports --- scripts/check-port-conflicts.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/check-port-conflicts.py b/scripts/check-port-conflicts.py index d9fd4ac..dbbe636 100755 --- a/scripts/check-port-conflicts.py +++ b/scripts/check-port-conflicts.py @@ -27,6 +27,13 @@ def extract_ports_from_compose(file_path): return ports +def find_next_available_port(used_ports, starting_port): + """Find the next available port starting from the given port.""" + port = starting_port + while port in used_ports: + port += 1 + return port + def check_port_conflicts(): """Check for port conflicts within each docker group.""" base_dir = Path('.') @@ -40,6 +47,7 @@ def check_port_conflicts(): continue group_ports = {} # port -> [service_files] + all_used_ports = set() # Find all compose files in this group for compose_file in group_path.rglob('compose.yaml'): @@ -47,6 +55,7 @@ def check_port_conflicts(): ports = extract_ports_from_compose(compose_file) for port in ports: + all_used_ports.add(port) if port not in group_ports: group_ports[port] = [] group_ports[port].append(f"{group}/{service_name}") @@ -54,7 +63,9 @@ def check_port_conflicts(): # Check for conflicts within this group for port, services in group_ports.items(): if len(services) > 1: + suggested_port = find_next_available_port(all_used_ports, port + 1) print(f"❌ Port conflict in {group}: Port {port} used by {', '.join(services)}") + print(f"💡 Suggestion: Use port {suggested_port} for one of the conflicting services") conflicts_found = True if group_ports and not any(len(services) > 1 for services in group_ports.values()):