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

merge main #4

Merged
merged 2 commits into from
Oct 25, 2023
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/sylabs/sif/v2 v2.8.1
github.com/sylabs/squashfs v0.6.1
github.com/wagoodman/go-partybus v0.0.0-20200526224238-eb215533f07d
github.com/wagoodman/go-progress v0.0.0-20230911172108-cf810b7e365c
github.com/wagoodman/go-progress v0.0.0-20230925121702-07e42b3cdba0
golang.org/x/crypto v0.1.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYp
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
github.com/wagoodman/go-partybus v0.0.0-20200526224238-eb215533f07d h1:KOxOL6qpmqwoPloNwi+CEgc1ayjHNOFNrvoOmeDOjDg=
github.com/wagoodman/go-partybus v0.0.0-20200526224238-eb215533f07d/go.mod h1:JPirS5jde/CF5qIjcK4WX+eQmKXdPc6vcZkJ/P0hfPw=
github.com/wagoodman/go-progress v0.0.0-20230911172108-cf810b7e365c h1:mM8T8YhiD19d2wYv3vqZn8xpe1ZFJrUJCGlK4IV05xM=
github.com/wagoodman/go-progress v0.0.0-20230911172108-cf810b7e365c/go.mod h1:jLXFoL31zFaHKAAyZUh+sxiTDFe1L1ZHrcK2T1itVKA=
github.com/wagoodman/go-progress v0.0.0-20230925121702-07e42b3cdba0 h1:0KGbf+0SMg+UFy4e1A/CPVvXn21f1qtWdeJwxZFoQG8=
github.com/wagoodman/go-progress v0.0.0-20230925121702-07e42b3cdba0/go.mod h1:jLXFoL31zFaHKAAyZUh+sxiTDFe1L1ZHrcK2T1itVKA=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
Expand Down
21 changes: 20 additions & 1 deletion pkg/image/oci/directory_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/layout"

"github.com/anchore/stereoscope/pkg/file"
Expand Down Expand Up @@ -43,7 +44,13 @@ func (p *DirectoryImageProvider) Provide(_ context.Context, userMetadata ...imag

// for now, lets only support one image indexManifest (it is not clear how to handle multiple manifests)
if len(indexManifest.Manifests) != 1 {
return nil, fmt.Errorf("unexpected number of OCI directory manifests (found %d)", len(indexManifest.Manifests))
if len(indexManifest.Manifests) == 0 {
return nil, fmt.Errorf("unexpected number of OCI directory manifests (found %d)", len(indexManifest.Manifests))
}
// if all the manifests have the same digest, then we can treat this as a single image
if !checkManifestDigestsEqual(indexManifest.Manifests) {
return nil, fmt.Errorf("unexpected number of OCI directory manifests (found %d)", len(indexManifest.Manifests))
}
}

manifest := indexManifest.Manifests[0]
Expand Down Expand Up @@ -72,3 +79,15 @@ func (p *DirectoryImageProvider) Provide(_ context.Context, userMetadata ...imag

return image.New(img, p.tmpDirGen, contentTempDir, metadata...), nil
}

func checkManifestDigestsEqual(manifests []v1.Descriptor) bool {
if len(manifests) < 1 {
return false
}
for _, m := range manifests {
if m.Digest != manifests[0].Digest {
return false
}
}
return true
}
1 change: 1 addition & 0 deletions pkg/image/oci/directory_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func Test_Directory_Provide(t *testing.T) {
{"reads invalid oci manifest", "test-fixtures/invalid_file", true},
{"reads valid oci manifest with no images", "test-fixtures/no_manifests", true},
{"reads a fully correct manifest", "test-fixtures/valid_manifest", false},
{"reads a fully correct manifest with equal digests", "test-fixtures/valid_manifest", false},
}

for _, tc := range tests {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"schemaVersion": 2,
"manifests": [
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:27280e6c2e98b6ec460a9c1a5f354d894037dac6a649535bcc4063eb1f555c15",
"size": 480,
"annotations": {
"io.containerd.image.name": "docker.io/anchore/app:latest",
"org.opencontainers.image.created": "2023-09-19T15:16:47Z",
"org.opencontainers.image.ref.name": "latest"
},
"platform": {
"architecture": "amd64",
"os": "linux"
}
},
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:27280e6c2e98b6ec460a9c1a5f354d894037dac6a649535bcc4063eb1f555c15",
"size": 480,
"annotations": {
"io.containerd.image.name": "docker.io/anchore/app:1.0.0",
"org.opencontainers.image.created": "2023-09-19T15:16:47Z",
"org.opencontainers.image.ref.name": "1.0.0"
},
"platform": {
"architecture": "amd64",
"os": "linux"
}
}
]
}
Loading