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

OCI layout extensions #2633

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

vrothberg
Copy link
Member

Taken over from #2567 but:

  • Added tests for the three commits
  • Added hardlinks when adding a file

Images in the index can now be referenced via the @sourceIndex syntax.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
The new API allows for listing all manifests in an OCI layout's index.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
On Linux machines, the file will not be copied but hardlinked.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
@vrothberg
Copy link
Member Author

In draft for now.

// It computes, and returns, the digest and size of the used file.
//
// This function can be used instead of dest.PutBlob() where the ImageDestination requires PutBlob() to be called.
func PutBlobFromLocalFile(ctx context.Context, dest types.ImageDestination, file string) (digest.Digest, int64, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@mtrmac @baude
I think we should add the functionality of specifying the media type of the blob/layer here. A podman artifact add --mediatype something.something.ai may actually be needed. Otherwise, the manifest would suggest that the layers/files are compressed tar balls.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, scratch that. The caller is expected to update the manifest in those cases.

I implemented a very similar mechanism in buildah source add which automatically adds the layers to the manifest and updates the digests etc:
https://github.com/containers/buildah/blob/main/internal/source/add.go#L46

I am OK with the current design but it's probably something we should add to the docs of the function.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, scratch that. The caller is expected to update the manifest in those cases.

Yes. Copy&pasting from #2567 (comment):

The way the ImageDestination API works, PutBlob doesn’t typically need to worry about the MIME type: the MIME type comes via PutManifest.

While it is true that the PutBlobWithOptions gets a full types.BlobInfo, and

blobInfo, diffIDChan, err := ic.copyLayerFromStream(ctx, srcStream, types.BlobInfo{Digest: srcInfo.Digest, Size: srcBlobSize, MediaType: srcInfo.MediaType, Annotations: srcInfo.Annotations}, diffIDIsNeeded, toEncrypt, bar, layerIndex, emptyLayer)
forwards the MIME type value into the layer copy code, there are things like
stream.info = types.BlobInfo{ // FIXME? Should we preserve more data in src.info?
just dropping that; so, transports can’t rely on a MIME type being present (~instead, we have PutBlobOptions.IsConfig).

Also, specifically in the OCI transport, the PutBlob* code really doesn’t care about the MIME type. It is going to create a sha256-named file, and as far as the layout definition is concerned, it’s perfectly valid to refer to a single blob in two different manifests using two different MIME types. So, for this OCI-transport-specific function, I don’t think adding a MIME type is right.

Copy link
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

Just a quick skim; I’m afraid I didn’t read the added tests yet.

Comment on lines +315 to +316
os.Remove(blobFile.Name())
if err := os.Link(file, blobFile.Name()); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is conceptually racy against the CreateTemp above. An alternative could be to create a temporary directory, and to create this link to a file in that temporary directory.

Comment on lines +315 to +316
os.Remove(blobFile.Name())
if err := os.Link(file, blobFile.Name()); err != nil {
Copy link
Collaborator

@mtrmac mtrmac Nov 14, 2024

Choose a reason for hiding this comment

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

I’m EDIT not quite sure about a hard-link to the user’s input; the user could continue to edit that file afterwards. At the very least this would need a strong API documentation.

I think a reflink would be uncontroversial, OTOH not always possible.

Copy link
Member Author

@vrothberg vrothberg Nov 15, 2024

Choose a reason for hiding this comment

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

Fair point. Reflinks work on Linux (xfs, btrfs) and on Mac OS (? see unix package). Hardlinks work everywhere, so they are more portable.

If we envision podman artifact having to deal with huge files (e.g., LLMs), then hardlinks seem more attractive. On the other hand, any change to the file after a podman artifact add would corrupt the image as the digest wouldn't match anymore. The digest could be recomputed on artifact push for instance.

OR will podman artifact on the remote-clients be talking to podman-machine? In that case, the reflinks would only work on Linux.

@baude can you give direction?


// need to explicitly close the file, since a rename won't otherwise work on Windows
blobFile.Close()
if err := os.Rename(blobFile.Name(), blobPath); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We might already have a file with exactly that digest; that’s not an error.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will add a test for that case 👍

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