feat(docker): add async port change and docker compose reload for services

- Introduce async `change_port` to update service port and reload docker compose
- Add `run_docker_command` for running docker compose commands asynchronously
- Implement `_get_random_port` utility for selecting available ports
- Refactor service discovery and port change logic to use new async methods
- Update proxy and manager logic to support new port change workflow
This commit is contained in:
2026-04-13 20:33:14 +02:00 Unverified
parent 7b540cd0b5
commit 7d176fad39
8 changed files with 90 additions and 30 deletions
+13
View File
@@ -1,6 +1,19 @@
import socket
from collections.abc import Mapping
def _get_random_port() -> int:
# os automatically assigns an available port when binding to port 0, so we can use that to find a free port
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(('', 0))
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
port = s.getsockname()[1]
return port
except Exception as e:
raise RuntimeError(f"Could not find an available port: {e}")
def _get_service_port(mapping: str | int | Mapping[str, object]) -> int | None:
if isinstance(mapping, int):
return mapping