Skip to content

Commit 68269eb

Browse files
committed
Allow artifact add to override org.opencontainers.image.title annotation
Signed-off-by: Daniel J Walsh <[email protected]>
1 parent 80b20c7 commit 68269eb

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

pkg/libartifact/store/store.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,6 @@ func (as ArtifactStore) Add(ctx context.Context, dest string, artifactBlobs []en
221221
return nil, errors.New("append option is not compatible with type option")
222222
}
223223

224-
// currently we don't allow override of the filename ; if a user requirement emerges,
225-
// we could seemingly accommodate but broadens possibilities of something bad happening
226-
// for things like `artifact extract`
227-
if _, hasTitle := options.Annotations[specV1.AnnotationTitle]; hasTitle {
228-
return nil, fmt.Errorf("cannot override filename with %s annotation", specV1.AnnotationTitle)
229-
}
230-
231224
locked := true
232225
as.lock.Lock()
233226
defer func() {
@@ -320,7 +313,10 @@ func (as ArtifactStore) Add(ctx context.Context, dest string, artifactBlobs []en
320313
}
321314

322315
annotations := maps.Clone(options.Annotations)
323-
annotations[specV1.AnnotationTitle] = artifactBlob.FileName
316+
if _, ok := annotations[specV1.AnnotationTitle]; !ok {
317+
// Only override if the user did not specify the Title
318+
annotations[specV1.AnnotationTitle] = artifactBlob.FileName
319+
}
324320

325321
newLayer := specV1.Descriptor{
326322
MediaType: options.FileMIMEType,

test/e2e/artifact_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ var _ = Describe("Podman artifact", func() {
115115
Expect(a.Manifest.Layers[0].Annotations["flavor"]).To(Equal("lemon"))
116116
Expect(a.Manifest.Layers[0].MediaType).To(Equal(yamlType))
117117

118-
failSession := podmanTest.Podman([]string{"artifact", "add", "--annotation", "org.opencontainers.image.title=foobar", "foobar", artifact1File})
119-
failSession.WaitWithDefaultTimeout()
120-
Expect(failSession).Should(ExitWithError(125, "Error: cannot override filename with org.opencontainers.image.title annotation"))
118+
title := RandomString(12)
119+
annotation3 := fmt.Sprintf("org.opencontainers.image.title=%s", title)
120+
podmanTest.PodmanExitCleanly("artifact", "add", "--annotation", annotation3, "foobar", artifact1File)
121+
Expect(a.Manifest.Layers[0].Annotations["org.opencontainers.image.title"]).To(Equal(title))
121122
})
122123

123124
It("podman artifact add multiple", func() {

0 commit comments

Comments
 (0)