Skip to content

Commit 2ad7263

Browse files
authored
Add simplified filename and SHA256 checksum uploads for Gardenlinux images (#985)
- Upload Gardenlinux images with original filename containing hash suffix (e.g., openstack-gardener_prod-amd64-1877.6-48d68617.qcow2) - Upload additional copy with simplified filename without hash suffix (e.g., openstack-gardener_prod-amd64-1877.6.qcow2) - Create and upload SHA256 checksum file (e.g., openstack-gardener_prod-amd64-1877.6.qcow2.sha256) - SHA256 checksum file follows standard format: checksum filename - Gardenlinux-specific logic only triggers for images with shortname 'gardenlinux' - Uses regex pattern to detect and remove 8-character hex hash suffix from filenames - Symlink approach for efficient file handling - Proper cleanup of temporary files AI-assisted: Claude Code Signed-off-by: Christian Berendt <berendt@osism.tech>
1 parent 8427201 commit 2ad7263

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

contrib/mirror.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import hashlib
44
import os
55
import patoolib
6+
import re
67
import requests
78
import shutil
89
import sys
@@ -219,6 +220,66 @@ def main(
219220
mirror_filename,
220221
)
221222

223+
# Gardenlinux-specific: Upload additional files with simplified filename and SHA256 checksum
224+
if image["shortname"] == "gardenlinux":
225+
# Check if filename matches pattern with hash suffix: *-[8-char-hex].qcow2
226+
hash_pattern = re.compile(r"-([a-f0-9]{8})\.qcow2$")
227+
match = hash_pattern.search(mirror_filename)
228+
229+
if match:
230+
# Create simplified filename by removing hash suffix
231+
simplified_filename = hash_pattern.sub(
232+
".qcow2", mirror_filename
233+
)
234+
logger.info(
235+
f"Creating simplified filename: {simplified_filename}"
236+
)
237+
238+
# Create symlink to simplified filename
239+
if os.path.exists(simplified_filename):
240+
os.remove(simplified_filename)
241+
os.symlink(mirror_filename, simplified_filename)
242+
243+
# Upload simplified filename
244+
logger.info(
245+
f"Uploading {simplified_filename} to bucket {mirror_dirname}"
246+
)
247+
client.fput_object(
248+
minio_bucket,
249+
os.path.join(mirror_dirname, simplified_filename),
250+
simplified_filename,
251+
)
252+
253+
# Calculate SHA256 checksum
254+
h_sha256 = hashlib.sha256()
255+
with open(mirror_filename, "rb") as fp:
256+
while chunk := fp.read(8192):
257+
h_sha256.update(chunk)
258+
259+
sha256_hash = h_sha256.hexdigest()
260+
logger.info(
261+
f"SHA256 of {simplified_filename}: {sha256_hash}"
262+
)
263+
264+
# Create SHA256 checksum file
265+
sha256_filename = f"{simplified_filename}.sha256"
266+
with open(sha256_filename, "w") as fp:
267+
fp.write(f"{sha256_hash} {simplified_filename}\n")
268+
269+
# Upload SHA256 checksum file
270+
logger.info(
271+
f"Uploading {sha256_filename} to bucket {mirror_dirname}"
272+
)
273+
client.fput_object(
274+
minio_bucket,
275+
os.path.join(mirror_dirname, sha256_filename),
276+
sha256_filename,
277+
)
278+
279+
# Clean up temporary files
280+
os.remove(simplified_filename)
281+
os.remove(sha256_filename)
282+
222283
os.remove(mirror_filename)
223284
else:
224285
logger.info(

0 commit comments

Comments
 (0)