-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create OCI image manifest #8
Conversation
Signed-off-by: Jaideep Rao <[email protected]>
f115d6a
to
326ab95
Compare
60826ae
to
21b54f1
Compare
Signed-off-by: Jaideep Rao <[email protected]>
21b54f1
to
b4ba3ea
Compare
def get_file_media_type(file_path: os.PathLike) -> str: | ||
""" | ||
Get the MIME type of a file using the `file` command. | ||
""" | ||
try: | ||
result = subprocess.run(['file', '--mime-type', '-b', file_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True) | ||
mime_type = result.stdout.decode('utf-8').strip() | ||
return mime_type | ||
except subprocess.CalledProcessError as e: | ||
print(f"Error occurred while getting MIME type: {e}") | ||
return MIMETypes.octet_stream | ||
except Exception as e: | ||
print(f"Unexpected error: {e}") | ||
return MIMETypes.octet_stream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice addition, thanks!
def create_blobs(source_dir: Path, oci_dir: Path): | ||
if not source_dir.exists(): | ||
raise ValueError(f"Input directory '{source_dir}' does not exist.") | ||
|
||
sha256_path = oci_dir / "blobs" / "sha256" | ||
os.makedirs(sha256_path, exist_ok=True) | ||
|
||
layers = {} # layer digest : diff_id | ||
|
||
# assume flat structure for source_dir for now | ||
# TODO: handle subdirectories appropriately | ||
model_files = [source_dir / Path(f) for f in os.listdir(source_dir) if os.path.isfile(os.path.join(source_dir, f))] | ||
|
||
for model_file in model_files: | ||
|
||
# handle model card file if encountered - assume README.md is the modelcard | ||
if os.path.basename(os.path.normpath(model_file)).endswith("README.md"): | ||
postcomp_chksum, precomp_chksum = targz_from_file(model_file, sha256_path) | ||
layers[postcomp_chksum] = precomp_chksum | ||
else: | ||
checksum = tarball_from_file(model_file, sha256_path) | ||
layers[checksum] = checksum | ||
return layers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dups from
Lines 37 to 59 in ceccbe9
def create_blobs(source_dir: Path, oci_dir: Path): | |
if not source_dir.exists(): | |
raise ValueError(f"Input directory '{source_dir}' does not exist.") | |
sha256_path = oci_dir / "blobs" / "sha256" | |
os.makedirs(sha256_path, exist_ok=True) | |
layers = {} # layer digest : diff_id | |
# assume flat structure for source_dir for now | |
# TODO: handle subdirectories appropriately | |
model_files = [source_dir / Path(f) for f in os.listdir(source_dir) if os.path.isfile(os.path.join(source_dir, f))] | |
for model_file in model_files: | |
# handle model card file if encountered - assume README.md is the modelcard | |
if os.path.basename(os.path.normpath(model_file)).endswith("README.md"): | |
postcomp_chksum, precomp_chksum = targz_from_file(model_file, sha256_path) | |
layers[postcomp_chksum] = precomp_chksum | |
else: | |
checksum = tarball_from_file(model_file, sha256_path) | |
layers[checksum] = checksum | |
return layers |
agree on removal
in hope of making it easier, going to exceptionally merge-commit for this one |
This PR adds logic to create an OCI image manifest and write it out to the blobs dir for a provided source model directory
should be merged after #7