script looks for open ports
This commit is contained in:
parent
f447d68970
commit
e5a970428f
1 changed files with 11 additions and 0 deletions
|
@ -27,6 +27,13 @@ def extract_ports_from_compose(file_path):
|
||||||
|
|
||||||
return ports
|
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():
|
def check_port_conflicts():
|
||||||
"""Check for port conflicts within each docker group."""
|
"""Check for port conflicts within each docker group."""
|
||||||
base_dir = Path('.')
|
base_dir = Path('.')
|
||||||
|
@ -40,6 +47,7 @@ def check_port_conflicts():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
group_ports = {} # port -> [service_files]
|
group_ports = {} # port -> [service_files]
|
||||||
|
all_used_ports = set()
|
||||||
|
|
||||||
# Find all compose files in this group
|
# Find all compose files in this group
|
||||||
for compose_file in group_path.rglob('compose.yaml'):
|
for compose_file in group_path.rglob('compose.yaml'):
|
||||||
|
@ -47,6 +55,7 @@ def check_port_conflicts():
|
||||||
ports = extract_ports_from_compose(compose_file)
|
ports = extract_ports_from_compose(compose_file)
|
||||||
|
|
||||||
for port in ports:
|
for port in ports:
|
||||||
|
all_used_ports.add(port)
|
||||||
if port not in group_ports:
|
if port not in group_ports:
|
||||||
group_ports[port] = []
|
group_ports[port] = []
|
||||||
group_ports[port].append(f"{group}/{service_name}")
|
group_ports[port].append(f"{group}/{service_name}")
|
||||||
|
@ -54,7 +63,9 @@ def check_port_conflicts():
|
||||||
# Check for conflicts within this group
|
# Check for conflicts within this group
|
||||||
for port, services in group_ports.items():
|
for port, services in group_ports.items():
|
||||||
if len(services) > 1:
|
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"❌ 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
|
conflicts_found = True
|
||||||
|
|
||||||
if group_ports and not any(len(services) > 1 for services in group_ports.values()):
|
if group_ports and not any(len(services) > 1 for services in group_ports.values()):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue