[SPRINT-V1][B] Drift v2: различаем дрейф контейнера и расхождение compose-файла с git (найдено 20+ CT с несинхронными файлами)
This commit is contained in:
1 parent
6a4aa8e7b8
commit
87d34cb609
2 files changed
+47
-8
No files matched your search
@@ -323,8 +323,38 @@ def check_compose_drift():
|
||||
add("high", "drift compose", "; ".join(drift[:8]),
|
||||
"живое состояние расходится с git — восстановление из репозитория не сработает",
|
||||
"python3 ops/scripts/check-compose-parity.py <ct> и обновить compose")
|
||||
add("info", "compose-паритет", "проверено CT: %d, с расхождениями: %d, ошибок: %d"
|
||||
% (checked, len(drift), errors), "соответствие репозиторию", "—")
|
||||
|
||||
# --- (2) живой compose-файл на CT vs файл в git ---
|
||||
file_drift = []
|
||||
for d in sorted(os.listdir(base)):
|
||||
if not d.startswith("ct"):
|
||||
continue
|
||||
ct = d[2:]
|
||||
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:
|
||||
continue
|
||||
live = sh("pct exec %s -- sh -c 'cat %s/docker-compose.yml 2>/dev/null'" % (ct, wd), 40)
|
||||
if not live:
|
||||
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))
|
||||
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")
|
||||
|
||||
add("info", "compose-паритет", "проверено CT: %d, контейнер-дрейф: %d, файл≠git: %d, ошибок: %d"
|
||||
% (checked, len(drift), len(file_drift), errors), "соответствие репозиторию", "—")
|
||||
|
||||
|
||||
def check_backup_freshness():
|
||||
|
||||
Reference in new issue
Block a user