Files
computer-playbook/cli/deploy/test/storage.py
T
kevinveenbirkenbach daab131b71 ci: auto-detect storage constraints and enable aggressive docker cleanup
- add storage detection utility for CI (DockerRootDir free space check)
- automatically set STORAGE_CONSTRAINED in cli.deploy.test when disk < 100 GiB
- forward STORAGE_CONSTRAINED into generated CI inventory via --vars
- introduce global STORAGE_CONSTRAINED default in group_vars
- run aggressive docker prune handler only in storage constrained mode
- mark CI inventory environment as development

https://chatgpt.com/share/696d6a11-2d90-800f-83e8-a30f6229e2e0
2026-01-19 00:17:31 +01:00

44 lines
1.1 KiB
Python

# cli/deploy/test/storage.py
from __future__ import annotations
from .compose import Compose
def detect_storage_constrained(compose: Compose, *, threshold_gib: int = 100) -> bool:
"""
Return True if the filesystem that contains DockerRootDir has less than
`threshold_gib` GiB free space.
We intentionally measure the DockerRootDir filesystem because this is where
images/volumes/build cache usually grow (especially in CI / Docker-in-Docker).
"""
threshold_bytes = threshold_gib * 1024 * 1024 * 1024
cmd = [
"sh",
"-lc",
r"""
set -euo pipefail
root="$(docker info -f '{{.DockerRootDir}}' 2>/dev/null || true)"
if [ -z "${root}" ]; then
root="/var/lib/docker"
fi
free="$(df -PB1 "${root}" | awk 'NR==2{print $4}')"
printf "%s\n" "${free}"
""",
]
r = compose.exec(cmd, check=False, capture=True)
if r.returncode != 0:
# If we can't determine free space, do not force constrained mode.
return False
txt = (r.stdout or "").strip()
try:
free_bytes = int(txt)
except ValueError:
return False
return free_bytes < threshold_bytes