1+ #!/usr/bin/env python
2+
3+ import argparse
4+ import glob
5+ import json
6+ import os
7+ import subprocess
8+
9+
10+ def pull_image (image_url , destination_image_file ):
11+ """
12+ """
13+ apptainer_pull_cmd = [
14+ "apptainer" ,
15+ "pull" ,
16+ destination_image_file ,
17+ image_url ,
18+ ]
19+ subprocess .run (apptainer_pull_cmd )
20+
21+
22+ def push_image (source_image_file , image_url ):
23+ """
24+ """
25+
26+ apptainer_push_cmd = [
27+ "apptainer" ,
28+ "push" ,
29+ source_image_file ,
30+ image_url ,
31+ ]
32+ subprocess .run (apptainer_push_cmd )
33+
34+
35+ def main (args ):
36+ repo_owner = os .environ ['GITHUB_REPOSITORY_OWNER' ].lower ()
37+
38+ wave_jsons = glob .glob (os .path .join (args .wave_jsons_dir , "*.json" ))
39+ for wave_json in wave_jsons :
40+ with open (wave_json , 'r' ) as f :
41+ w = json .load (f )
42+ pull_image_url = w ['containerImage' ]
43+ image_name_with_version = pull_image_url .split ('/' )[- 1 ]
44+ image_name , image_version = image_name_with_version .split (':' )
45+ pull_destination = os .path .join (args .images_dir , f"{ image_name } --{ image_version } .img" )
46+ pull_image (pull_image_url , pull_destination )
47+
48+ push_image_url = f"oras://ghcr.io/{ repo_owner } /{ image_name } :{ image_version } "
49+ push_image (pull_destination , push_image_url )
50+
51+
52+ if __name__ == '__main__' :
53+ parser = argparse .ArgumentParser ()
54+ parser .add_argument ('--wave-jsons-dir' )
55+ parser .add_argument ('--images-dir' )
56+ args = parser .parse_args ()
57+ main (args )
0 commit comments