Created
September 4, 2025 14:02
-
-
Save riprasad/8a70a2c6a1d98da39694b4c675124c39 to your computer and use it in GitHub Desktop.
Generate ImageDigestMirrorSet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import requests | |
| import sys | |
| import yaml # pip install pyyaml | |
| # --- CONFIGURATION --- | |
| QUAY_API = "https://quay.io/api/v1" | |
| ORGANIZATION = "rhoai" | |
| TARGET_REGISTRY = "registry.redhat.io/rhoai" # Destination registry path | |
| AUTH_TOKEN = os.environ["QUAY_TOKEN"] | |
| # --- HEADERS --- | |
| HEADERS = { | |
| "Authorization": f"Bearer {AUTH_TOKEN}", | |
| "Content-Type": "application/json", | |
| } | |
| def get_repositories(org, next_page=None): | |
| repos = [] | |
| page = 1 | |
| while True: | |
| url = f"{QUAY_API}/repository?namespace={org}&page={page}" | |
| if next_page: | |
| url = f"{url}&next_page={next_page}" | |
| response = requests.get(url, headers=HEADERS) | |
| if response.status_code != 200: | |
| print(f"Failed to get repositories: {response.status_code} {response.text}") | |
| sys.exit(1) | |
| data = response.json() | |
| repos.extend(data.get("repositories", [])) | |
| next_page = data.get("next_page") | |
| if not next_page: | |
| break | |
| page += 1 | |
| return [repo["name"] for repo in repos] | |
| def generate_image_digest_mirror_set(org, repos): | |
| mirrors = [] | |
| for repo in repos: | |
| mirrors.append({ | |
| "mirrors": [f"quay.io/{org}/{repo}"], | |
| "source": f"{TARGET_REGISTRY}/{repo}" | |
| }) | |
| yaml_obj = { | |
| "apiVersion": "operator.openshift.io/v1alpha1", | |
| "kind": "ImageDigestMirrorSet", | |
| "metadata": {"name": "redhat-registry-mirror-set"}, | |
| "spec": {"imageDigestMirrors": mirrors} | |
| } | |
| return yaml.dump(yaml_obj, sort_keys=False) | |
| def main(): | |
| print(f"Fetching repositories for organization: {ORGANIZATION}") | |
| repos = get_repositories(ORGANIZATION) | |
| print(f"Found {len(repos)} repositories.") | |
| yaml_output = generate_image_digest_mirror_set(ORGANIZATION, repos) | |
| print("\n--- Generated ImageDigestMirrorSet ---\n") | |
| print(yaml_output) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment