Skip to content

Commit

Permalink
fix push path
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <[email protected]>
  • Loading branch information
Xiaoxuan Wang committed Sep 11, 2024
1 parent 72de231 commit 897b862
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
10 changes: 9 additions & 1 deletion cmd/oras/root/manifest/index/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
25 changes: 21 additions & 4 deletions test/e2e/suite/command/manifest_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -465,4 +482,4 @@ var _ = Describe("OCI image layout users:", func() {
MatchErrKeyWords("Error", "is not a manifest").Exec()
})
})
})
})

0 comments on commit 897b862

Please sign in to comment.