-
Notifications
You must be signed in to change notification settings - Fork 31
feat: support index based reading of OCI artifacts #1646
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
base: main
Are you sure you want to change the base?
Changes from 13 commits
1c184d2
7ce6b75
c7eb44e
66b018d
8914447
43ea712
7b24f46
2ff06d0
9f95f98
9b13a06
e14ac45
caaff95
8b1e934
6595729
0bb1612
0e5616d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package genericocireg | |
|
|
||
| import ( | ||
| "bytes" | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
| "strings" | ||
|
|
@@ -13,6 +14,7 @@ import ( | |
|
|
||
| "ocm.software/ocm/api/oci" | ||
| "ocm.software/ocm/api/oci/artdesc" | ||
| "ocm.software/ocm/api/oci/extensions/repositories/artifactset" | ||
| "ocm.software/ocm/api/ocm/cpi/accspeccpi" | ||
| "ocm.software/ocm/api/ocm/extensions/accessmethods/localblob" | ||
| "ocm.software/ocm/api/utils/blobaccess/blobaccess" | ||
|
|
@@ -26,6 +28,7 @@ type localBlobAccessMethod struct { | |
| spec *localblob.AccessSpec | ||
| namespace oci.NamespaceAccess | ||
| artifact oci.ArtifactAccess | ||
| mimeType string | ||
| } | ||
|
|
||
| var _ accspeccpi.AccessMethodImpl = (*localBlobAccessMethod)(nil) | ||
|
|
@@ -40,6 +43,11 @@ func newLocalBlobAccessMethodImpl(a *localblob.AccessSpec, ns oci.NamespaceAcces | |
| namespace: ns, | ||
| artifact: art, | ||
| } | ||
| if m.spec.MediaType == artdesc.MediaTypeImageIndex || m.spec.MediaType == artdesc.MediaTypeImageManifest { | ||
| // if we discover a localblob with an index or manifest media type, we can | ||
| // assume that we are dealing with a new style of artifact created by the new reference library. | ||
| m.mimeType = artifactset.MediaType(m.spec.MediaType) | ||
| } | ||
|
Comment on lines
+46
to
+50
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if the localblob would be an actual OCI artifact? This would not make a difference as the new reference library creates its artifact in the OCI layout, right?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. im not sure I understand the question. a localblob as an oci artifact does not exist in the old ocm world afaik. what use case are you looking at? |
||
| ref.BeforeCleanup(refmgmt.CleanupHandlerFunc(m.cache)) | ||
| return m, nil | ||
| } | ||
|
|
@@ -99,8 +107,35 @@ func (m *localBlobAccessMethod) getBlob() (blobaccess.DataAccess, error) { | |
| err error | ||
| ) | ||
| if len(refs) < 2 { | ||
| _, data, err = m.namespace.GetBlobData(digest.Digest(m.spec.LocalReference)) | ||
| if err != nil { | ||
| if m.spec.MediaType == artdesc.MediaTypeImageIndex || m.spec.MediaType == artdesc.MediaTypeImageManifest { | ||
| // if we have a nested manifest or index, we can use the blob synthesis utility here to download | ||
| // the entire artifact set. | ||
| art, err := m.namespace.GetArtifact(m.spec.LocalReference) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get artifact for local reference %q: %w", m.spec.LocalReference, err) | ||
| } | ||
| defer art.Close() | ||
| var artifactRefs []string | ||
| if m.spec.ReferenceName != "" { | ||
| // if we have a reference name, it consists of repository and tag | ||
| // so we can extract the tag to use it as target, instead of latest | ||
| refSpec, err := oci.ParseRef(m.spec.ReferenceName) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to parse reference name %q: %w", m.spec.ReferenceName, err) | ||
| } | ||
| if refSpec.GetTag() != "" { | ||
| artifactRefs = append(artifactRefs, refSpec.GetTag()) | ||
| } | ||
| } | ||
| localReferenceDigest := digest.Digest(m.spec.LocalReference) | ||
| artifactRefs = append(artifactRefs, fmt.Sprintf("%s-%s", localReferenceDigest.Algorithm(), localReferenceDigest.Encoded())) | ||
| artifactRefs = append(artifactRefs, "latest") | ||
| artblob, err := artifactset.SynthesizeArtifactBlobForArtifact(art, artifactRefs) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to synthesize artifact blob: %w", err) | ||
| } | ||
| data = artblob | ||
| } else if _, data, err = m.namespace.GetBlobData(digest.Digest(m.spec.LocalReference)); err != nil { | ||
| return nil, err | ||
| } | ||
| } else { | ||
|
|
@@ -123,10 +158,13 @@ func (m *localBlobAccessMethod) Get() ([]byte, error) { | |
| } | ||
|
|
||
| func (m *localBlobAccessMethod) MimeType() string { | ||
| if m.mimeType != "" { | ||
| return m.mimeType | ||
| } | ||
| return m.spec.MediaType | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| // ////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| type composedBlock struct { | ||
| m *localBlobAccessMethod | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.