@@ -98,15 +98,15 @@ def download_to_directory(
9898
9999 def upload_from_directory (
100100 self ,
101- cname : str ,
101+ base_name : str ,
102102 artifacts_dir : PathLike [str ] | str ,
103103 delete_before_push : bool = False ,
104104 dry_run : bool = False ,
105105 ) -> None :
106106 """
107107 Pushes S3 artifacts to the underlying bucket.
108108
109- :param cname : Canonical name of the GardenLinux S3 artifacts
109+ :param base_name : Base name of the GardenLinux S3 artifacts
110110 :param artifacts_dir: Path of the image artifacts
111111 :param delete_before_push: True to delete objects before upload
112112
@@ -115,35 +115,32 @@ def upload_from_directory(
115115
116116 artifacts_dir = Path (artifacts_dir )
117117
118- cname_object = CName (cname )
119-
120118 if not artifacts_dir .is_dir ():
121119 raise RuntimeError (f"Artifacts directory given is invalid: { artifacts_dir } " )
122120
123- release_file = artifacts_dir .joinpath (f"{ cname } .release" )
124- release_timestamp = stat (release_file ).st_ctime
125-
126- cname_object .load_from_release_file (release_file )
121+ release_file = artifacts_dir .joinpath (f"{ base_name } .release" )
127122
128- if cname_object .arch is None :
129- raise RuntimeError (
130- "Architecture could not be determined from GardenLinux canonical name or release file"
131- )
123+ cname_object = CName .new_from_release_file (release_file )
132124
133125 if cname_object .version_and_commit_id is None :
134126 raise RuntimeError (
135- "Version information could not be determined from GardenLinux canonical name or release file"
127+ "Version information could not be determined from release file"
136128 )
137129
130+ arch = cname_object .arch
138131 feature_list = cname_object .feature_set
139- requirements_file = artifacts_dir .joinpath (f"{ cname } .requirements" )
132+ release_timestamp = stat (release_file ).st_ctime
133+ requirements_file = artifacts_dir .joinpath (f"{ base_name } .requirements" )
140134 require_uefi = None
141135 secureboot = None
142136
143137 if requirements_file .exists ():
144138 requirements_config = ConfigParser (allow_unnamed_section = True )
145139 requirements_config .read (requirements_file )
146140
141+ if requirements_config .has_option (UNNAMED_SECTION , "arch" ):
142+ arch = requirements_config .get (UNNAMED_SECTION , "arch" )
143+
147144 if requirements_config .has_option (UNNAMED_SECTION , "uefi" ):
148145 require_uefi = requirements_config .getboolean (UNNAMED_SECTION , "uefi" )
149146
@@ -152,16 +149,25 @@ def upload_from_directory(
152149 UNNAMED_SECTION , "secureboot"
153150 )
154151
152+ if arch is None :
153+ raise RuntimeError (
154+ "Architecture could not be determined from release or requirements file"
155+ )
156+
155157 if require_uefi is None :
156158 require_uefi = "_usi" in feature_list
157159
158160 if secureboot is None :
159161 secureboot = "_trustedboot" in feature_list
160162
161- commit_hash = cname_object .commit_hash
163+ # RegEx for S3 supported characters
164+ re_object = re .compile ("[^a-zA-Z0-9\\ s+\\ -=.\\ _:/@]" )
165+
166+ arch = re_object .sub ("+" , arch )
167+ commit_id_or_hash = cname_object .commit_hash
162168
163- if commit_hash is None :
164- commit_hash = ""
169+ if commit_id_or_hash is None :
170+ commit_id_or_hash = cname_object . commit_id
165171
166172 version_epoch = str (cname_object .version_epoch )
167173
@@ -170,9 +176,9 @@ def upload_from_directory(
170176
171177 metadata = {
172178 "platform" : cname_object .feature_set_platform ,
173- "architecture" : cname_object . arch ,
179+ "architecture" : arch ,
174180 "base_image" : None ,
175- "build_committish" : commit_hash ,
181+ "build_committish" : commit_id_or_hash ,
176182 "build_timestamp" : datetime .fromtimestamp (release_timestamp ).isoformat (),
177183 "gardenlinux_epoch" : {version_epoch },
178184 "logs" : None ,
@@ -181,7 +187,7 @@ def upload_from_directory(
181187 "secureboot" : secureboot ,
182188 "published_image_metadata" : None ,
183189 "s3_bucket" : self ._bucket .name ,
184- "s3_key" : f"meta/singles/{ cname } " ,
190+ "s3_key" : f"meta/singles/{ base_name } " ,
185191 "test_result" : None ,
186192 "version" : cname_object .version ,
187193 "paths" : [],
@@ -192,39 +198,34 @@ def upload_from_directory(
192198 if platform_variant is not None :
193199 metadata ["platform_variant" ] = platform_variant
194200
195- re_object = re . compile ( "[^a-zA-Z0-9 \\ s+ \\ -=. \\ _:/@]" )
201+ base_name_length = len ( base_name )
196202
197203 for artifact in artifacts_dir .iterdir ():
198- if not artifact .match (f"{ cname } *" ):
204+ if not artifact .match (f"{ base_name } *" ):
199205 continue
200206
201- if not artifact .name .startswith (cname ):
202- raise RuntimeError (
203- f"Artifact name '{ artifact .name } ' does not start with cname '{ cname } '"
204- )
205-
206- s3_key = f"objects/{ cname } /{ artifact .name } "
207+ s3_key = f"objects/{ base_name } /{ artifact .name } "
207208
208209 with artifact .open ("rb" ) as fp :
209210 md5sum = file_digest (fp , "md5" ).hexdigest ()
210211 sha256sum = file_digest (fp , "sha256" ).hexdigest ()
211212
212- suffix = artifact .name [ len ( cname ) :]
213+ suffixes = "" . join ( artifact .name )[ 1 + base_name_length :]
213214
214215 artifact_metadata = {
215216 "name" : artifact .name ,
216217 "s3_bucket_name" : self ._bucket .name ,
217218 "s3_key" : s3_key ,
218- "suffix" : suffix ,
219+ "suffix" : re_object . sub ( "+" , suffixes ) ,
219220 "md5sum" : md5sum ,
220221 "sha256sum" : sha256sum ,
221222 }
222223
223224 s3_tags = {
224- "architecture" : re_object . sub ( "+" , cname_object . arch ) ,
225+ "architecture" : arch ,
225226 "platform" : re_object .sub ("+" , cname_object .platform ),
226227 "version" : re_object .sub ("+" , cname_object .version ), # type: ignore[arg-type]
227- "committish" : commit_hash ,
228+ "committish" : commit_id_or_hash ,
228229 "md5sum" : md5sum ,
229230 "sha256sum" : sha256sum ,
230231 }
@@ -246,13 +247,15 @@ def upload_from_directory(
246247 else :
247248 if delete_before_push :
248249 self ._bucket .delete_objects (
249- Delete = {"Objects" : [{"Key" : f"meta/singles/{ cname } " }]}
250+ Delete = {"Objects" : [{"Key" : f"meta/singles/{ base_name } " }]}
250251 )
251252
252253 with TemporaryFile (mode = "wb+" ) as fp :
253254 fp .write (yaml .dump (metadata ).encode ("utf-8" ))
254255 fp .seek (0 )
255256
256257 self ._bucket .upload_fileobj (
257- fp , f"meta/singles/{ cname } " , ExtraArgs = {"ContentType" : "text/yaml" }
258+ fp ,
259+ f"meta/singles/{ base_name } " ,
260+ ExtraArgs = {"ContentType" : "text/yaml" },
258261 )
0 commit comments