Merge pull request #112 from umohnani8/kpod_load

Fix misleading print statement in kpod load
This commit is contained in:
Matthew Heon 2017-12-11 13:12:43 -05:00 committed by GitHub
commit b85d0fa4ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 19 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"fmt"
"io"
"io/ioutil"
"os"
@ -101,16 +102,18 @@ func loadCmd(c *cli.Context) error {
}
src := libpod.DockerArchive + ":" + input
if err := runtime.PullImage(src, options); err != nil {
imgName, err := runtime.PullImage(src, options)
if err != nil {
src = libpod.OCIArchive + ":" + input
// generate full src name with specified image:tag
if image != "" {
src = src + ":" + image
}
if err := runtime.PullImage(src, options); err != nil {
imgName, err = runtime.PullImage(src, options)
if err != nil {
return errors.Wrapf(err, "error pulling %q", src)
}
}
fmt.Println("Loaded image: ", imgName)
return nil
}

View File

@ -113,6 +113,8 @@ func pullCmd(c *cli.Context) error {
Writer: writer,
}
return runtime.PullImage(image, options)
if _, err := runtime.PullImage(image, options); err != nil {
return errors.Wrapf(err, "error pulling image %q", image)
}
return nil
}

View File

@ -56,6 +56,7 @@ Copying config sha256:7328f6f8b41890597575cbaadc884e7386ae0acc53b747401ebce5cf0d
0 B / 1.48 KB [---------------------------------------------------------------]
Writing manifest to image destination
Storing signatures
Loaded image: registry.fedoraproject.org/fedora:latest
```
```
@ -67,6 +68,7 @@ Copying config sha256:7328f6f8b41890597575cbaadc884e7386ae0acc53b747401ebce5cf0d
0 B / 1.48 KB [---------------------------------------------------------------]
Writing manifest to image destination
Storing signatures
Loaded image: registry.fedoraproject.org/fedora:latest
```
## SEE ALSO

View File

@ -10,6 +10,8 @@ import (
"time"
cp "github.com/containers/image/copy"
"github.com/containers/image/directory"
"github.com/containers/image/docker"
dockerarchive "github.com/containers/image/docker/archive"
"github.com/containers/image/docker/reference"
"github.com/containers/image/docker/tarfile"
@ -40,12 +42,16 @@ var (
OCIArchive = ociarchive.Transport.Name()
// DirTransport is the transport for pushing and pulling
// images to and from a directory
DirTransport = "dir"
DirTransport = directory.Transport.Name()
// TransportNames are the supported transports in string form
TransportNames = [...]string{DefaultTransport, DockerArchive, OCIArchive, "ostree:", "dir:"}
// TarballTransport is the transport for importing a tar archive
// and creating a filesystem image
TarballTransport = "tarball"
TarballTransport = tarball.Transport.Name()
// Docker is the transport for docker registries
Docker = docker.Transport.Name()
// Atomic is the transport for atomic registries
Atomic = "atomic"
)
// CopyOptions contains the options given when pushing or pulling images
@ -622,12 +628,12 @@ func (r *Runtime) getPullListFromRef(srcRef types.ImageReference, imgName string
// pulled. If allTags is true, all tags for the requested image will be pulled.
// Signature validation will be performed if the Runtime has been appropriately
// configured
func (r *Runtime) PullImage(imgName string, options CopyOptions) error {
func (r *Runtime) PullImage(imgName string, options CopyOptions) (string, error) {
r.lock.Lock()
defer r.lock.Unlock()
if !r.valid {
return ErrRuntimeStopped
return "", ErrRuntimeStopped
}
// PullImage copies the image from the source to the destination
@ -645,25 +651,25 @@ func (r *Runtime) PullImage(imgName string, options CopyOptions) error {
// could be trying to pull from registry with short name
pullStructs, err = getRegistriesToTry(imgName, r.store, r.config.ImageDefaultTransport)
if err != nil {
return errors.Wrap(err, "error getting default registries to try")
return "", errors.Wrap(err, "error getting default registries to try")
}
} else {
pullStructs, err = r.getPullListFromRef(srcRef, imgName, sc)
if err != nil {
return errors.Wrapf(err, "error getting pullStruct info to pull image %q", imgName)
return "", errors.Wrapf(err, "error getting pullStruct info to pull image %q", imgName)
}
}
policyContext, err := getPolicyContext(sc)
if err != nil {
return err
return "", err
}
defer policyContext.Destroy()
copyOptions := common.GetCopyOptions(options.Writer, signaturePolicyPath, &options.DockerRegistryOptions, nil, options.SigningOptions, options.AuthFile)
for _, imageInfo := range pullStructs {
if options.Writer != nil {
// Print the following statement only when pulling from a docker or atomic registry
if options.Writer != nil && (imageInfo.srcRef.Transport().Name() == Docker || imageInfo.srcRef.Transport().Name() == Atomic) {
io.WriteString(options.Writer, fmt.Sprintf("Trying to pull %s...\n", imageInfo.image))
}
if err = cp.Image(policyContext, imageInfo.dstRef, imageInfo.srcRef, copyOptions); err != nil {
@ -671,10 +677,10 @@ func (r *Runtime) PullImage(imgName string, options CopyOptions) error {
io.WriteString(options.Writer, "Failed\n")
}
} else {
return nil
return imageInfo.image, nil
}
}
return errors.Wrapf(err, "error pulling image from %q", imgName)
return "", errors.Wrapf(err, "error pulling image from %q", imgName)
}
// PushImage pushes the given image to a location described by the given path

View File

@ -105,9 +105,6 @@ func (s *SQLState) Refresh() (err error) {
Mountpoint=?,
Pid=?;`
s.lock.Lock()
defer s.lock.Unlock()
if !s.valid {
return ErrDBClosed
}