blob: ae8e18031a12e5a6ff42adfdb9bb34593d2e8cef [file] [log] [blame]
Stella Laurenzoea2b79d2023-03-09 10:33:49 -08001#!/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
10Syntax:
11 ./build_tools/docker/get_image_name.py {short_name}
12
13Where {short_name} is the last name component of an image in prod_digests.txt
14(i.e. "base", "nvidia", etc).
15
16This is used both in tree and out of tree to get a image name and current
17version without adding fully referencing sha256 hashes, etc.
18"""
19
20from pathlib import Path
21import sys
22
Jonathan DEKHTIAR4880d002023-04-19 23:39:11 -040023
24def 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 Laurenzoea2b79d2023-03-09 10:33:49 -080037if __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 DEKHTIAR4880d002023-04-19 23:39:11 -040042 image_name = find_image_by_name(short_name)
43 print(image_name)