Skip to content
Open
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
12 changes: 10 additions & 2 deletions cmd/oras/root/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ func runBackup(cmd *cobra.Command, opts *backupOptions) error {
}

for i, tag := range tags {
// Add the full image reference to the title annotation
root := roots[i]
fullRef := opts.repository + ":" + tag
if root.Annotations == nil {
root.Annotations = make(map[string]string, 1)
}
root.Annotations[ocispec.AnnotationTitle] = fullRef

referrerCount, err := func() (referrerCount int, retErr error) {
trackedDst, err := statusHandler.StartTracking(dstOCI)
if err != nil {
Expand All @@ -248,9 +256,9 @@ func runBackup(cmd *cobra.Command, opts *backupOptions) error {
}()

if opts.includeReferrers {
return backupTagWithReferrers(ctx, srcRepo, trackedDst, tag, roots[i], extCopyGraphOpts)
return backupTagWithReferrers(ctx, srcRepo, trackedDst, tag, root, extCopyGraphOpts)
}
return 0, backupTag(ctx, srcRepo, trackedDst, tag, roots[i], copyGraphOpts)
return 0, backupTag(ctx, srcRepo, trackedDst, tag, root, copyGraphOpts)
}()
if err != nil {
return fmt.Errorf("failed to back up tag %q from %q to %q: %w", tag, opts.repository, dstRoot, oerrors.UnwrapCopyError(err))
Expand Down
34 changes: 34 additions & 0 deletions test/e2e/suite/command/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
package command

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
Expand All @@ -25,6 +26,7 @@ import (

. "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"

. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
Expand Down Expand Up @@ -471,6 +473,38 @@ var _ = Describe("ORAS users:", func() {
})
})

When("verifying annotations", func() {
It("should set org.opencontainers.image.title annotation with full reference", func() {
tmpDir := GinkgoT().TempDir()
outDir := filepath.Join(tmpDir, "backup-title-annotation")
repo := backupTestRepo("title-annotation")
tag := "v1.0"
srcRef := RegistryRef(ZOTHost, repo, tag)

prepare(RegistryRef(ZOTHost, ArtifactRepo, foobar.Tag), srcRef)

ORAS("backup", "--output", outDir, srcRef).Exec()

verifyBackupDirectoryStructure(outDir)

// Read and verify index.json annotations
indexPath := filepath.Join(outDir, "index.json")
indexBytes, err := os.ReadFile(indexPath)
Expect(err).ToNot(HaveOccurred())

var index ocispec.Index
err = json.Unmarshal(indexBytes, &index)
Expect(err).ToNot(HaveOccurred())
Expect(index.Manifests).ToNot(BeEmpty())

// Verify annotations on the first manifest
annotations := index.Manifests[0].Annotations
Expect(annotations["org.opencontainers.image.ref.name"]).To(Equal(tag))
expectedFullRef := fmt.Sprintf("%s/%s:%s", ZOTHost, repo, tag)
Expect(annotations[ocispec.AnnotationTitle]).To(Equal(expectedFullRef))
})
})

When("handling error cases", func() {
It("should fail when output directory cannot be created", func() {
// Create a file that will conflict with our output path
Expand Down
Loading