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

libimage/manifests.list.Add(): preserve artifactType when all=true #2021

Merged
merged 1 commit into from
May 28, 2024
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
3 changes: 3 additions & 0 deletions libimage/manifests/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,9 @@ func (l *list) Add(ctx context.Context, sys *types.SystemContext, ref types.Imag
if err != nil {
return "", fmt.Errorf("adding instance with digest %q: %w", *instanceInfo.instanceDigest, err)
}
if err := l.List.SetArtifactType(instanceInfo.instanceDigest, instanceInfo.ArtifactType); err != nil {
return "", fmt.Errorf("setting artifact manifest type for instance with digest %q: %w", *instanceInfo.instanceDigest, err)
}
if err = l.List.SetURLs(*instanceInfo.instanceDigest, instanceInfo.URLs); err != nil {
return "", fmt.Errorf("setting URLs for instance with digest %q: %w", *instanceInfo.instanceDigest, err)
}
Expand Down
21 changes: 21 additions & 0 deletions libimage/manifests/manifests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,3 +816,24 @@ func TestInstanceByImageAndFiles(t *testing.T) {
assert.NoError(t, err)
assert.ElementsMatch(t, []string{}, noFiles)
}

// TestAddIndexOfArtifacts ensures that we don't fail to preserve artifactType
// fields in artifact manifests when added from one list to another.
func TestAddIndexOfArtifacts(t *testing.T) {
ctx := context.Background()

absPath, err := filepath.Abs(filepath.Join("..", "..", "pkg", "manifests", "testdata", "artifacts", "index"))
require.NoError(t, err)
rawPath := "oci:" + absPath
ref, err := alltransports.ParseImageName(rawPath)
require.NoErrorf(t, err, "ParseImageName(%q)", rawPath)

cookedList := Create()
_, err = cookedList.Add(ctx, sys, ref, true)
assert.NoError(t, err, "list.Add()")

cooked := cookedList.OCIv1()
for _, instance := range cooked.Manifests {
assert.NotEmpty(t, instance.ArtifactType, "lost the artifactType field")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"layers": [
{
"digest": "sha256:541b3e9daa09b20bf85fa273e5cbd3e80185aa4ec298e765db87742b70138a53",
"mediaType": "application/octet-stream",
"size": 1000,
"annotations": {
"org.opencontainers.image.ref.name": "one-thousand"
}
}
],
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"artifactType": "application/vnd.reproducer+foo",
"schemaVersion": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"layers": [
{
"digest": "sha256:e6304a473c65ecd0ccffbd2f5925a8f51c44b11f59b66cfcc055e4bb911b8fa0",
"mediaType": "application/octet-stream",
"size": 500,
"annotations": {
"org.opencontainers.image.ref.name": "five-hundred"
}
}
],
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"artifactType": "application/vnd.reproducer+bar",
"schemaVersion": 2
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.index.v1+json",
"manifests": [
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:25cb16f769a2248cde5556529b88e3cdff322dbe5c71e40cfb24030221e88b06",
"size": 417,
"platform": {
"architecture": "s390x",
"os": "linux"
},
"artifactType": "application/vnd.reproducer+bar"
},
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:11a1bc9fb43d6791f7f881a0375f88e83b10ea1c040a8d6d986cf799bb56e981",
"size": 418,
"platform": {
"architecture": "ppc64le",
"os": "linux"
},
"artifactType": "application/vnd.reproducer+foo"
}
]
}
Binary file not shown.
11 changes: 11 additions & 0 deletions pkg/manifests/testdata/artifacts/index/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.index.v1+json",
"manifests": [
{
"mediaType": "application/vnd.oci.image.index.v1+json",
"digest": "sha256:74c31168f466d846e0e0cf46fc8c14e0c516500558166654fce7555682b1cba6",
"size": 760
}
]
}
3 changes: 3 additions & 0 deletions pkg/manifests/testdata/artifacts/index/oci-layout
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"imageLayoutVersion": "1.0.0"
}