#!/usr/bin/env python3 """Pin the Chromium the CI box runs browser tests with, and the page renderer runners ship: write scripts/ci-chromium.json and internal/release/renderer.json. scripts/ci-chromium-pin.py VERSION DEBIAN_SNAPSHOT SECURITY_SNAPSHOT for example scripts/ci-chromium-pin.py 156.0.8078.79-1~deb13u1 20261107T024144Z 20261103T013555Z The browser is Debian 13's chromium-headless-shell, the system the box image runs, because Debian builds it for arm64 (hosted CI) and amd64 alike; Chrome for Testing has no Linux arm64 build. It is a program and some sixty libraries, not one file, so this reads the Packages indexes of trixie and trixie-security at two snapshot.debian.org timestamps and pins every package the headless shell needs that a Debian image does not already have: what Priority: required pulls in is in every Debian image, the box's too, and is left out. Each package is pinned by the SHA-256 the signed index gives it, at a snapshot URL that never changes; scripts/ci-box.py fetches and checks them and unpacks them into one tree. internal/release/renderer.json is the same browser for Linux amd64 with nothing left out: the same resolution without pruning the base, so a tree built from it runs with nothing from the host (the loader and libc included). Its packages marked "base" are the ones ci-chromium.json leaves to the image; the rest are ci-chromium.json's amd64 packages, entry for entry. The release build fetches and checks them (sha256) and builds the renderer tree; nothing downloads them at run time. Raise the pin with each Chromium security release: the newest version is at https://snapshot.debian.org/mr/binary/chromium-headless-shell/, and its first_seen there (binfiles?fileinfo=1) is the security timestamp. """ import json import lzma import os import re import sys import urllib.request ARCHES = ("amd64", "arm64") TOP = ("chromium-headless-shell", "chromium-common") # chromium-common's own dependencies are the full browser's (x11-utils for # xmessage, xdg-utils for opening links); the headless shell runs neither. SKIP = {"x11-utils", "xdg-utils"} HERE = os.path.dirname(os.path.abspath(__file__)) OUT = os.path.join(HERE, "ci-chromium.json") RENDERER_OUT = os.path.join(HERE, os.pardir, "internal", "release", "renderer.json") RENDERER_ARCH = "amd64" SNAPSHOT = "https://snapshot.debian.org/archive/%s/%s/" def fetch(url): request = urllib.request.Request(url, headers={"User-Agent": "equipo-ci-chromium-pin"}) with urllib.request.urlopen(request, timeout=300) as response: return response.read() def stanzas(text): for block in text.split("\n\n"): fields, last = {}, None for line in block.splitlines(): if line[:1] in (" ", "\t") and last: fields[last] += "\n" + line elif ":" in line: last, value = line.split(":", 1) fields[last] = value.strip() if "Package" in fields: yield fields def index(archive, stamp, suite, arch): url = SNAPSHOT % (archive, stamp) + "dists/%s/main/binary-%s/Packages.xz" % (suite, arch) packages = {} for p in stanzas(lzma.decompress(fetch(url)).decode()): p["_base"] = SNAPSHOT % (archive, stamp) packages[p["Package"]] = p return packages def relations(p): """The alternatives of each Depends and Pre-Depends group, names only.""" groups = [] for field in ("Pre-Depends", "Depends"): for group in filter(None, (g.strip() for g in p.get(field, "").split(","))): groups.append([re.split(r"[\s(\[:]", alt.strip(), maxsplit=1)[0] for alt in group.split("|")]) return groups def resolver(packages): provides = {} for name, p in packages.items(): for virtual in filter(None, (v.strip() for v in p.get("Provides", "").split(","))): provides.setdefault(re.split(r"[\s(]", virtual, maxsplit=1)[0], name) def pick(alternatives): for alt in alternatives: if alt in packages: return alt for alt in alternatives: if alt in provides: return provides[alt] raise SystemExit("no package for any of %s" % " | ".join(alternatives)) def closure(start, skip=frozenset(), prune=frozenset()): seen, todo = set(), list(start) while todo: name = todo.pop() if name in seen or name in prune: continue seen.add(name) if name in skip: continue for group in relations(packages[name]): todo.append(pick(group)) return seen return closure def archive(debian, security, arch): """Every package of trixie at the debian snapshot, with trixie-security's updates at the security snapshot in place of the release's builds.""" packages = index("debian", debian, "trixie", arch) for name, p in index("debian-security", security, "trixie-security", arch).items(): packages[name] = p # a security update supersedes the release's build return packages def entry(p): return {"package": p["Package"], "version": p["Version"], "url": p["_base"] + p["Filename"], "sha256": p["SHA256"], "size": int(p["Size"])} def renderer_entry(p, base): """A renderer.json entry: base is true for a package ci-chromium.json leaves to the image.""" return {"package": p["Package"], "version": p["Version"], "architecture": p["Architecture"], "url": p["_base"] + p["Filename"], "sha256": p["SHA256"], "size": int(p["Size"]), "base": base} def pins(packages, version, arch): """(the browser packages a Debian image lacks, those plus the base they need): one resolution, pruned at the required base and not.""" for name in TOP: if packages[name]["Version"] != version: sys.exit("%s %s: the snapshots have %s, not %s" % (name, arch, packages[name]["Version"], version)) closure = resolver(packages) required = [n for n, p in packages.items() if p.get("Priority") == "required" or p.get("Essential") == "yes"] base = closure(required) browser = closure(TOP, skip=SKIP, prune=base) - SKIP full = closure(TOP, skip=SKIP) - SKIP if not browser <= full: sys.exit("%s: the pruned closure has %s beyond the full one" % (arch, sorted(browser - full))) return browser, full def main(argv): if len(argv) != 3: print(__doc__, file=sys.stderr) return 2 version, debian, security = argv head = { "version": version, "snapshots": {"debian": debian, "debian-security": security}, "program": "usr/lib/chromium/chromium-headless-shell", } pinned, renderer = dict(head), dict(head) for arch in ARCHES: packages = archive(debian, security, arch) browser, full = pins(packages, version, arch) pinned[arch] = [entry(packages[n]) for n in sorted(browser)] print("%s: %d packages, %.0f MB" % (arch, len(pinned[arch]), sum(p["size"] for p in pinned[arch]) / 1e6)) if arch == RENDERER_ARCH: renderer[arch] = [renderer_entry(packages[n], n not in browser) for n in sorted(full)] print("renderer %s: %d packages, %d of them base, %.0f MB" % ( arch, len(full), len(full - browser), sum(p["size"] for p in renderer[arch]) / 1e6)) for path, data in ((OUT, pinned), (RENDERER_OUT, renderer)): with open(path, "w") as f: json.dump(data, f, indent=2) f.write("\n") print("wrote " + os.path.normpath(path)) return 0 if __name__ == "__main__": sys.exit(main(sys.argv[1:]))