From 4e5d5fbbbdcbcf7ed97b3b53a9b12455915c79fd Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Wed, 11 Sep 2024 14:59:31 +0800 Subject: [PATCH] fix push path Signed-off-by: Xiaoxuan Wang --- cmd/oras/root/manifest/index/update.go | 10 +++++++++- test/e2e/suite/command/manifest_index.go | 25 ++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/cmd/oras/root/manifest/index/update.go b/cmd/oras/root/manifest/index/update.go index 32e6c696b..b2a40354b 100644 --- a/cmd/oras/root/manifest/index/update.go +++ b/cmd/oras/root/manifest/index/update.go @@ -132,7 +132,8 @@ func updateIndex(cmd *cobra.Command, opts updateOptions) error { desc := content.NewDescriptorFromBytes(updatedIndex.MediaType, indexBytes) printUpdateStatus(status.IndexPromptUpdated, string(desc.Digest), "", opts.Printer) - return pushIndex(ctx, target, desc, indexBytes, opts.Reference, opts.tags, opts.AnnotatedReference(), opts.Printer) + path := getPushPath(opts.RawReference, opts.Type, opts.Reference, opts.Path) + return pushIndex(ctx, target, desc, indexBytes, opts.Reference, opts.tags, path, opts.Printer) } func fetchIndex(ctx context.Context, target oras.ReadOnlyTarget, opts updateOptions) (ocispec.Index, error) { @@ -240,3 +241,10 @@ func printUpdateStatus(verb string, reference string, resolvedDigest string, pri printer.Println(verb, resolvedDigest, reference) } } + +func getPushPath(rawReference string, targetType string, reference string, path string) string { + if contentutil.IsDigest(reference) { + return fmt.Sprintf("[%s] %s", targetType, path) + } + return fmt.Sprintf("[%s] %s", targetType, rawReference) +} diff --git a/test/e2e/suite/command/manifest_index.go b/test/e2e/suite/command/manifest_index.go index 34d36cc9b..f90617acf 100644 --- a/test/e2e/suite/command/manifest_index.go +++ b/test/e2e/suite/command/manifest_index.go @@ -37,10 +37,10 @@ var _ = Describe("ORAS beginners:", func() { }) When("running `manifest index update`", func() { - It("should show help doc with --tag flag", func() { - ORAS("manifest", "index", "update", "--help").MatchKeyWords("--tag", "tags for the updated index").Exec() - }) + It("should show help doc with --tag flag", func() { + ORAS("manifest", "index", "update", "--help").MatchKeyWords("--tag", "tags for the updated index").Exec() }) + }) }) func indexTestRepo(subcommand string, text string) string { @@ -197,6 +197,23 @@ var _ = Describe("1.1 registry users:", func() { ValidateIndex(content, expectedManifests) }) + It("should update and tag the updated index by --tag flag", func() { + testRepo := indexTestRepo("update", "tag-updated-index") + CopyZOTRepo(ImageRepo, testRepo) + // create an index for testing purpose + ORAS("manifest", "index", "create", RegistryRef(ZOTHost, testRepo, ""), + string(multi_arch.LinuxAMD64.Digest), string(multi_arch.LinuxARM64.Digest)).Exec() + // add a manifest to the index + ORAS("manifest", "index", "update", RegistryRef(ZOTHost, testRepo, "sha256:cce9590b1193d8bcb70467e2381dc81e77869be4801c09abe9bc274b6a1d2001"), + "--add", string(multi_arch.LinuxARMV7.Digest), "--tag", "updated"). + MatchKeyWords("sha256:84887718c9e61daa0f1996aad3ae2eb10db15dcbdab394e4b2dfee7967c55f2c").Exec() + // verify + content := ORAS("manifest", "fetch", RegistryRef(ZOTHost, testRepo, "updated")). + Exec().Out.Contents() + expectedManifests := []ocispec.Descriptor{multi_arch.LinuxAMD64, multi_arch.LinuxARM64, multi_arch.LinuxARMV7} + ValidateIndex(content, expectedManifests) + }) + It("should tell user nothing to update if no update flags are used", func() { testRepo := indexTestRepo("update", "no-flags") CopyZOTRepo(ImageRepo, testRepo) @@ -465,4 +482,4 @@ var _ = Describe("OCI image layout users:", func() { MatchErrKeyWords("Error", "is not a manifest").Exec() }) }) -}) \ No newline at end of file +})