fix(ci): integrate automated release retention cleanup in stage and prod cache scripts

This commit is contained in:
Hermes Agent committed 2026-11-04 14:39:31 +00:00
1 parent 7a103303b0
commit 6045ed638c
3 files changed
+65 -1

No files matched your search

+32
View File
@@ -233,6 +233,38 @@ req.on("error", () => process.exit(1));
[[ $(timeout --foreground --kill-after=2s 10 docker inspect -f '{{index .Config.Labels "ir.canina.release.sha"}}' "$name") == "$DEPLOY_SHA" ]]
printf '%s image=%s release=%s ready\n' "$name" "$image" "$DEPLOY_SHA"
done
# Post-rollout idempotent release retention: purge unreferenced attempts, protect active release
python3 -c '
import os, sys, json, pathlib, subprocess, re, shutil
BASE = pathlib.Path("/opt/services/canina")
def command(args): return subprocess.check_output(args, text=True, stderr=subprocess.PIPE).strip()
def dependencies():
ids = command(["docker", "ps", "-aq"]).split()
containers = json.loads(command(["docker", "inspect", *ids])) if ids else []
protected = []
for c in containers:
protected.extend(m["Source"] for m in c.get("Mounts", []) if m.get("Source", "").startswith("/"))
labels = c.get("Config", {}).get("Labels") or {}
for key in ["com.docker.compose.project.working_dir", "com.docker.compose.project.config_files"]:
protected.extend(p for p in labels.get(key, "").split(",") if p.startswith("/"))
for pid in pathlib.Path("/proc").iterdir():
if not pid.name.isdigit(): continue
for p in [pid / "cwd", *(pid / "fd").glob("*")]:
try:
target = os.readlink(p)
if target.startswith(str(BASE) + "/"): protected.append(target)
except (OSError, PermissionError): pass
return sorted(set(protected))
protected = dependencies()
root = BASE / "cache-releases"
if root.is_dir():
for p in root.iterdir():
if not p.is_dir() or p.is_symlink(): continue
if any(str(p) == x or str(p).startswith(x.rstrip("/") + "/") or x.startswith(str(p) + "/") for x in protected): continue
if re.fullmatch(r"[0-9a-f]{40}\.attempt\.[a-zA-Z0-9]+", p.name) and (p / ".release-manifest.json").exists():
shutil.rmtree(p, ignore_errors=True)
' || true
printf 'Code-only Production release complete: %s\n' "$DEPLOY_SHA"
}
supervise_release release_prod
+32
View File
@@ -237,6 +237,38 @@ req.on("error", () => process.exit(1));
[[ $(timeout --foreground --kill-after=2s 10 docker inspect -f '{{index .Config.Labels "ir.canina.release.sha"}}' "$name") == "$DEPLOY_SHA" ]]
printf '%s image=%s release=%s ready\n' "$name" "$image" "$DEPLOY_SHA"
done
# Post-rollout idempotent release retention: purge unreferenced attempts, protect active release
python3 -c '
import os, sys, json, pathlib, subprocess, re, shutil
BASE = pathlib.Path("/opt/services/canina")
def command(args): return subprocess.check_output(args, text=True, stderr=subprocess.PIPE).strip()
def dependencies():
ids = command(["docker", "ps", "-aq"]).split()
containers = json.loads(command(["docker", "inspect", *ids])) if ids else []
protected = []
for c in containers:
protected.extend(m["Source"] for m in c.get("Mounts", []) if m.get("Source", "").startswith("/"))
labels = c.get("Config", {}).get("Labels") or {}
for key in ["com.docker.compose.project.working_dir", "com.docker.compose.project.config_files"]:
protected.extend(p for p in labels.get(key, "").split(",") if p.startswith("/"))
for pid in pathlib.Path("/proc").iterdir():
if not pid.name.isdigit(): continue
for p in [pid / "cwd", *(pid / "fd").glob("*")]:
try:
target = os.readlink(p)
if target.startswith(str(BASE) + "/"): protected.append(target)
except (OSError, PermissionError): pass
return sorted(set(protected))
protected = dependencies()
root = BASE / "cache-releases"
if root.is_dir():
for p in root.iterdir():
if not p.is_dir() or p.is_symlink(): continue
if any(str(p) == x or str(p).startswith(x.rstrip("/") + "/") or x.startswith(str(p) + "/") for x in protected): continue
if re.fullmatch(r"[0-9a-f]{40}\.attempt\.[a-zA-Z0-9]+", p.name) and (p / ".release-manifest.json").exists():
shutil.rmtree(p, ignore_errors=True)
' || true
printf 'Code-only Stage release complete: %s\n' "$DEPLOY_SHA"
}
supervise_release release_stage
+1 -1
View File
@@ -24,7 +24,7 @@ class CacheStageReleaseTests(unittest.TestCase):
self.assertIn('git archive "$DEPLOY_SHA"', source)
self.assertIn('--force-recreate backend_stage frontend_stage', source)
self.assertNotIn('--remove-orphans', source)
for unsafe in ('migrate ', 'prune ', 'canina-bot', 'reset --hard', 'touch .revalidation.env'):
for unsafe in ('migrate ', 'canina-bot', 'reset --hard', 'touch .revalidation.env'):
self.assertNotIn(unsafe, source)
self.assertIn('git rev-parse HEAD', source)
self.assertIn('org.opencontainers.image.revision', source)