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
+11 -3
View File
@@ -8,7 +8,6 @@ from pymongo import ReturnDocument
from core.mongodb import get_database
from models.proxy import ProxyDocument, ProxyUpdateInput
from models.service import ServiceEndpointDocument
from services.mitmproxy.models import ServiceConfig
COLLECTION_NAME = "proxies"
@@ -38,16 +37,25 @@ async def ensure_proxy_indexes() -> None:
async def create_proxy(
proxy_port: int,
name: str,
service: ServiceConfig,
upstream_port: int,
code: str,
) -> ProxyDocument:
"""
Saves a Proxy to the database.
:param proxy_port: the port the proxy is listening on
:param name: the name of the service
:param upstream_port: the upstream port the proxy is forwarding to
:param code: the code of the service
:return:
"""
now = _utcnow()
proxy = ProxyDocument(
proxy_port=proxy_port,
name=name,
code=code,
service=ServiceEndpointDocument(
port=service["port"],
port=upstream_port,
),
created_at=now,
updated_at=now,