Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show annotations in oras discover tree format output #735

Merged
merged 7 commits into from
Jan 9, 2023

Conversation

qweeah
Copy link
Contributor

@qweeah qweeah commented Jan 6, 2023

This PR enriches tree output of oras discover. Artifact annotations will be shown in yaml format if --verbose flag is set.

Resolves #631

$ IMAGE="localhost:5000/test:anno"
$ oras-demo push $IMAGE image
Uploading 254eddf15d95 image
Uploaded  254eddf15d95 image
Pushed localhost:5000/test:anno
Digest: sha256:93305aefab90f837c555e42afcce5a3d92e23180d5dc64e37363d78d65c93306
$ oras-demo attach $IMAGE sig -a "key: "="value ' " --artifact-type test.anno
Uploading 0a017e570e0b sig
Uploaded  0a017e570e0b sig
Attached to localhost:5000/test@sha256:93305aefab90f837c555e42afcce5a3d92e23180d5dc64e37363d78d65c93306
Digest: sha256:0f6ac3195806949d22ac6eaab804fa4fd5c25974acdfb003ddb4f24cc1b6da62
$ oras-demo attach $IMAGE -a "key"="value" --artifact-type test.anno
Uploading empty artifact
Attached to localhost:5000/test@sha256:93305aefab90f837c555e42afcce5a3d92e23180d5dc64e37363d78d65c93306
Digest: sha256:b9311291861ce206db11fdaf30a28492bac6a66b38b2183b17557cb49c7e18c2
$ oras-demo discover $IMAGE -o tree
localhost:5000/test:anno
└── test.anno
    ├── sha256:0f6ac3195806949d22ac6eaab804fa4fd5c25974acdfb003ddb4f24cc1b6da62
    └── sha256:b9311291861ce206db11fdaf30a28492bac6a66b38b2183b17557cb49c7e18c2
$ oras-demo discover $IMAGE -o tree -v
localhost:5000/test:anno
└── test.anno
    ├── sha256:0f6ac3195806949d22ac6eaab804fa4fd5c25974acdfb003ddb4f24cc1b6da62
    │   ├── 'key: ': 'value '' '
    │   └── org.opencontainers.image.created: "2023-01-09T02:24:17Z"
    └── sha256:b9311291861ce206db11fdaf30a28492bac6a66b38b2183b17557cb49c7e18c2
        ├── key: value
        └── org.opencontainers.image.created: "2023-01-09T02:24:37Z"

Signed-off-by: Billy Zha jinzha1@microsoft.com

Signed-off-by: Billy Zha <jinzha1@microsoft.com>
@codecov-commenter
Copy link

codecov-commenter commented Jan 6, 2023

Codecov Report

Merging #735 (53b96a5) into main (cdeca2f) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #735   +/-   ##
=======================================
  Coverage   73.17%   73.17%           
=======================================
  Files          16       16           
  Lines         574      574           
=======================================
  Hits          420      420           
  Misses        123      123           
  Partials       31       31           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@shizhMSFT
Copy link
Contributor

Will <key>: <value> better than <key> = <value>?

@qweeah
Copy link
Contributor Author

qweeah commented Jan 6, 2023

Will <key>: <value> better than <key> = <value>?

What's the intention of using colon? If it's for automation, then json output is definitely a better option. Since annotation key can contain a colon. If we use colon we'd better double quotes the key and value, with double quotes escaped. E.g. showing "my:key" : "my\\":value" for sha256:7b2b5d

$ oras-demo attach localhost:5000/test:anno -a "my:key"="my\":value" --artifact-type test.more
$ oras-demo attach locadiscover localhost:5000/test:anno -o tree
localhost:5000/test:anno
├── test
│   └── sha256:df31b7792e0f0d3bffa5843da07bfd7ab27c1ec756c37c5c55c56eaf44f3f636
│       └── org.opencontainers.image.created = 2023-01-05T09:08:01Z
└── test.more
    ├── sha256:d6e7f841cca49f4bb90f3f3a96183269f6b00a3eae87f9b1cd7655feb8a8d2f0
    │   ├── org.opencontainers.image.created = 2023-01-05T15:16:31Z
    │   ├── test = 123
    │   └── test2 = 456
    └── sha256:7b2b5d28bde095f2949fb62af5a75d05f1e9e7d0f80f2eab12b44ecd79f13442
        ├── my:key = my":value
        └── org.opencontainers.image.created = 2023-01-06T04:11:47Z

cc @yizha1 @FeynmanZhou

@shizhMSFT
Copy link
Contributor

What's the intention of using colon?

It is for human readability. Basically, <key>: <value> format is YAML like.

@qweeah qweeah requested a review from shizhMSFT January 9, 2023 02:42
cmd/oras/discover.go Outdated Show resolved Hide resolved
cmd/oras/discover.go Outdated Show resolved Hide resolved
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
@qweeah qweeah requested a review from shizhMSFT January 9, 2023 06:48
cmd/oras/discover.go Outdated Show resolved Hide resolved
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
if err != nil {
return err
}
referrerNode.AddPathString(strings.TrimSpace(string(bytes)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason to trim space?

Copy link
Contributor Author

@qweeah qweeah Jan 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. yaml.Marshal will add a new line automatically at the end of any object, which makes the tree view less prettified
    image

  2. Heading/trailing spaces in key/value will be quoted by yaml.Marshal, thus trimming space will not cause unwanted change to annotation key/value

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shizhMSFT shizhMSFT merged commit 1659011 into oras-project:main Jan 9, 2023
TerryHowe pushed a commit to TerryHowe/oras that referenced this pull request Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show annotations in oras discover
3 participants