| Stella Laurenzo | ea2b79d | 2023-03-09 10:33:49 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | # Copyright 2023 The IREE Authors |
| 4 | # |
| 5 | # Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 6 | # See https://llvm.org/LICENSE.txt for license information. |
| 7 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 8 | """Command line tool to get the fully qualified image name given short name. |
| 9 | |
| 10 | Syntax: |
| 11 | ./build_tools/docker/get_image_name.py {short_name} |
| 12 | |
| 13 | Where {short_name} is the last name component of an image in prod_digests.txt |
| 14 | (i.e. "base", "nvidia", etc). |
| 15 | |
| 16 | This is used both in tree and out of tree to get a image name and current |
| 17 | version without adding fully referencing sha256 hashes, etc. |
| 18 | """ |
| 19 | |
| 20 | from pathlib import Path |
| 21 | import sys |
| 22 | |
| Jonathan DEKHTIAR | 4880d00 | 2023-04-19 23:39:11 -0400 | [diff] [blame] | 23 | |
| 24 | def find_image_by_name(img_name): |
| 25 | this_dir = Path(__file__).resolve().parent |
| 26 | |
| 27 | with open(this_dir / "prod_digests.txt", "rt") as f: |
| 28 | for line in f.readlines(): |
| 29 | line = line.strip() |
| 30 | if line.startswith(f"gcr.io/iree-oss/{img_name}@"): |
| 31 | return line |
| 32 | else: |
| 33 | raise ValueError( |
| 34 | f"ERROR: Image name {img_name} not found in prod_digests.txt") |
| 35 | |
| 36 | |
| Stella Laurenzo | ea2b79d | 2023-03-09 10:33:49 -0800 | [diff] [blame] | 37 | if __name__ == "__main__": |
| 38 | if len(sys.argv) != 2: |
| 39 | print("ERROR: Expected image short name", file=sys.stderr) |
| 40 | sys.exit(1) |
| 41 | short_name = sys.argv[1] |
| Jonathan DEKHTIAR | 4880d00 | 2023-04-19 23:39:11 -0400 | [diff] [blame] | 42 | image_name = find_image_by_name(short_name) |
| 43 | print(image_name) |