Skip to content

Commit 3994aae

Browse files
committed
Allow artifact add to override org.opencontainers.image.title annotation
Signed-off-by: Daniel J Walsh <[email protected]>
1 parent 14b68ba commit 3994aae

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
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,

pkg/machine/ocipull/ociartifact.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const (
2727
artifactRegistry = "quay.io"
2828
artifactRepo = "podman"
2929
artifactImageName = "machine-os"
30-
artifactOriginalName = "org.opencontainers.image.title"
30+
artifactOriginalName = specV1.AnnotationTitle
3131
machineOS = "linux"
3232
)
3333

test/e2e/artifact_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/containers/podman/v5/utils"
1515
. "github.com/onsi/ginkgo/v2"
1616
. "github.com/onsi/gomega"
17+
imgspec "github.com/opencontainers/image-spec/specs-go/v1"
1718
)
1819

1920
const (
@@ -99,6 +100,7 @@ var _ = Describe("Podman artifact", func() {
99100
It("podman artifact add with options", func() {
100101
yamlType := "text/yaml"
101102
artifact1Name := "localhost/test/artifact1"
103+
artifact2Name := "localhost/test/artifact2"
102104
artifact1File, err := createArtifactFile(1024)
103105
Expect(err).ToNot(HaveOccurred())
104106

@@ -115,9 +117,11 @@ var _ = Describe("Podman artifact", func() {
115117
Expect(a.Manifest.Layers[0].Annotations["flavor"]).To(Equal("lemon"))
116118
Expect(a.Manifest.Layers[0].MediaType).To(Equal(yamlType))
117119

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"))
120+
title := RandomString(12)
121+
annotation3 := fmt.Sprintf("%s=%s", imgspec.AnnotationTitle, title)
122+
podmanTest.PodmanExitCleanly("artifact", "add", "--annotation", annotation3, artifact2Name, artifact1File)
123+
a = podmanTest.InspectArtifact(artifact2Name)
124+
Expect(a.Manifest.Layers[0].Annotations[imgspec.AnnotationTitle]).To(Equal(title))
121125
})
122126

123127
It("podman artifact add multiple", func() {
@@ -480,9 +484,9 @@ var _ = Describe("Podman artifact", func() {
480484
Expect(a.Manifest.Layers).To(HaveLen(3))
481485

482486
for _, l := range a.Manifest.Layers {
483-
layersNames[l.Annotations["org.opencontainers.image.title"]] += 1
487+
layersNames[l.Annotations[imgspec.AnnotationTitle]] += 1
484488

485-
if l.Annotations["org.opencontainers.image.title"] == filepath.Base(artifact3File) {
489+
if l.Annotations[imgspec.AnnotationTitle] == filepath.Base(artifact3File) {
486490
Expect(l.Annotations["color"]).To(Equal("blue"))
487491
} else {
488492
Expect(l.Annotations).To(HaveLen(1))

0 commit comments

Comments
 (0)