script looks for open ports

This commit is contained in:
rebel onion 2025-06-21 16:14:29 -05:00
parent f447d68970
commit e5a970428f

View file

@ -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()):