forked from longtao.wu/droboticflow
Builtin operator images were rebuilt four times after 2026-06-29 but the catalog kept the first digests: recording a release was a manual step that nothing ran. Once the old tags were pruned from CCR, 66 builtin operators pointed at manifests that no longer exist. - build-poc-images-kaniko.sh now runs record_operator_releases.py after operator builds (POC_KANIKO_RECORD_RELEASES, default true): it resolves each pushed tag to its digest, writes release.json with the stable :builtin tag, regenerates the catalog and repository manifests, then runs verify_operator_image_digests.py on the built operators. - verify_operator_image_digests.py fails when any pinned catalog digest is missing from the registry (usable in CI / before deploys). - sync_live_builtin_operator_images.py promotes catalog digests to a running platform (the API keeps live digests over the catalog), only after confirming each digest exists; dry run unless --apply. - scripts/lib/registry_client.py parses repo:tag@sha256 references and handles CCR's Bearer token challenge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
117 lines
4.3 KiB
Python
117 lines
4.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Record freshly pushed builtin operator images as their release truth.
|
|
|
|
Resolves each pushed image:tag to its registry digest, writes it into the operator's
|
|
release.json (stable `:builtin` tag + digest-pinned imageId), then regenerates the builtin
|
|
catalog and repository manifests so the API embeds the new digests.
|
|
|
|
Usage:
|
|
record_operator_releases.py --env poc --source-commit SHA [--built-at ISO] IMAGE:TAG ...
|
|
record_operator_releases.py --env poc --from-build-log build.log # reads OPERATOR_IMAGE= lines
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import datetime
|
|
import json
|
|
import pathlib
|
|
import subprocess
|
|
import sys
|
|
|
|
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / "scripts" / "lib"))
|
|
|
|
from registry_client import RegistryClient, parse_image_reference # noqa: E402
|
|
|
|
OPERATOR_IMAGE_MANIFEST = ROOT / "operator-images" / "builtin" / "operator-images.json"
|
|
IMAGE_PREFIX = "droboticflow-operator-"
|
|
|
|
|
|
def operator_slugs() -> dict[str, str]:
|
|
"""Map registry image names (droboticflow-operator-foo-bar) to operator slugs (foo_bar)."""
|
|
items = json.loads(OPERATOR_IMAGE_MANIFEST.read_text(encoding="utf-8"))["items"]
|
|
return {IMAGE_PREFIX + item["operatorSlug"].replace("_", "-"): item["operatorSlug"] for item in items}
|
|
|
|
|
|
def images_from_build_log(path: pathlib.Path) -> list[str]:
|
|
return [
|
|
line.split("=", 1)[1].strip()
|
|
for line in path.read_text(encoding="utf-8").splitlines()
|
|
if line.startswith("OPERATOR_IMAGE=") and line.split("=", 1)[1].strip()
|
|
]
|
|
|
|
|
|
def plan_releases(images: list[str], slugs: dict[str, str], resolve) -> list[dict[str, str]]:
|
|
"""Return one release record per image; raises if an image is unknown or not pushed."""
|
|
releases = []
|
|
for value in images:
|
|
image = parse_image_reference(value)
|
|
name = image.repository.rsplit("/", 1)[-1]
|
|
slug = slugs.get(name)
|
|
if slug is None:
|
|
raise SystemExit(f"{value}: not a builtin operator image ({name})")
|
|
image_id = resolve(value)
|
|
releases.append(
|
|
{
|
|
"slug": slug,
|
|
"image": f"{image.host}/{image.repository}:builtin",
|
|
"imageId": image_id,
|
|
"builtTag": image.tag,
|
|
}
|
|
)
|
|
return releases
|
|
|
|
|
|
def run(command: list[str]) -> None:
|
|
subprocess.run(command, cwd=ROOT, check=True)
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
parser.add_argument("images", nargs="*", help="pushed operator images (host/repo:tag)")
|
|
parser.add_argument("--from-build-log", type=pathlib.Path, help="read OPERATOR_IMAGE= lines from a kaniko build log")
|
|
parser.add_argument("--env", default="poc")
|
|
parser.add_argument("--source-commit", default="")
|
|
parser.add_argument("--built-at", default="")
|
|
args = parser.parse_args()
|
|
|
|
images = list(args.images)
|
|
if args.from_build_log:
|
|
images.extend(images_from_build_log(args.from_build_log))
|
|
if not images:
|
|
raise SystemExit("no operator images to record")
|
|
|
|
client = RegistryClient()
|
|
releases = plan_releases(images, operator_slugs(), client.resolve_digest)
|
|
built_at = args.built_at or datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
for release in releases:
|
|
command = [
|
|
sys.executable,
|
|
"scripts/update_operator_release_manifests.py",
|
|
"--env",
|
|
args.env,
|
|
"--slug",
|
|
release["slug"],
|
|
"--image",
|
|
release["image"],
|
|
"--image-id",
|
|
release["imageId"],
|
|
"--built-at",
|
|
built_at,
|
|
"--kaniko-job",
|
|
f"kaniko-op-{release['slug'].replace('_', '-')}-{release['builtTag']}",
|
|
]
|
|
if args.source_commit:
|
|
command += ["--source-commit", args.source_commit]
|
|
run(command)
|
|
print(f"recorded {release['slug']} -> {release['imageId']}")
|
|
run([sys.executable, "scripts/generate_operator_images.py", "--write"])
|
|
run([sys.executable, "scripts/generate_operator_repository_manifests.py", "--write"])
|
|
print(f"recorded {len(releases)} operator release(s); commit release.json and the regenerated catalog")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|