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
+17 -7
View File
@@ -1,27 +1,37 @@
import uuid
from pathlib import Path
from integrations import docker
from integrations.docker import DockerContainer
from services.mitmproxy.models import ServiceConfig
from integrations.docker.ports import _get_random_port
async def create_proxy(
port: int,
name: str,
service: ServiceConfig,
service: DockerContainer,
code: str,
services: list[DockerContainer]
) -> int:
"""
Utility function that will:
- run ``integrations/docker`` utilities to change the old port of original service to a random one
- write ``code`` into ``/tmp/theplug/{random}.py``
/- write ``code`` into ``/tmp/theplug/{random}.py``
- start a subprocess via asyncio
- return the proxy infos (pid, )
"""
path = Path("/tmp/theplug/{random}.py".format(random=str(uuid.uuid4())))
path = Path(f"/tmp/theplug/{service["name"]}.py")
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(code, encoding="utf-8")
# da qui bisogna:
# scegliere una porta random alla quale spostare il docker
# modificare il docker via integrations.docker.editor.change_port ( service.folder, service.name, port, random_nuova_port )
random_port = _get_random_port()
docker.editor.change_port(
service["name"],
service["folder"],
port,
random_port,
)
return 0
-5
View File
@@ -1,5 +0,0 @@
from typing import TypedDict
class ServiceConfig(TypedDict):
port: int