77from docker .models .containers import Container
88
99from tagging .apps .common_cli_arguments import common_arguments_parser
10- from tagging .hierarchy .get_taggers_and_manifests import (
11- get_taggers_and_manifests ,
12- )
10+ from tagging .hierarchy .get_manifests import get_manifests
11+ from tagging .hierarchy .get_taggers import get_taggers
1312from tagging .manifests .build_info import BuildInfo
14- from tagging .manifests .manifest_interface import ManifestInterface
1513from tagging .utils .config import Config
1614from tagging .utils .docker_runner import DockerRunner
1715from tagging .utils .get_prefix import get_file_prefix , get_tag_prefix
2422MARKDOWN_LINE_BREAK = "<br />"
2523
2624
27- def write_build_history_line (
28- config : Config , filename : str , all_tags : list [str ]
29- ) -> None :
30- LOGGER .info ("Appending build history line" )
25+ def get_build_history_line (config : Config , filename : str , container : Container ) -> str :
26+ LOGGER .info (f"Calculating build history line for image: { config .image } " )
27+
28+ taggers = get_taggers (config .image )
29+ tags_prefix = get_tag_prefix (config .variant )
30+ all_tags = [tags_prefix + "-" + tagger .tag_value (container ) for tagger in taggers ]
3131
3232 date_column = f"`{ BUILD_TIMESTAMP } `"
3333 image_column = MARKDOWN_LINE_BREAK .join (
@@ -42,19 +42,28 @@ def write_build_history_line(
4242 ]
4343 )
4444 build_history_line = f"| { date_column } | { image_column } | { links_column } |"
45- config .hist_lines_dir .mkdir (parents = True , exist_ok = True )
46- file = config .hist_lines_dir / f"{ filename } .txt"
47- file .write_text (build_history_line )
48- LOGGER .info (f"Build history line written to: { file } " )
49-
50-
51- def write_manifest_file (
52- config : Config ,
53- filename : str ,
54- commit_hash_tag : str ,
55- manifests : list [ManifestInterface ],
56- container : Container ,
45+
46+ LOGGER .info (f"Build history line calculated for image: { config .image } " )
47+ return build_history_line
48+
49+
50+ def write_build_history_line (
51+ config : Config , filename : str , container : Container
5752) -> None :
53+ LOGGER .info (f"Writing tags for image: { config .image } " )
54+
55+ path = config .hist_lines_dir / f"{ filename } .txt"
56+ path .parent .mkdir (parents = True , exist_ok = True )
57+ build_history_line = get_build_history_line (config , filename , container )
58+ path .write_text (build_history_line )
59+
60+ LOGGER .info (f"Build history line written to: { path } " )
61+
62+
63+ def get_manifest (config : Config , commit_hash_tag : str , container : Container ) -> str :
64+ LOGGER .info (f"Calculating manifest file for image: { config .image } " )
65+
66+ manifests = get_manifests (config .image )
5867 manifest_names = [manifest .__class__ .__name__ for manifest in manifests ]
5968 LOGGER .info (f"Using manifests: { manifest_names } " )
6069
@@ -65,27 +74,35 @@ def write_manifest_file(
6574 ]
6675 markdown_content = "\n \n " .join (markdown_pieces ) + "\n "
6776
68- config .manifests_dir .mkdir (parents = True , exist_ok = True )
69- file = config .manifests_dir / f"{ filename } .md"
70- file .write_text (markdown_content )
71- LOGGER .info (f"Manifest file written to: { file } " )
77+ LOGGER .info (f"Manifest file calculated for image: { config .image } " )
78+ return markdown_content
79+
80+
81+ def write_manifest (
82+ config : Config , filename : str , commit_hash_tag : str , container : Container
83+ ) -> None :
84+ LOGGER .info (f"Writing manifest file for image: { config .image } " )
7285
86+ path = config .manifests_dir / f"{ filename } .md"
87+ path .parent .mkdir (parents = True , exist_ok = True )
88+ manifest = get_manifest (config , commit_hash_tag , container )
89+ path .write_text (manifest )
7390
74- def write_manifest (config : Config ) -> None :
75- LOGGER .info (f"Creating manifests for image: { config .image } " )
76- taggers , manifests = get_taggers_and_manifests (config .image )
91+ LOGGER .info (f"Manifest file wrtitten to: { path } " )
92+
93+
94+ def write_all (config : Config ) -> None :
95+ LOGGER .info (f"Writing all files for image: { config .image } " )
7796
7897 file_prefix = get_file_prefix (config .variant )
7998 commit_hash_tag = GitHelper .commit_hash_tag ()
8099 filename = f"{ file_prefix } -{ config .image } -{ commit_hash_tag } "
81100
82101 with DockerRunner (config .full_image ()) as container :
83- tags_prefix = get_tag_prefix (config .variant )
84- all_tags = [
85- tags_prefix + "-" + tagger .tag_value (container ) for tagger in taggers
86- ]
87- write_build_history_line (config , filename , all_tags )
88- write_manifest_file (config , filename , commit_hash_tag , manifests , container )
102+ write_build_history_line (config , filename , container )
103+ write_manifest (config , filename , commit_hash_tag , container )
104+
105+ LOGGER .info (f"All files written for image: { config .image } " )
89106
90107
91108if __name__ == "__main__" :
@@ -101,4 +118,4 @@ def write_manifest(config: Config) -> None:
101118 manifests_dir = True ,
102119 repository = True ,
103120 )
104- write_manifest (config )
121+ write_all (config )
0 commit comments