Files
thePlug/app/services/mitmproxy/manager.py
T
reloia 7d176fad39 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
2026-04-13 20:33:14 +02:00

38 lines
1.1 KiB
Python

from pathlib import Path
from integrations import docker
from integrations.docker import DockerContainer
from integrations.docker.ports import _get_random_port
async def create_proxy(
port: int,
service: DockerContainer,
code: str,
) -> 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``
- start a subprocess via asyncio
- return the proxy infos (pid, )
"""
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