Remove the --registry flag from podman search

Instead of setting the --registry flag to search a single registry,
prefix the registry before the image name in the input, an example is
`podman search registry.fedoraproject.org/fedora` and this will search for
the fedora image in only registry.fedoraproject.org.

Signed-off-by: umohnani8 <umohnani@redhat.com>

Closes: #1011
Approved by: rhatdan
This commit is contained in:
umohnani8 2018-06-27 13:37:56 -04:00 committed by Atomic Bot
parent 650797c016
commit 3b9046a170
4 changed files with 34 additions and 24 deletions

View File

@ -7,6 +7,7 @@ import (
"strings" "strings"
"github.com/containers/image/docker" "github.com/containers/image/docker"
"github.com/docker/distribution/reference"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/projectatomic/libpod/cmd/podman/formats" "github.com/projectatomic/libpod/cmd/podman/formats"
"github.com/projectatomic/libpod/cmd/podman/libpodruntime" "github.com/projectatomic/libpod/cmd/podman/libpodruntime"
@ -43,10 +44,6 @@ var (
Name: "no-trunc", Name: "no-trunc",
Usage: "do not truncate the output", Usage: "do not truncate the output",
}, },
cli.StringSliceFlag{
Name: "registry",
Usage: "specific registry to search",
},
cli.BoolTFlag{ cli.BoolTFlag{
Name: "tls-verify", Name: "tls-verify",
Usage: "require HTTPS and verify certificates when contacting registries (default: true)", Usage: "require HTTPS and verify certificates when contacting registries (default: true)",
@ -98,6 +95,15 @@ func searchCmd(c *cli.Context) error {
} }
term := args[0] term := args[0]
// Check if search term has a registry in it
registry, err := getRegistry(term)
if err != nil {
return errors.Wrapf(err, "error getting registry from %q", term)
}
if registry != "" {
term = term[len(registry)+1:]
}
if err := validateFlags(c, searchFlags); err != nil { if err := validateFlags(c, searchFlags); err != nil {
return err return err
} }
@ -116,7 +122,7 @@ func searchCmd(c *cli.Context) error {
filter: c.StringSlice("filter"), filter: c.StringSlice("filter"),
authfile: c.String("authfile"), authfile: c.String("authfile"),
} }
regAndSkipTLS, err := getRegistriesAndSkipTLS(c) regAndSkipTLS, err := getRegistriesAndSkipTLS(c, registry)
if err != nil { if err != nil {
return err return err
} }
@ -158,7 +164,7 @@ func (s *searchParams) headerMap() map[string]string {
} }
// A function for finding which registries can skip TLS // A function for finding which registries can skip TLS
func getRegistriesAndSkipTLS(c *cli.Context) (map[string]bool, error) { func getRegistriesAndSkipTLS(c *cli.Context, registry string) (map[string]bool, error) {
// Variables for setting up Registry and TLSVerify // Variables for setting up Registry and TLSVerify
tlsVerify := c.BoolT("tls-verify") tlsVerify := c.BoolT("tls-verify")
forceSecure := false forceSecure := false
@ -168,8 +174,8 @@ func getRegistriesAndSkipTLS(c *cli.Context) (map[string]bool, error) {
} }
var registries []string var registries []string
if len(c.StringSlice("registry")) > 0 { if registry != "" {
registries = c.StringSlice("registry") registries = append(registries, registry)
} else { } else {
var err error var err error
registries, err = sysreg.GetRegistries() registries, err = sysreg.GetRegistries()
@ -343,3 +349,11 @@ func matchesOfficialFilter(filter searchFilterParams, result docker.SearchResult
} }
return true return true
} }
func getRegistry(image string) (string, error) {
imgRef, err := reference.Parse(image)
if err != nil {
return "", err
}
return reference.Domain(imgRef.(reference.Named)), nil
}

View File

@ -1303,7 +1303,6 @@ _podman_search() {
--filter -f --filter -f
--format --format
--limit --limit
--registry
" "
local boolean_options=" local boolean_options="
--no-trunc --no-trunc

View File

@ -15,8 +15,9 @@ podman\-search - Search a registry for an image
## DESCRIPTION ## DESCRIPTION
**podman search** searches a registry or a list of registries for a matching image. **podman search** searches a registry or a list of registries for a matching image.
The user can specify which registry to search by setting the **--registry** flag, default The user can specify which registry to search by prefixing the registry in the search term
is the default registries set in the config file - **/etc/containers/registries.conf**. (example **registry.fedoraproject.org/fedora**), default is the registries in the
**registires.search** table in the config file - **/etc/containers/registries.conf**.
The number of results can be limited using the **--limit** flag. If more than one registry The number of results can be limited using the **--limit** flag. If more than one registry
is being searched, the limit will be applied to each registry. The output can be filtered is being searched, the limit will be applied to each registry. The output can be filtered
using the **--filter** flag. using the **--filter** flag.
@ -70,10 +71,6 @@ The order of the search results is the order in which the API endpoint returns t
Do not truncate the output Do not truncate the output
**--registry**
Specific registry to search (only the given registry will be searched, not the default registries)
**--tls-verify** **--tls-verify**
Require HTTPS and verify certificates when contacting registries (default: true). If explicitly set to true, Require HTTPS and verify certificates when contacting registries (default: true). If explicitly set to true,
@ -104,7 +101,7 @@ docker.io docker.io/tenstartups/alpine Alpine linux base d
``` ```
``` ```
# podman search --registry registry.fedoraproject.org fedora # podman search registry.fedoraproject.org/fedora
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
fedoraproject.org fedoraproject.org/fedora 0 fedoraproject.org fedoraproject.org/fedora 0
fedoraproject.org fedoraproject.org/fedora-minimal 0 fedoraproject.org fedoraproject.org/fedora-minimal 0
@ -117,7 +114,7 @@ docker.io docker.io/library/alpine A minimal Docker image based on Alpine Li
``` ```
``` ```
# podman search --registry registry.fedoraproject.org --format "table {{.Index}} {{.Name}}" fedora # podman search --format "table {{.Index}} {{.Name}}" registry.fedoraproject.org/fedora
INDEX NAME INDEX NAME
fedoraproject.org fedoraproject.org/fedora fedoraproject.org fedoraproject.org/fedora
fedoraproject.org fedoraproject.org/fedora-minimal fedoraproject.org fedoraproject.org/fedora-minimal

View File

@ -58,8 +58,8 @@ var _ = Describe("Podman search", func() {
Expect(search.LineInOutputContains("docker.io/library/alpine")).To(BeTrue()) Expect(search.LineInOutputContains("docker.io/library/alpine")).To(BeTrue())
}) })
It("podman search registry flag", func() { It("podman search single registry flag", func() {
search := podmanTest.Podman([]string{"search", "--registry", "registry.fedoraproject.org", "fedora-minimal"}) search := podmanTest.Podman([]string{"search", "registry.fedoraproject.org/fedora-minimal"})
search.WaitWithDefaultTimeout() search.WaitWithDefaultTimeout()
Expect(search.ExitCode()).To(Equal(0)) Expect(search.ExitCode()).To(Equal(0))
Expect(search.LineInOutputContains("fedoraproject.org/fedora-minimal")).To(BeTrue()) Expect(search.LineInOutputContains("fedoraproject.org/fedora-minimal")).To(BeTrue())
@ -128,7 +128,7 @@ var _ = Describe("Podman search", func() {
Skip("Can not start docker registry.") Skip("Can not start docker registry.")
} }
search := podmanTest.Podman([]string{"search", "--registry", "localhost:5000", "fake/image:andtag", "--tls-verify=false"}) search := podmanTest.Podman([]string{"search", "localhost:5000/fake/image:andtag", "--tls-verify=false"})
search.WaitWithDefaultTimeout() search.WaitWithDefaultTimeout()
// if this test succeeded, there will be no output (there is no entry named fake/image:andtag in an empty registry) // if this test succeeded, there will be no output (there is no entry named fake/image:andtag in an empty registry)
@ -150,7 +150,7 @@ var _ = Describe("Podman search", func() {
push := podmanTest.Podman([]string{"push", "--tls-verify=false", "--remove-signatures", ALPINE, "localhost:5000/my-alpine"}) push := podmanTest.Podman([]string{"push", "--tls-verify=false", "--remove-signatures", ALPINE, "localhost:5000/my-alpine"})
push.WaitWithDefaultTimeout() push.WaitWithDefaultTimeout()
Expect(push.ExitCode()).To(Equal(0)) Expect(push.ExitCode()).To(Equal(0))
search := podmanTest.Podman([]string{"search", "--registry", "localhost:5000", "my-alpine", "--tls-verify=false"}) search := podmanTest.Podman([]string{"search", "localhost:5000/my-alpine", "--tls-verify=false"})
search.WaitWithDefaultTimeout() search.WaitWithDefaultTimeout()
Expect(search.ExitCode()).To(Equal(0)) Expect(search.ExitCode()).To(Equal(0))
@ -176,7 +176,7 @@ var _ = Describe("Podman search", func() {
os.Setenv("REGISTRIES_CONFIG_PATH", outfile) os.Setenv("REGISTRIES_CONFIG_PATH", outfile)
ioutil.WriteFile(outfile, regFileBytes, 0644) ioutil.WriteFile(outfile, regFileBytes, 0644)
search := podmanTest.Podman([]string{"search", "--registry", "localhost:5000", "my-alpine"}) search := podmanTest.Podman([]string{"search", "localhost:5000/my-alpine"})
search.WaitWithDefaultTimeout() search.WaitWithDefaultTimeout()
Expect(search.ExitCode()).To(Equal(0)) Expect(search.ExitCode()).To(Equal(0))
@ -206,7 +206,7 @@ var _ = Describe("Podman search", func() {
os.Setenv("REGISTRIES_CONFIG_PATH", outfile) os.Setenv("REGISTRIES_CONFIG_PATH", outfile)
ioutil.WriteFile(outfile, regFileBytes, 0644) ioutil.WriteFile(outfile, regFileBytes, 0644)
search := podmanTest.Podman([]string{"search", "--registry", "localhost:5000", "my-alpine", "--tls-verify=true"}) search := podmanTest.Podman([]string{"search", "localhost:5000/my-alpine", "--tls-verify=true"})
search.WaitWithDefaultTimeout() search.WaitWithDefaultTimeout()
Expect(search.ExitCode()).To(Equal(0)) Expect(search.ExitCode()).To(Equal(0))
@ -236,7 +236,7 @@ var _ = Describe("Podman search", func() {
os.Setenv("REGISTRIES_CONFIG_PATH", outfile) os.Setenv("REGISTRIES_CONFIG_PATH", outfile)
ioutil.WriteFile(outfile, regFileBytes, 0644) ioutil.WriteFile(outfile, regFileBytes, 0644)
search := podmanTest.Podman([]string{"search", "--registry", "localhost:5000", "my-alpine"}) search := podmanTest.Podman([]string{"search", "localhost:5000/my-alpine"})
search.WaitWithDefaultTimeout() search.WaitWithDefaultTimeout()
Expect(search.ExitCode()).To(Equal(0)) Expect(search.ExitCode()).To(Equal(0))