Skip to content

Commit

Permalink
Resolve buildah.Pull to use registries.conf
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rhatdan committed Feb 2, 2019
1 parent 973bb88 commit 8842b99
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 42 deletions.
5 changes: 2 additions & 3 deletions cmd/buildah/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,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)
Expand Down
78 changes: 39 additions & 39 deletions pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,60 +152,60 @@ 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,
}

if options.Quiet {
options.ReportWriter = nil // Turns off logging output
boptions.ReportWriter = nil // Turns off logging output
}
var names []string
srcRef, _, err := resolveImage(ctx, systemContext, options.Store, boptions)
if err != nil {
return err
}

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()
Expand Down

0 comments on commit 8842b99

Please sign in to comment.