feat: troppa roba davvero
This commit is contained in:
@@ -2,8 +2,9 @@ import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
import yaml
|
||||
from integrations.docker.models import DockerContainer
|
||||
from integrations.docker.ports import _get_service_binding
|
||||
|
||||
from app.integrations.docker.models import DockerContainer, DockerPortBinding
|
||||
from app.integrations.docker.ports import _get_service_binding
|
||||
|
||||
COMPOSE_NAMES = (
|
||||
"compose.yml",
|
||||
@@ -12,24 +13,43 @@ COMPOSE_NAMES = (
|
||||
"docker-compose.yaml",
|
||||
)
|
||||
|
||||
type ComposeDocument = dict[str, object]
|
||||
|
||||
|
||||
def _get_visible_folders(directory: Path) -> list[Path]:
|
||||
return [
|
||||
p
|
||||
for p in Path(directory).iterdir()
|
||||
if p.is_dir() and not p.name.startswith(".")
|
||||
]
|
||||
try:
|
||||
entries = list(Path(directory).iterdir())
|
||||
except OSError:
|
||||
return []
|
||||
|
||||
folders: list[Path] = []
|
||||
for entry in entries:
|
||||
if entry.name.startswith("."):
|
||||
continue
|
||||
try:
|
||||
if entry.is_dir():
|
||||
folders.append(entry)
|
||||
except OSError:
|
||||
continue
|
||||
|
||||
return folders
|
||||
|
||||
|
||||
def find_docker_compose(path: Path) -> tuple[dict, Path] | None:
|
||||
if not path or not path.is_dir():
|
||||
def find_docker_compose(path: Path) -> tuple[ComposeDocument, Path] | None:
|
||||
try:
|
||||
if not path or not path.is_dir():
|
||||
return None
|
||||
except OSError:
|
||||
return None
|
||||
|
||||
for name in COMPOSE_NAMES:
|
||||
file = path / name
|
||||
if file.is_file():
|
||||
content = yaml.safe_load(file.read_text()) or {}
|
||||
return content, file
|
||||
try:
|
||||
if file.is_file():
|
||||
content = yaml.safe_load(file.read_text()) or {}
|
||||
return content, file
|
||||
except OSError:
|
||||
continue
|
||||
|
||||
return None
|
||||
|
||||
@@ -42,7 +62,7 @@ def get_services(folder: Path) -> list[DockerContainer] | None:
|
||||
|
||||
docker_compose, _ = compose_data
|
||||
compose_services = docker_compose.get("services") or {}
|
||||
if not compose_services:
|
||||
if not isinstance(compose_services, dict) or not compose_services:
|
||||
return None
|
||||
|
||||
for service_name, config in compose_services.items():
|
||||
@@ -50,7 +70,7 @@ def get_services(folder: Path) -> list[DockerContainer] | None:
|
||||
if not isinstance(mappings, list) or not mappings:
|
||||
continue
|
||||
|
||||
bindings = [
|
||||
bindings: list[DockerPortBinding] = [
|
||||
{"published": published, "host": host}
|
||||
for published, host in (
|
||||
_get_service_binding(mapping) for mapping in mappings
|
||||
@@ -76,7 +96,10 @@ def get_all_services_in_dir(
|
||||
directory: str | Path,
|
||||
) -> list[DockerContainer]:
|
||||
path = Path(directory)
|
||||
if not path.is_dir():
|
||||
try:
|
||||
if not path.is_dir():
|
||||
return []
|
||||
except OSError:
|
||||
return []
|
||||
|
||||
services: list[DockerContainer] = []
|
||||
@@ -88,7 +111,10 @@ def get_all_services_in_dir(
|
||||
return services
|
||||
|
||||
|
||||
async def run_docker_command(file: Path, command: list[str]) -> dict | None:
|
||||
async def run_docker_command(
|
||||
file: Path,
|
||||
command: list[str],
|
||||
) -> dict[str, str] | None:
|
||||
if not command:
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user