From f183b094dee21e80e20faeaf77b069f7fabc16ab Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Sat, 2 Feb 2019 07:29:05 -0500 Subject: [PATCH] Resolve buildah.Pull to use registries.conf Currently buildah pull does not resolve images based on registries.conf This does not match the behaviour of buildah from or buildah bud This patch makes buildah pull use the same image resolver as the other two tools. Signed-off-by: Daniel J Walsh Closes: #1319 Approved by: TomSweeneyRedHat --- cmd/buildah/pull.go | 5 ++- pull.go | 80 +++++++++++++++++++++++---------------------- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/cmd/buildah/pull.go b/cmd/buildah/pull.go index 572f6fe3f1b..490deed9112 100644 --- a/cmd/buildah/pull.go +++ b/cmd/buildah/pull.go @@ -98,9 +98,8 @@ func pullCmd(c *cobra.Command, args []string, iopts pullResults) error { SystemContext: systemContext, BlobDirectory: iopts.blobCache, AllTags: iopts.allTags, - } - if !iopts.quiet { - options.ReportWriter = os.Stderr + ReportWriter: os.Stderr, + Quiet: iopts.quiet, } return buildah.Pull(getContext(), args[0], options) diff --git a/pull.go b/pull.go index aede1784b2e..64438bbb391 100644 --- a/pull.go +++ b/pull.go @@ -152,60 +152,62 @@ func localImageNameForReference(ctx context.Context, store storage.Store, srcRef // Pull copies the contents of the image from somewhere else to local storage. func Pull(ctx context.Context, imageName string, options PullOptions) error { - spec := imageName systemContext := getSystemContext(options.SystemContext, options.SignaturePolicyPath) - srcRef, err := alltransports.ParseImageName(spec) - if err != nil { - if options.Transport == "" { - options.Transport = util.DefaultTransport - } - logrus.Debugf("error parsing image name %q, trying with transport %q: %v", spec, options.Transport, err) - transport := options.Transport - if transport != util.DefaultTransport { - transport = transport + ":" - } - spec = transport + spec - srcRef2, err2 := alltransports.ParseImageName(spec) - if err2 != nil { - return errors.Wrapf(err2, "error parsing image name %q", imageName) - } - srcRef = srcRef2 + + transport := options.Transport + if transport == "" { + transport = util.DefaultTransport + } + boptions := BuilderOptions{ + FromImage: imageName, + Transport: transport, + SignaturePolicyPath: options.SignaturePolicyPath, + SystemContext: systemContext, + PullBlobDirectory: options.BlobDirectory, + ReportWriter: options.ReportWriter, } + if options.Quiet { - options.ReportWriter = nil // Turns off logging output + boptions.ReportWriter = nil // Turns off logging output } - var names []string + srcRef, img, err := resolveImage(ctx, systemContext, options.Store, boptions) + if err != nil { + return err + } + + fmt.Printf("%s\n", img.ID) + var errs *multierror.Error if options.AllTags { if srcRef.DockerReference() == nil { return errors.New("Non-docker transport is currently not supported") } + + spec := transport + srcRef.DockerReference().Name() + srcRef, err = alltransports.ParseImageName(spec) + if err != nil { + return errors.Wrapf(err, "error getting repository tags") + } tags, err := docker.GetRepositoryTags(ctx, systemContext, srcRef) if err != nil { return errors.Wrapf(err, "error getting repository tags") } for _, tag := range tags { name := spec + ":" + tag - names = append(names, name) - } - } else { - names = append(names, spec) - } - var errs *multierror.Error - for _, name := range names { - if options.ReportWriter != nil { - options.ReportWriter.Write([]byte("Pulling " + name + "\n")) - } - ref, err := pullImage(ctx, options.Store, name, options, systemContext) - if err != nil { - errs = multierror.Append(errs, err) - continue - } - img, err := is.Transport.GetStoreImage(options.Store, ref) - if err != nil { - errs = multierror.Append(errs, err) - continue + if options.ReportWriter != nil { + options.ReportWriter.Write([]byte("Pulling " + name + "\n")) + } + ref, err := pullImage(ctx, options.Store, name, options, systemContext) + if err != nil { + errs = multierror.Append(errs, err) + continue + } + img, err := is.Transport.GetStoreImage(options.Store, ref) + if err != nil { + errs = multierror.Append(errs, err) + continue + } + fmt.Printf("%s\n", img.ID) } - fmt.Printf("%s\n", img.ID) } return errs.ErrorOrNil()