Skip to content
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

Merged
merged 2 commits into from
Jan 22, 2025
Merged

Conversation

jaideepr97
Copy link
Collaborator

@jaideepr97 jaideepr97 commented Jan 7, 2025

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

Signed-off-by: Jaideep Rao <[email protected]>
@jaideepr97 jaideepr97 force-pushed the create-manifest branch 3 times, most recently from 60826ae to 21b54f1 Compare January 15, 2025 03:56
Comment on lines +163 to +176
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice addition, thanks!

Comment on lines 37 to 59
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dups from

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

@tarilabs
Copy link
Member

in hope of making it easier, going to exceptionally merge-commit for this one

@tarilabs tarilabs merged commit b41567d into containers:main Jan 22, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants