Skip to content

Commit 7d3ef01

Browse files
author
Malte Münch
committed
Adds function to push from dir
Signed-off-by: Malte Münch <[email protected]>
1 parent 76aee79 commit 7d3ef01

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "python_gardenlinux_lib"
3-
version = "0.4.2"
3+
version = "0.4.3"
44
description = "Contains tools to work with the features directory of gardenlinux, for example deducting dependencies from feature sets or validating cnames"
55
authors = ["Garden Linux Maintainers <[email protected]>"]
66
license = "Apache-2.0"

src/python_gardenlinux_lib/oras/registry.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,43 @@ def push_from_tar(self, architecture: str, version: str, cname: str, tar: str):
662662
print("removed tmp files.")
663663
return digest
664664

665+
def push_from_dir(self, architecture: str, version: str, cname: str, dir: str):
666+
# Step 1 scan and extract nested artifacts:
667+
for file in os.listdir(dir):
668+
try:
669+
if file.endswith(".pxe.tar.gz"):
670+
logger.info(f"Found nested artifact {file}")
671+
nested_tar_obj = tarfile.open(f"{dir}/{file}")
672+
nested_tar_obj.extractall(filter="data", path=dir)
673+
nested_tar_obj.close()
674+
except (OSError, tarfile.FilterError, tarfile.TarError) as e:
675+
print(f"Failed to extract nested artifact {file}", e)
676+
exit(1)
677+
678+
try:
679+
oci_metadata = get_oci_metadata_from_fileset(os.listdir(dir), architecture)
680+
681+
features = ""
682+
for artifact in oci_metadata:
683+
if artifact["media_type"] == "application/io.gardenlinux.release":
684+
file = open(f"{dir}/{artifact["file_name"]}", "r")
685+
lines = file.readlines()
686+
for line in lines:
687+
if line.strip().startswith("GARDENLINUX_FEATURES="):
688+
features = line.strip().removeprefix(
689+
"GARDENLINUX_FEATURES="
690+
)
691+
break
692+
file.close()
693+
694+
digest = self.push_image_manifest(
695+
architecture, cname, version, dir, oci_metadata, features
696+
)
697+
except Exception as e:
698+
print("Error: ", e)
699+
exit(1)
700+
return digest
701+
665702

666703
def extract_tar(tar: str, tmpdir: str):
667704
"""

0 commit comments

Comments
 (0)