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

Search repository tags using --list-tags #7836

Merged
merged 1 commit into from
Oct 12, 2020

Conversation

QiWang19
Copy link
Collaborator

For fix of BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1684263
Add --list-tags to podman search to return a table the repository tags.

Signed-off-by: Qi Wang qiwan@redhat.com

@@ -65,6 +68,10 @@ Example if limit is 10 and two registries are being searched, the total
number of results will be 20, 10 from each (if there are at least 10 matches in each).
The order of the search results is the order in which the API endpoint returns the results.

**--list-tags**

Search tags available in the repository. Note: the result only contains the Image name and its tag.
Copy link
Member

Choose a reason for hiding this comment

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

As we can use search on registry.redhat.io/ and get all of the images in the repository:

Suggested change
Search tags available in the repository. Note: the result only contains the Image name and its tag.
List the available tags in the repository for each image found. Note: the result contains the Image name and its tag, one line for every tag associated with the image.

dockerPrefix := fmt.Sprintf("%s://", docker.Transport.Name())
imageRef, err := alltransports.ParseImageName(fmt.Sprintf("%s/%s", registry, term))
if err == nil && imageRef.Transport().Name() != docker.Transport.Name() {
logrus.Errorf("reference %q must be a docker reference", term)
Copy link
Member

Choose a reason for hiding this comment

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

@rhatdan got a less Docker way to say this? Perhaps:

Suggested change
logrus.Errorf("reference %q must be a docker reference", term)
logrus.Errorf("reference %q must be a valid container image reference", term)

Copy link
Member

Choose a reason for hiding this comment

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

I think "docker" is more accurate in containers-transports(5) terms as all of the transports refer to a container image.

Copy link
Member

@TomSweeneyRedHat TomSweeneyRedHat Sep 30, 2020

Choose a reason for hiding this comment

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

@vrothberg sometimes I really don't like it when you're right... Let's leave it then, thx for the follow up.

search = podmanTest.Podman([]string{"search", "--filter=is-official", "--list-tags", "docker.io/library/alpine"})
search.WaitWithDefaultTimeout()
Expect(search.ExitCode()).To(Not(Equal(0)))
})
Copy link
Member

Choose a reason for hiding this comment

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

need to add a search for a registry too with a backslash only, no image name. For that and for this test, add a test to make sure the returned lines are greater than 1 and perhaps greater than 2 or 3.

Copy link
Member

Choose a reason for hiding this comment

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

I see you added the test with lines >2, ty! Could you also add a test that lists the tags for docker.io/library/ (no image, just a backslash). According to the doc, it's allowed: podman search registry.fedoraproject.org/ and if it is NOT allowed with the --list-tags option, it would be good to test that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Test added. It's not allowed, no tags will be returned for docker.io/library/

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with not allowing it, but we really should add a note to the --list-tags option in the man page saying that, and preferably raise some kind of error message telling the user that they need to specify an image or at least return an "image not found" kind of message.

Copy link
Member

Choose a reason for hiding this comment

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

Hope I'm not being too painful @QiWang19 !

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the error would be "library/" must be a docker reference". Add to the doc "the search term should be repository name". Would this work?
$ bin/podman search --list-tags docker.io/library/
ERRO[0000] error listing registry tags "docker.io": reference "library/" must be a docker reference

Copy link
Member

Choose a reason for hiding this comment

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

OK, first off, I'd still like to see a test for docker.io/library/ (or some other registry) and then test for the appropriate error message. I'm finding the man page to be very confusing at the moment, will try to suggest a rewrite.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

search does not return error, it logs errors to standard logger and returns the 0 entry of the result.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good and it looks like you've added a test for that, TY!

libpod/image/search.go Show resolved Hide resolved
dockerPrefix := fmt.Sprintf("%s://", docker.Transport.Name())
imageRef, err := alltransports.ParseImageName(fmt.Sprintf("%s/%s", registry, term))
if err == nil && imageRef.Transport().Name() != docker.Transport.Name() {
logrus.Errorf("reference %q must be a docker reference", term)
Copy link
Member

Choose a reason for hiding this comment

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

I think "docker" is more accurate in containers-transports(5) terms as all of the transports refer to a container image.

@@ -591,6 +591,7 @@ func SearchImages(w http.ResponseWriter, r *http.Request) {
NoTrunc bool `json:"noTrunc"`
Filters []string `json:"filters"`
TLSVerify bool `json:"tlsVerify"`
ListTags bool `json:"listTags"`
Copy link
Member

Choose a reason for hiding this comment

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

We also need to extend the swagger docs in pkg/api/server/register_images.go

@QiWang19
Copy link
Collaborator Author

@containers/podman-maintainers PTAL

@@ -86,6 +86,7 @@ func searchFlags(flags *pflag.FlagSet) {
flags.BoolVar(&searchOptions.NoTrunc, "no-trunc", false, "Do not truncate the output")
flags.StringVar(&searchOptions.Authfile, "authfile", auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
flags.BoolVar(&searchOptions.TLSVerifyCLI, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries")
flags.BoolVar(&searchOptions.ListTags, "list-tags", false, "Search the tags of the input registry")
Copy link
Member

Choose a reason for hiding this comment

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

List the tags ...

@@ -126,6 +127,19 @@ func imageSearch(cmd *cobra.Command, args []string) error {
return err
}

if searchOptions.ListTags {
if len(searchOptions.Filters) != 0 {
return errors.Errorf("filters are not applicable to search tags result")
Copy link
Member

Choose a reason for hiding this comment

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

applicable to list tags result

@@ -207,6 +217,45 @@ func searchImageInRegistry(term string, registry string, options SearchOptions)
return paramsArr
}

func searchRepositoryTags(registry, term string, sc *types.SystemContext, options SearchOptions) []SearchResult {
Copy link
Member

Choose a reason for hiding this comment

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

This should return real errors, and not just write them to the screen.

dockerPrefix := fmt.Sprintf("%s://", docker.Transport.Name())
imageRef, err := alltransports.ParseImageName(fmt.Sprintf("%s/%s", registry, term))
if err == nil && imageRef.Transport().Name() != docker.Transport.Name() {
logrus.Errorf("reference %q must be a docker reference", term)
Copy link
Member

Choose a reason for hiding this comment

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

Return this error

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@rhatdan
Copy link
Member

rhatdan commented Oct 1, 2020

/approve

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: QiWang19, rhatdan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 1, 2020
@rhatdan
Copy link
Member

rhatdan commented Oct 1, 2020

LGTM

@rhatdan
Copy link
Member

rhatdan commented Oct 1, 2020

@containers/podman-maintainers PTAL

@TomSweeneyRedHat
Copy link
Member

Looks like there are still comments from @vrothberg and me that have not yet been addressed....

@QiWang19
Copy link
Collaborator Author

QiWang19 commented Oct 1, 2020

Looks like there are still comments from @vrothberg and me that have not yet been addressed....

fixed that in pkg/api/server/register_images.go

@QiWang19 QiWang19 force-pushed the search-tags branch 5 times, most recently from 39e8d00 to 600c1dd Compare October 5, 2020 17:47

List the available tags in the repository for each image found. Note: --list-tags requires the search term to be a full
repository name. If not specified the registry server, default registries will be searched through (in /etc/containers/registries.conf). The result contains the Image name and its tag, one line for every tag associated with the image.

Copy link
Member

Choose a reason for hiding this comment

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

This is all very contradictory. You're saying at the start that you'll list all tags for each image found in the repository, and then that the full name must be used. I think from our conversations that the image name with the repository must be supplied. I.e. you must do docker.io/library/alpine and you can't do docker.io/library/ or alpine. Given that assumption:

Suggested change
List the available tags in the repository for the specified image. **Note:** --list-tags requires the search term to be a fully
specified image name. The result contains the Image name and its tag, one line for every tag associated with the image.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the docker.io/library/alpine refer to a repository name, if append a tag to it, it will refer to an image?

Copy link
Member

Choose a reason for hiding this comment

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

@QiWang19 yeah, it's confusing and I may not have helped matters. When you push a container image to a registry, it creates a repository from it. How's this?

List the available tags in the repository for the specified image. **Note:** --list-tags requires the search term to be a fully
specified image. The result contains the Image name and its tag, one line for every tag found in the repository.

Copy link
Member

Choose a reason for hiding this comment

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

👍
nicely done @QiWang19

@QiWang19 QiWang19 force-pushed the search-tags branch 3 times, most recently from 9b70587 to b8c5af2 Compare October 7, 2020 17:47
@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 8, 2020
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 8, 2020
For fix of BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1684263
Add --list-tags to podman search to return a table the repository tags.

Signed-off-by: Qi Wang <qiwan@redhat.com>
Copy link
Member

@TomSweeneyRedHat TomSweeneyRedHat left a comment

Choose a reason for hiding this comment

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

LGTM

@rhatdan
Copy link
Member

rhatdan commented Oct 10, 2020

/lgtm
/hold

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 10, 2020
@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 10, 2020
@rhatdan
Copy link
Member

rhatdan commented Oct 12, 2020

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 12, 2020
@openshift-merge-robot openshift-merge-robot merged commit 212011f into containers:master Oct 12, 2020
@QiWang19 QiWang19 deleted the search-tags branch October 12, 2020 14:43
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants