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

Remove null blobs from Soci Index #23

Merged
merged 1 commit into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions fs/artifact_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,7 @@ func FetchSociArtifacts(ctx context.Context, imageRef, indexDigest string, store

eg, ctx := errgroup.WithContext(ctx)
for _, blob := range index.Blobs {
if blob == nil {
continue
}
blob := *blob
blob := blob
eg.Go(func() error {
rc, local, err := fetcher.Fetch(ctx, blob)
if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,8 @@ func (fs *filesystem) fetchSociArtifacts(ctx context.Context, imageRef, indexDig

func (fs *filesystem) populateImageLayerToSociMapping(sociIndex *soci.SociIndex) {
for _, desc := range sociIndex.Blobs {
if desc != nil {
ociDigest := desc.Annotations[soci.IndexAnnotationImageLayerDigest]
fs.imageLayerToSociDesc[ociDigest] = *desc
}
ociDigest := desc.Annotations[soci.IndexAnnotationImageLayerDigest]
fs.imageLayerToSociDesc[ociDigest] = desc
}
}

Expand Down
20 changes: 2 additions & 18 deletions integration/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,11 @@ func TestSociCreateSparseIndex(t *testing.T) {
}

blobs := sociIndex.Blobs
notNilBlobCount := 0
for _, b := range blobs {
if b != nil {
notNilBlobCount++
}
}
if notNilBlobCount != len(includedLayers) {
t.Fatalf("unexpected blob count; expected=%v, got=%v", len(includedLayers), notNilBlobCount)
if len(blobs) != len(includedLayers) {
t.Fatalf("unexpected blob count; expected=%v, got=%v", len(includedLayers), len(blobs))
}

for i, blob := range blobs {
if blob == nil {
continue
}
blob := *blob

blobContent := fetchContentFromPath(sh, blobStorePath+"/"+trimSha256Prefix(blob.Digest.String()))
blobSize := int64(len(blobContent))
blobDigest := digest.FromBytes(blobContent)
Expand Down Expand Up @@ -205,11 +194,6 @@ func TestSociCreate(t *testing.T) {
blobs := sociIndex.Blobs

for _, blob := range blobs {
if blob == nil {
continue
}
blob := *blob

blobContent := fetchContentFromPath(sh, blobStorePath+"/"+trimSha256Prefix(blob.Digest.String()))
blobSize := int64(len(blobContent))
blobDigest := digest.FromBytes(blobContent)
Expand Down
11 changes: 9 additions & 2 deletions soci/soci_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type SociIndex struct {
MediaType string `json:"mediaType"`
ArtifactType string `json:"artifactType"`
// descriptors of ztocs
Blobs []*ocispec.Descriptor `json:"blobs,omitempty"`
Blobs []ocispec.Descriptor `json:"blobs,omitempty"`
// descriptor of image manifest
Subject ocispec.Descriptor `json:"subject,omitempty"`

Expand Down Expand Up @@ -172,6 +172,13 @@ func BuildSociIndex(ctx context.Context, cs content.Store, img images.Image, spa
return nil, err
}

ztocsDesc := make([]ocispec.Descriptor, 0, len(manifest.Layers))
for _, desc := range sociLayersDesc {
if desc != nil {
ztocsDesc = append(ztocsDesc, *desc)
}
}

annotations := map[string]string{
IndexAnnotationBuildToolIdentifier: config.buildToolIdentifier,
IndexAnnotationBuildToolVersion: config.buildToolVersion,
Expand All @@ -180,7 +187,7 @@ func BuildSociIndex(ctx context.Context, cs content.Store, img images.Image, spa
sociIndex := SociIndex{
MediaType: sociIndexMediaType,
ArtifactType: SociIndexArtifactType,
Blobs: sociLayersDesc,
Blobs: ztocsDesc,
Subject: ocispec.Descriptor{
MediaType: imgManifestDesc.MediaType,
Digest: imgManifestDesc.Digest,
Expand Down