Survey true upstream default branch instead of local abra checkout

This commit is contained in:
notplants
2026-11-23 22:46:29 +00:00
parent 7ead707989
commit 4223ef4c7a
4 changed files with 117 additions and 18 deletions
+63 -6
View File
@@ -15,11 +15,11 @@ kept getting skipped, and why a CVE sweep reported it as unknown.
This reads the compose files directly and queries the registries itself, so a digest pin is just a
digest pin. Output is JSON (default) or a table.
resolve-images.py <recipe> [--ssh HOST] [--recipe-dir DIR] [--table] [--only IMAGE]
resolve-images.py <recipe> --upstream-default [--recipe-dir DIR] [--table] [--only IMAGE]
The cc-ci host has no python3, so `--ssh cc-ci` reads the compose files from that host's checkout
over ssh and does the resolving locally. That keeps the source of truth the SAME tree abra and CI
use, rather than a second copy that can drift.
Use `--upstream-default` on the cc-ci host for weekly surveys. It fetches the real coop-cloud
default branch and reads compose from that exact commit, independent of the mirror default or
the local abra checkout. `--ssh` remains available for reading an existing remote checkout.
TAG SHAPES. Registries mix wildly different tag conventions in one repo, so "newest" is meaningless
without a shape. Each tag is reduced to a signature by replacing digit runs with '#':
@@ -440,6 +440,54 @@ def resolve(ref: str) -> dict:
return out
def compose_images_upstream(recipe: str, recipe_dir: str) -> tuple[list[str], dict]:
"""Read compose from the true upstream default branch, regardless of local HEAD or mirror default.
Fetching updates the object database only; it never checks out a branch or changes the
recipe working tree. An unavailable or ambiguous upstream is an error, never an empty
image list that a caller might mistake for up-to-date.
"""
base = os.path.join(recipe_dir, recipe)
if not os.path.isdir(os.path.join(base, ".git")):
raise RuntimeError(f"recipe checkout missing: {base}")
upstream = f"https://git.coopcloud.tech/coop-cloud/{recipe}.git"
remote = subprocess.run(["git", "-C", base, "remote", "get-url", "upstream"],
capture_output=True, text=True)
if remote.returncode == 0 and remote.stdout.strip():
upstream = remote.stdout.strip()
head = subprocess.run(["git", "ls-remote", "--symref", upstream, "HEAD"],
capture_output=True, text=True, timeout=120)
if head.returncode != 0:
raise RuntimeError(f"cannot query true upstream default branch: {head.stderr.strip()[:200]}")
match = re.search(r"^ref:\s+(refs/heads/[^\s]+)\s+HEAD$", head.stdout, re.M)
sha = re.search(r"^([0-9a-f]{40})\s+HEAD$", head.stdout, re.M)
if not match or not sha:
raise RuntimeError(f"true upstream default branch ambiguous for {recipe}")
branch, commit = match.group(1), sha.group(1)
fetched = subprocess.run(["git", "-C", base, "fetch", "--no-tags", "--quiet", upstream, branch],
capture_output=True, text=True, timeout=180)
if fetched.returncode != 0:
raise RuntimeError(f"cannot fetch true upstream {branch}: {fetched.stderr.strip()[:200]}")
present = subprocess.run(["git", "-C", base, "cat-file", "-e", f"{commit}^{{commit}}"],
capture_output=True)
if present.returncode != 0:
raise RuntimeError(f"true upstream changed during fetch; retry {recipe}")
files = subprocess.run(["git", "-C", base, "ls-tree", "-r", "--name-only", commit],
capture_output=True, text=True, check=True).stdout.splitlines()
refs = []
for name in files:
if "/" in name or not re.fullmatch(r"compose[^/]*\.yml", name) or name == "compose.ccci.yml":
continue
content = subprocess.run(["git", "-C", base, "show", f"{commit}:{name}"],
capture_output=True, text=True, check=True).stdout
for image in IMAGE_RE.findall(content):
if image not in refs:
refs.append(image)
if not refs:
raise RuntimeError(f"no image refs in true upstream {branch} at {commit[:8]} for {recipe}")
return refs, {"url": upstream, "branch": branch, "commit": commit}
def compose_images_ssh(recipe: str, host: str, recipe_dir: str) -> list[str]:
"""Same as compose_images, but the recipe tree lives on another host (cc-ci has no python3)."""
# NB: no shell-quoting of the directory — it may legitimately start with ~ or $HOME, and
@@ -482,18 +530,27 @@ def main() -> int:
help="read the recipe's compose files from HOST over ssh (e.g. --ssh cc-ci); "
"resolving still happens locally")
ap.add_argument("--recipe-dir", default=RECIPE_DIR)
ap.add_argument("--upstream-default", action="store_true",
help="fetch and read the true coop-cloud default branch, ignoring local HEAD and mirror default")
ap.add_argument("--table", action="store_true", help="human-readable table instead of JSON")
ap.add_argument("--only", default=None, help="resolve just the images whose ref contains this")
a = ap.parse_args()
rdir = a.recipe_dir if a.recipe_dir != RECIPE_DIR or not a.ssh else "~/.abra/recipes"
refs = (compose_images_ssh(a.recipe, a.ssh, rdir) if a.ssh
else compose_images(a.recipe, a.recipe_dir))
if a.upstream_default and a.ssh:
ap.error("--upstream-default must run on the host with the recipe checkout")
source = None
if a.upstream_default:
refs, source = compose_images_upstream(a.recipe, a.recipe_dir)
else:
refs = (compose_images_ssh(a.recipe, a.ssh, rdir) if a.ssh
else compose_images(a.recipe, a.recipe_dir))
if a.only:
refs = [r for r in refs if a.only in r]
results = [resolve(r) for r in refs]
report = {
"recipe": a.recipe,
"source": source,
"images": results,
"upgrades_available": [r["ref"] for r in results if r["upgrade_available"]],
"unresolved": [r["ref"] for r in results if r["status"].startswith(("error", "skipped", "unverifiable"))],