mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2026-02-07 21:34:06 +00:00
backup: support all valid docker compose file names
Detect compose files case-insensitively and support: - compose.yml / compose.yaml - docker-compose.yml / docker-compose.yaml Replace hard-coded docker-compose.yml checks with a shared finder helper and extend unit tests accordingly. https://chatgpt.com/share/69873720-d444-800f-99f7-f7799fc10c0b
This commit is contained in:
@@ -4,7 +4,7 @@ import os
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
def _build_compose_cmd(project_dir: str, passthrough: List[str]) -> List[str]:
|
||||
@@ -30,6 +30,37 @@ def _build_compose_cmd(project_dir: str, passthrough: List[str]) -> List[str]:
|
||||
raise RuntimeError("Neither 'compose' nor 'docker' found in PATH")
|
||||
|
||||
|
||||
def _find_compose_file(project_dir: str) -> Optional[Path]:
|
||||
"""
|
||||
Detect a compose file in `project_dir` (case-insensitive).
|
||||
|
||||
Supported names:
|
||||
- compose.yml / compose.yaml
|
||||
- docker-compose.yml / docker-compose.yaml
|
||||
"""
|
||||
pdir = Path(project_dir)
|
||||
if not pdir.is_dir():
|
||||
return None
|
||||
|
||||
# Map lowercase filename -> actual Path (preserves original casing)
|
||||
by_lower = {p.name.lower(): p for p in pdir.iterdir() if p.is_file()}
|
||||
|
||||
# Preferred order (policy decision)
|
||||
candidates = [
|
||||
"docker-compose.yml",
|
||||
"docker-compose.yaml",
|
||||
"compose.yml",
|
||||
"compose.yaml",
|
||||
]
|
||||
|
||||
for name in candidates:
|
||||
found = by_lower.get(name)
|
||||
if found is not None:
|
||||
return found
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def hard_restart_docker_services(dir_path: str) -> None:
|
||||
print(f"Hard restart compose services in: {dir_path}", flush=True)
|
||||
|
||||
@@ -44,7 +75,8 @@ def hard_restart_docker_services(dir_path: str) -> None:
|
||||
|
||||
|
||||
def handle_docker_compose_services(
|
||||
parent_directory: str, hard_restart_required: list[str]
|
||||
parent_directory: str,
|
||||
hard_restart_required: list[str],
|
||||
) -> None:
|
||||
for entry in os.scandir(parent_directory):
|
||||
if not entry.is_dir():
|
||||
@@ -52,11 +84,12 @@ def handle_docker_compose_services(
|
||||
|
||||
dir_path = entry.path
|
||||
name = os.path.basename(dir_path)
|
||||
compose_file = os.path.join(dir_path, "docker-compose.yml")
|
||||
|
||||
print(f"Checking directory: {dir_path}", flush=True)
|
||||
if not os.path.isfile(compose_file):
|
||||
print("No docker-compose.yml found. Skipping.", flush=True)
|
||||
|
||||
compose_file = _find_compose_file(dir_path)
|
||||
if compose_file is None:
|
||||
print("No supported compose file found. Skipping.", flush=True)
|
||||
continue
|
||||
|
||||
if name in hard_restart_required:
|
||||
|
||||
Reference in New Issue
Block a user