Skip to content

Commit dbdff22

Browse files
committed
Test/scripts: add dl-one-image-build-cache tool
Add a script for downloading a specific image build cache based on a provided build info file. This is useful for downloading specific image artifacts from S3 after one already downloaded the image build metadata and do it without regenerating manifests. Signed-off-by: Tomáš Hozza <[email protected]>
1 parent 3c9f9ad commit dbdff22

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

test/scripts/dl-one-image-build-cache

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
Download the image build CI cache files for a specific image from AWS S3.
5+
6+
This script downloads the image build cache files for a specific image from AWS S3.
7+
The script reads the build info JSON file to determine the image build cache files to download.
8+
"""
9+
10+
import argparse
11+
import os
12+
import sys
13+
14+
import imgtestlib as testlib
15+
16+
17+
def get_argparser():
18+
parser = argparse.ArgumentParser(description=__doc__)
19+
20+
parser.add_argument(
21+
"--build-info", type=str, metavar="JSON_FILE",
22+
help="Path to the build info JSON file containing the image build cache information. " +
23+
"If not provided, the script will try to read '<build-dir>/info.json.'",
24+
)
25+
parser.add_argument(
26+
"build_dir", type=os.path.abspath, metavar="BUILD_DIR",
27+
help="Directory where the image build cache files are downloaded to. " +
28+
"It may already contain the build cache files from a previous run.",
29+
)
30+
31+
return parser
32+
33+
34+
def main():
35+
parser = get_argparser()
36+
args = parser.parse_args()
37+
38+
build_dir = args.build_dir
39+
build_info_dir = os.path.dirname(args.build_info) if args.build_info else build_dir
40+
41+
print(f"📜 Reading 'info.json' from {build_info_dir}")
42+
build_info = testlib.read_build_info(build_info_dir)
43+
44+
runner_distro = testlib.get_common_ci_runner_distro()
45+
46+
distro = build_info["distro"]
47+
arch = build_info["arch"]
48+
osbuild_ref = build_info["osbuild-commit"]
49+
manifest_id = build_info["manifest-checksum"]
50+
runner_distro = build_info.get("runner-distro")
51+
52+
if runner_distro is None:
53+
runner_distro = testlib.get_common_ci_runner_distro()
54+
print("⚠️ Runner distro not found in the build info. " +
55+
f"Using the CI runner distro from the current branch: {runner_distro}", file=sys.stderr)
56+
57+
print("📥 Downloading the image build cache files for:")
58+
print(f" distro:{distro}")
59+
print(f" arch:{arch}")
60+
print(f" manifest-id:{manifest_id}")
61+
print(f" osbuild-ref:{osbuild_ref}")
62+
print(f" runner-distro:{runner_distro}")
63+
64+
out, dl_ok = testlib.dl_build_cache(build_dir, distro, arch, osbuild_ref, runner_distro, manifest_id)
65+
print(out)
66+
if not dl_ok:
67+
print("❌ Failed to download the image build cache", file=sys.stderr)
68+
sys.exit(1)
69+
70+
print("✅ Successfully downloaded the image build cache")
71+
72+
73+
if __name__ == "__main__":
74+
try:
75+
main()
76+
except KeyboardInterrupt:
77+
print("Interrupted by user", file=sys.stderr)
78+
sys.exit(1)

0 commit comments

Comments
 (0)