ops: protect mounted test artifacts and document capacity adoption gate
Owned disk maintenance only / maintenance (push) Successful in 11s

This commit is contained in:
Canina Hermes committed 2026-11-19 07:33:24 +00:00
1 parent 6dec2c1469
commit 63ced7b44a
3 files changed
+41 -2

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
# Owned disk maintenance
Installed only by `.gitea/workflows/managed-disk.yml` on the dedicated ops branch. This workflow never calls an application deployment. The daily system timer manages only unused >24h Docker builder cache (no --all, images, volumes or logs) and explicit marked test children under `/opt/services/canina/.managed-disk/tests`. Unmarked directories, Git/env/dependency-bearing trees, symlinks, mounts and open files are preserved. Tests use temporary roots, not privileged installer fixtures.
Shared heavy work entry point:
```
python3 -B /opt/services/canina/.managed-disk/managed-disk.py build COMMAND ARG...
```
Holds `.managed-disk/heavy.lock` for the entire subprocess and requires >=20GiB available immediately before execution. This is an installed opt-in guard, NOT a global reservation: existing application build dispatchers do not yet acquire it. Migration of each dispatcher belongs in its reviewed release CI. Do not claim shared serialization is complete until all producers adopt it. Current lower headroom intentionally rejects new guarded heavy builds.
No existing test artifacts are automatically marked. New disposable tests may create `.disposable-test` containing exactly `canina-managed-test-v1\n`; expiry is seven days. Tests must acquire the same lock when creating/using that namespace. Existing source/donor/archive paths are outside this policy.
## Container log gate
Fresh inspection confirms older containers including Traefik, Nexus and databases have `json-file` with empty options. The daemon already has defaults; these do not retrofit existing containers. The exact per-service Compose option for the next separately authorized release is:
```yaml
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
```
Do not apply a broad override or recreate these services now. Traefik/DB/VPN downtime is not authorized. No live log truncation is permitted. Each affected service's managed Compose source must receive the scoped option through its own existing release path, followed by explicit downtime approval and a verified recreation. This document is a configuration recommendation, not an installed log-rotation change.
No historical backup staging, cloud history, named volume, source checkout or protected review image is retired by this maintenance.
+7 -2
View File
@@ -4,7 +4,7 @@ import pathlib,os,time,shutil,fcntl,subprocess,json,sys
BASE=pathlib.Path('/opt/services/canina/.managed-disk')
RESERVE=20*1024**3
def retire(root,now=None):
def retire(root,now=None,protected=()):
root=pathlib.Path(root);now=time.time() if now is None else now
if root.is_symlink() or root.resolve()!=root:raise RuntimeError('unsafe root')
removed=[]
@@ -13,6 +13,8 @@ def retire(root,now=None):
if p.is_symlink() or not p.is_dir() or p.resolve()!=p:continue
if not marker.is_file() or marker.is_symlink() or marker.read_text()!='canina-managed-test-v1\n':continue
if now-p.stat().st_mtime<7*86400:continue
if any(v==str(p) or v.startswith(str(p)+'/') or str(p).startswith(v.rstrip('/')+'/') for v in protected):continue
if os.path.ismount(p):continue
# Unknown/source-bearing contents are never eligible; symlinks are never followed.
if any(x.name in {'.git','.env','node_modules','vendor'} or x.is_symlink() or os.path.ismount(x) for x in p.rglob('*')):continue
users=[]
@@ -45,7 +47,10 @@ def main():
raise SystemExit(subprocess.call(sys.argv[2:]))
if busy():raise SystemExit('Active heavy work: retention deferred')
before=shutil.disk_usage(BASE).free
removed=retire(BASE/'tests')
ids=subprocess.check_output(['docker','ps','-aq'],text=True).split()
containers=json.loads(subprocess.check_output(['docker','inspect',*ids],text=True)) if ids else []
protected=[m['Source'] for c in containers for m in c['Mounts']]
removed=retire(BASE/'tests',protected=protected)
p=subprocess.run(['docker','builder','prune','--force','--filter','until=24h'],capture_output=True,text=True,timeout=300,check=True)
print(json.dumps({'removed_tests':removed,'docker_cache_result':p.stdout.strip(),'available_before':before,'available_after':shutil.disk_usage(BASE).free}))
if __name__=='__main__':main()
+5
View File
@@ -17,4 +17,9 @@ class Tests(unittest.TestCase):
try:self.assertEqual(m.retire(r),[])
finally:f.close()
self.assertEqual(m.retire(r),['busy'])
def test_mounted_artifact_is_preserved(self):
m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m)
with tempfile.TemporaryDirectory() as d:
r=pathlib.Path(d);p=r/'mounted';p.mkdir();(p/'.disposable-test').write_text('canina-managed-test-v1\n');os.utime(p,(1,1))
self.assertEqual(m.retire(r,protected=[str(p/'result')]),[])
if __name__=='__main__':unittest.main()