[SPRINT-V1][B] CT110: снимок compose перегенерирован (8 сервисов, 0 расхождений), drift-детектор различает мультипроектные CT
This commit is contained in:
1 parent
87d34cb609
commit
f91f179dd7
4 files changed
+38
-195
No files matched your search
@@ -326,6 +326,7 @@ def check_compose_drift():
|
||||
|
||||
# --- (2) живой compose-файл на CT vs файл в git ---
|
||||
file_drift = []
|
||||
multi_project = []
|
||||
for d in sorted(os.listdir(base)):
|
||||
if not d.startswith("ct"):
|
||||
continue
|
||||
@@ -333,25 +334,38 @@ def check_compose_drift():
|
||||
repo_file = os.path.join(base, d, "docker-compose.yml")
|
||||
if not os.path.exists(repo_file):
|
||||
continue
|
||||
wd = sh("pct exec %s -- sh -c 'c=$(docker ps -q | head -1); [ -n \"$c\" ] && docker inspect $c "
|
||||
"--format \"{{index .Config.Labels \\\"com.docker.compose.project.working_dir\\\"}}\"'"
|
||||
% ct, 40).strip()
|
||||
if not wd or wd.startswith("<") or "/" not in wd:
|
||||
wds = sh("pct exec %s -- sh -c 'docker ps -q 2>/dev/null | head -20 | xargs -r docker inspect "
|
||||
"--format \"{{index .Config.Labels \\\"com.docker.compose.project.working_dir\\\"}}\" 2>/dev/null "
|
||||
"| sort -u'" % ct, 60).split()
|
||||
wds = [w for w in wds if w.startswith("/")]
|
||||
if not wds:
|
||||
continue
|
||||
live = sh("pct exec %s -- sh -c 'cat %s/docker-compose.yml 2>/dev/null'" % (ct, wd), 40)
|
||||
if not live:
|
||||
# мультипроектный CT: один файл в git не может повторять несколько проектов
|
||||
if len(wds) > 1:
|
||||
multi_project.append("CT%s (%d)" % (ct, len(wds)))
|
||||
continue
|
||||
|
||||
def norm(t):
|
||||
return "\n".join(x.rstrip() for x in t.splitlines()
|
||||
if x.strip() and not x.strip().startswith("#"))
|
||||
|
||||
if norm(live) != norm(open(repo_file, encoding="utf-8").read()):
|
||||
file_drift.append("CT%s (%s)" % (ct, wd))
|
||||
repo_norm = norm(open(repo_file, encoding="utf-8").read())
|
||||
matched = False
|
||||
for wd in wds:
|
||||
live = sh("pct exec %s -- sh -c 'cat %s/docker-compose.yml 2>/dev/null'" % (ct, wd), 40)
|
||||
if live and norm(live) == repo_norm:
|
||||
matched = True
|
||||
break
|
||||
if not matched:
|
||||
file_drift.append("CT%s (%d каталогов)" % (ct, len(wds)))
|
||||
if file_drift:
|
||||
add("medium", "compose-файл ≠ git", "; ".join(file_drift[:8]),
|
||||
"на CT другая версия compose, чем в репозитории — правки не закоммичены",
|
||||
"diff <(pct exec <ct> cat <dir>/docker-compose.yml) deploy/ct<N>/docker-compose.yml")
|
||||
if multi_project:
|
||||
add("info", "мультипроектные CT", "; ".join(multi_project[:8]),
|
||||
"несколько compose-проектов в одном CT — файл в git является снимком",
|
||||
"учитывать при восстановлении: поднимать проекты по отдельности")
|
||||
|
||||
add("info", "compose-паритет", "проверено CT: %d, контейнер-дрейф: %d, файл≠git: %d, ошибок: %d"
|
||||
% (checked, len(drift), len(file_drift), errors), "соответствие репозиторию", "—")
|
||||
|
||||
Reference in new issue
Block a user