Image library stage 4 - create and commit

Migrate the podman create and commit subcommandis to leverage the images library.  I also had
to migrate the cmd/ portions of run and rmi.

Signed-off-by: baude <bbaude@redhat.com>

Closes: #498
Approved by: mheon
This commit is contained in:
baude
2018-03-15 10:06:49 -05:00
committed by Atomic Bot
parent ecfa321288
commit 38a1b2f16d
17 changed files with 304 additions and 286 deletions

View File

@ -2,11 +2,12 @@ package main
import ( import (
"fmt" "fmt"
"io"
"os" "os"
"github.com/opencontainers/image-spec/specs-go/v1" "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/projectatomic/libpod/libpod" "github.com/projectatomic/libpod/libpod/image"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -58,8 +59,11 @@ func commitCmd(c *cli.Context) error {
} }
defer runtime.Shutdown(false) defer runtime.Shutdown(false)
var opts libpod.CopyOptions var (
var container string container string
reference string
writer io.Writer
)
args := c.Args() args := c.Args()
switch len(args) { switch len(args) {
case 0: case 0:
@ -68,7 +72,7 @@ func commitCmd(c *cli.Context) error {
container = args[0] container = args[0]
case 2: case 2:
container = args[0] container = args[0]
opts.Reference = args[1] reference = args[1]
default: default:
return errors.Errorf("too many arguments. Usage CONTAINER [REFERENCE]") return errors.Errorf("too many arguments. Usage CONTAINER [REFERENCE]")
} }
@ -90,20 +94,18 @@ func commitCmd(c *cli.Context) error {
History: history, History: history,
Author: c.String("author"), Author: c.String("author"),
} }
opts.ImageConfig = config
opts.Writer = nil
if !c.Bool("quiet") { if !c.Bool("quiet") {
opts.Writer = os.Stderr writer = os.Stderr
} }
ctr, err := runtime.LookupContainer(container) ctr, err := runtime.LookupContainer(container)
if err != nil { if err != nil {
return errors.Wrapf(err, "error looking up container %q", container) return errors.Wrapf(err, "error looking up container %q", container)
} }
img, err := ctr.Commit(c.BoolT("pause"), opts) newImage, err := ctr.Commit(c.BoolT("pause"), reference, writer, image.SigningOptions{}, config)
if err == nil { if err == nil {
fmt.Println(img.ID) fmt.Println(newImage.ID())
} }
return nil return nil
} }

View File

@ -3,13 +3,6 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"net"
"os"
"strconv"
"strings"
"syscall"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/signal" "github.com/docker/docker/pkg/signal"
"github.com/docker/go-connections/nat" "github.com/docker/go-connections/nat"
@ -17,10 +10,16 @@ import (
"github.com/opencontainers/selinux/go-selinux/label" "github.com/opencontainers/selinux/go-selinux/label"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/projectatomic/libpod/libpod" "github.com/projectatomic/libpod/libpod"
"github.com/projectatomic/libpod/libpod/image"
"github.com/projectatomic/libpod/pkg/inspect" "github.com/projectatomic/libpod/pkg/inspect"
"github.com/projectatomic/libpod/pkg/util" "github.com/projectatomic/libpod/pkg/util"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/urfave/cli" "github.com/urfave/cli"
"net"
"os"
"strconv"
"strings"
"syscall"
) )
type mountType string type mountType string
@ -154,6 +153,7 @@ var createCommand = cli.Command{
func createCmd(c *cli.Context) error { func createCmd(c *cli.Context) error {
// TODO should allow user to create based off a directory on the host not just image // TODO should allow user to create based off a directory on the host not just image
// Need CLI support for this // Need CLI support for this
if err := validateFlags(c, createFlags); err != nil { if err := validateFlags(c, createFlags); err != nil {
return err return err
} }
@ -174,11 +174,14 @@ func createCmd(c *cli.Context) error {
} }
defer runtime.Shutdown(false) defer runtime.Shutdown(false)
imageName, _, data, err := imageData(c, runtime, c.Args()[0]) rtc := runtime.GetConfig()
newImage, err := runtime.ImageRuntime().New(c.Args()[0], rtc.SignaturePolicyPath, "", os.Stderr, nil, image.SigningOptions{})
if err != nil { if err != nil {
return err return err
} }
createConfig, err := parseCreateOpts(c, runtime, imageName, data) data, err := libpod.GetImageData(newImage)
createConfig, err := parseCreateOpts(c, runtime, newImage.Names()[0], data)
if err != nil { if err != nil {
return err return err
} }
@ -379,46 +382,6 @@ func exposedPorts(c *cli.Context, imageExposedPorts map[string]struct{}) (map[na
return portBindings, nil return portBindings, nil
} }
// imageData pulls down the image if not stored locally and extracts the
// default container runtime data out of it. imageData returns the data
// to the caller. Example Data: Entrypoint, Env, WorkingDir, Labels ...
func imageData(c *cli.Context, runtime *libpod.Runtime, image string) (string, string, *inspect.ImageData, error) {
var (
err error
imageName, imageID string
)
// Deal with the image after all the args have been checked
createImage := runtime.NewImage(image)
imageName, imageID, _ = createImage.GetLocalImageName()
if createImage.LocalName == "" {
// The image wasnt found by the user input'd name or its fqname
// Pull the image
var writer io.Writer
if !c.Bool("quiet") {
writer = os.Stderr
}
createImage.Pull(writer)
}
createImage.LocalName = imageName
if imageName == "" {
imageName, err = createImage.GetFQName()
_, imageID, _ = createImage.GetLocalImageName()
}
if err != nil {
return "", "", nil, err
}
storageImage, err := runtime.GetImage(imageName)
if err != nil {
return "", "", nil, errors.Wrapf(err, "error getting storage image %q", image)
}
data, err := runtime.GetImageInspectInfo(*storageImage)
if err != nil {
return "", "", nil, errors.Wrapf(err, "error parsing image data %q", image)
}
return imageName, imageID, data, err
}
// Parses CLI options related to container creation into a config which can be // Parses CLI options related to container creation into a config which can be
// parsed into an OCI runtime spec // parsed into an OCI runtime spec
func parseCreateOpts(c *cli.Context, runtime *libpod.Runtime, imageName string, data *inspect.ImageData) (*createConfig, error) { func parseCreateOpts(c *cli.Context, runtime *libpod.Runtime, imageName string, data *inspect.ImageData) (*createConfig, error) {

View File

@ -98,8 +98,11 @@ func historyCmd(c *cli.Context) error {
if len(args) > 1 { if len(args) > 1 {
return errors.Errorf("podman history takes at most 1 argument") return errors.Errorf("podman history takes at most 1 argument")
} }
imgName := args[0]
image, err := runtime.ImageRuntime().NewFromLocal(args[0])
if err != nil {
return err
}
opts := historyOptions{ opts := historyOptions{
human: c.BoolT("human"), human: c.BoolT("human"),
noTrunc: c.Bool("no-trunc"), noTrunc: c.Bool("no-trunc"),
@ -107,12 +110,12 @@ func historyCmd(c *cli.Context) error {
format: format, format: format,
} }
history, layers, imageID, err := runtime.GetHistory(imgName) history, layers, err := image.History()
if err != nil { if err != nil {
return errors.Wrapf(err, "error getting history of image %q", imgName) return errors.Wrapf(err, "error getting history of image %q", image.InputName)
} }
return generateHistoryOutput(history, layers, imageID, opts) return generateHistoryOutput(history, layers, image.ID(), opts)
} }
func genHistoryFormat(format string, quiet bool) string { func genHistoryFormat(format string, quiet bool) string {

View File

@ -11,7 +11,7 @@ import (
"github.com/opencontainers/image-spec/specs-go/v1" "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/projectatomic/libpod/libpod" "github.com/projectatomic/libpod/libpod/image"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -55,8 +55,12 @@ func importCmd(c *cli.Context) error {
} }
defer runtime.Shutdown(false) defer runtime.Shutdown(false)
var opts libpod.CopyOptions var (
var source string source string
reference string
writer io.Writer
)
args := c.Args() args := c.Args()
switch len(args) { switch len(args) {
case 0: case 0:
@ -65,7 +69,7 @@ func importCmd(c *cli.Context) error {
source = args[0] source = args[0]
case 2: case 2:
source = args[0] source = args[0]
opts.Reference = args[1] reference = args[1]
default: default:
return errors.Errorf("too many arguments. Usage TARBALL [REFERENCE]") return errors.Errorf("too many arguments. Usage TARBALL [REFERENCE]")
} }
@ -87,11 +91,9 @@ func importCmd(c *cli.Context) error {
History: history, History: history,
} }
opts.ImageConfig = config writer = nil
opts.Writer = nil
if !c.Bool("quiet") { if !c.Bool("quiet") {
opts.Writer = os.Stderr writer = os.Stderr
} }
// if source is a url, download it and save to a temp file // if source is a url, download it and save to a temp file
@ -105,9 +107,9 @@ func importCmd(c *cli.Context) error {
source = file source = file
} }
img, err := runtime.ImportImage(source, opts) newImage, err := runtime.Import(source, reference, writer, image.SigningOptions{}, config)
if err == nil { if err == nil {
fmt.Println(img.ID) fmt.Println(newImage.ID())
} }
return err return err
} }

View File

@ -128,31 +128,27 @@ func iterateInput(c *cli.Context, args []string, runtime *libpod.Runtime, inspec
break break
} }
case inspectTypeImage: case inspectTypeImage:
newImage := runtime.NewImage(input) image, err := runtime.ImageRuntime().NewFromLocal(input)
newImage.GetLocalImageName()
image, err := runtime.GetImage(newImage.LocalName)
if err != nil { if err != nil {
inspectError = errors.Wrapf(err, "error getting image %q", input) inspectError = errors.Wrapf(err, "error getting image %q", input)
break break
} }
data, err = runtime.GetImageInspectInfo(*image) data, err = libpod.GetImageData(image)
if err != nil { if err != nil {
inspectError = errors.Wrapf(err, "error parsing image data %q", image.ID) inspectError = errors.Wrapf(err, "error parsing image data %q", image.ID())
break break
} }
case inspectAll: case inspectAll:
ctr, err := runtime.LookupContainer(input) ctr, err := runtime.LookupContainer(input)
if err != nil { if err != nil {
newImage := runtime.NewImage(input) image, err := runtime.ImageRuntime().NewFromLocal(input)
newImage.GetLocalImageName()
image, err := runtime.GetImage(newImage.LocalName)
if err != nil { if err != nil {
inspectError = errors.Wrapf(err, "error getting image %q", input) inspectError = errors.Wrapf(err, "error getting image %q", input)
break break
} }
data, err = runtime.GetImageInspectInfo(*image) data, err = libpod.GetImageData(image)
if err != nil { if err != nil {
inspectError = errors.Wrapf(err, "error parsing image data %q", image.ID) inspectError = errors.Wrapf(err, "error parsing image data %q", image.ID())
break break
} }
} else { } else {

View File

@ -6,6 +6,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/projectatomic/libpod/libpod" "github.com/projectatomic/libpod/libpod"
"github.com/projectatomic/libpod/libpod/image"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -51,28 +52,37 @@ func rmiCmd(c *cli.Context) error {
return errors.Errorf("when using the --all switch, you may not pass any images names or IDs") return errors.Errorf("when using the --all switch, you may not pass any images names or IDs")
} }
imagesToDelete := args[:] images := args[:]
var lastError error var lastError error
var imagesToDelete []*image.Image
if removeAll { if removeAll {
localImages, err := runtime.GetImages(&libpod.ImageFilterParams{}) imagesToDelete, err = runtime.GetImages(&libpod.ImageFilterParams{})
if err != nil { if err != nil {
return errors.Wrapf(err, "unable to query local images") return errors.Wrapf(err, "unable to query local images")
} }
for _, image := range localImages { } else {
imagesToDelete = append(imagesToDelete, image.ID) // Create image.image objects for deletion from user input
for _, i := range images {
newImage, err := runtime.ImageRuntime().NewFromLocal(i)
if err != nil {
fmt.Fprintln(os.Stderr, err)
continue
}
imagesToDelete = append(imagesToDelete, newImage)
} }
} }
if len(imagesToDelete) == 0 {
for _, arg := range imagesToDelete { return errors.Errorf("no valid images to delete")
image := runtime.NewImage(arg) }
iid, err := image.Remove(c.Bool("force")) for _, img := range imagesToDelete {
err := runtime.RemoveImage(img, c.Bool("force"))
if err != nil { if err != nil {
if lastError != nil { if lastError != nil {
fmt.Fprintln(os.Stderr, lastError) fmt.Fprintln(os.Stderr, lastError)
} }
lastError = err lastError = err
} else { } else {
fmt.Println(iid) fmt.Println(img.ID())
} }
} }
return lastError return lastError

View File

@ -7,8 +7,10 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/projectatomic/libpod/libpod" "github.com/projectatomic/libpod/libpod"
"github.com/projectatomic/libpod/libpod/image"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/urfave/cli" "github.com/urfave/cli"
"os"
) )
var runDescription = "Runs a command in a new container from the given image" var runDescription = "Runs a command in a new container from the given image"
@ -49,12 +51,15 @@ func runCmd(c *cli.Context) error {
return errors.Errorf("image name or ID is required") return errors.Errorf("image name or ID is required")
} }
imageName, _, data, err := imageData(c, runtime, c.Args()[0]) rtc := runtime.GetConfig()
newImage, err := runtime.ImageRuntime().New(c.Args()[0], rtc.SignaturePolicyPath, "", os.Stderr, nil, image.SigningOptions{})
data, err := libpod.GetImageData(newImage)
if err != nil { if err != nil {
return err return err
} }
createConfig, err := parseCreateOpts(c, runtime, imageName, data) createConfig, err := parseCreateOpts(c, runtime, newImage.Names()[0], data)
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,16 +1,18 @@
package libpod package libpod
import ( import (
"io"
"io/ioutil" "io/ioutil"
"os" "os"
"strconv" "strconv"
"time" "time"
"github.com/containers/storage"
"github.com/docker/docker/daemon/caps" "github.com/docker/docker/daemon/caps"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/projectatomic/libpod/libpod/driver" "github.com/projectatomic/libpod/libpod/driver"
"github.com/projectatomic/libpod/libpod/image"
"github.com/projectatomic/libpod/pkg/inspect" "github.com/projectatomic/libpod/pkg/inspect"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
@ -532,7 +534,7 @@ func (c *Container) Inspect(size bool) (*inspect.ContainerInspectData, error) {
// Commit commits the changes between a container and its image, creating a new // Commit commits the changes between a container and its image, creating a new
// image // image
func (c *Container) Commit(pause bool, options CopyOptions) (*storage.Image, error) { func (c *Container) Commit(pause bool, reference string, writer io.Writer, signingOptions image.SigningOptions, imageConfig ociv1.Image) (*image.Image, error) {
if !c.locked { if !c.locked {
c.lock.Lock() c.lock.Lock()
defer c.lock.Unlock() defer c.lock.Unlock()
@ -563,7 +565,7 @@ func (c *Container) Commit(pause bool, options CopyOptions) (*storage.Image, err
if err := c.export(tempFile.Name()); err != nil { if err := c.export(tempFile.Name()); err != nil {
return nil, err return nil, err
} }
return c.runtime.ImportImage(tempFile.Name(), options) return image.Import(tempFile.Name(), reference, writer, signingOptions, imageConfig, c.runtime.imageRuntime)
} }
// Wait blocks on a container to exit and returns its exit code // Wait blocks on a container to exit and returns its exit code

View File

@ -926,16 +926,14 @@ func (c *Container) addImageVolumes(g *generate.Generator) error {
if !c.state.Mounted { if !c.state.Mounted {
return errors.Wrapf(ErrInternal, "container is not mounted") return errors.Wrapf(ErrInternal, "container is not mounted")
} }
newImage, err := c.runtime.imageRuntime.NewFromLocal(c.config.RootfsImageID)
imageStorage, err := c.runtime.getImage(c.config.RootfsImageID)
if err != nil { if err != nil {
return err return err
} }
imageData, err := c.runtime.getImageInspectInfo(*imageStorage) imageData, err := GetImageData(newImage)
if err != nil { if err != nil {
return err return err
} }
for k := range imageData.ContainerConfig.Volumes { for k := range imageData.ContainerConfig.Volumes {
mount := spec.Mount{ mount := spec.Mount{
Destination: k, Destination: k,

View File

@ -12,6 +12,7 @@ import (
cp "github.com/containers/image/copy" cp "github.com/containers/image/copy"
"github.com/containers/image/docker/reference" "github.com/containers/image/docker/reference"
is "github.com/containers/image/storage" is "github.com/containers/image/storage"
"github.com/containers/image/tarball"
"github.com/containers/image/transports/alltransports" "github.com/containers/image/transports/alltransports"
"github.com/containers/image/types" "github.com/containers/image/types"
"github.com/containers/storage" "github.com/containers/storage"
@ -19,6 +20,8 @@ import (
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
ociv1 "github.com/opencontainers/image-spec/specs-go/v1" ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/projectatomic/libpod/libpod/common"
"github.com/projectatomic/libpod/libpod/driver"
"github.com/projectatomic/libpod/pkg/inspect" "github.com/projectatomic/libpod/pkg/inspect"
"github.com/projectatomic/libpod/pkg/util" "github.com/projectatomic/libpod/pkg/util"
) )
@ -36,12 +39,20 @@ type Image struct {
// Runtime contains the store // Runtime contains the store
type Runtime struct { type Runtime struct {
store storage.Store store storage.Store
SignaturePolicyPath string
} }
// NewImageRuntime creates an Image Runtime including the store given // NewImageRuntimeFromStore creates an ImageRuntime based on a provided store
func NewImageRuntimeFromStore(store storage.Store) *Runtime {
return &Runtime{
store: store,
}
}
// NewImageRuntimeFromOptions creates an Image Runtime including the store given
// store options // store options
func NewImageRuntime(options storage.StoreOptions) (*Runtime, error) { func NewImageRuntimeFromOptions(options storage.StoreOptions) (*Runtime, error) {
if reexec.Init() { if reexec.Init() {
return nil, errors.Errorf("unable to reexec") return nil, errors.Errorf("unable to reexec")
} }
@ -110,10 +121,12 @@ func (ir *Runtime) New(name, signaturePolicyPath, authfile string, writer io.Wri
} }
// The image is not local // The image is not local
if signaturePolicyPath == "" {
signaturePolicyPath = ir.SignaturePolicyPath
}
imageName, err := newImage.pullImage(writer, authfile, signaturePolicyPath, signingoptions, dockeroptions) imageName, err := newImage.pullImage(writer, authfile, signaturePolicyPath, signingoptions, dockeroptions)
if err != nil { if err != nil {
return &newImage, errors.Errorf("unable to pull %s", name) return nil, errors.Errorf("unable to pull %s", name)
} }
newImage.InputName = imageName newImage.InputName = imageName
@ -141,7 +154,7 @@ func (i *Image) reloadImage() error {
// getLocalImage resolves an unknown input describing an image and // getLocalImage resolves an unknown input describing an image and
// returns a storage.Image or an error. It is used by NewFromLocal. // returns a storage.Image or an error. It is used by NewFromLocal.
func (i *Image) getLocalImage() (*storage.Image, error) { func (i *Image) getLocalImage() (*storage.Image, error) {
imageError := fmt.Sprintf("unable to find '%s' in local storage\n", i.InputName) imageError := fmt.Sprintf("unable to find '%s' in local storage", i.InputName)
if i.InputName == "" { if i.InputName == "" {
return nil, errors.Errorf("input name is blank") return nil, errors.Errorf("input name is blank")
} }
@ -187,8 +200,7 @@ func (i *Image) getLocalImage() (*storage.Image, error) {
if err == nil { if err == nil {
return repoImage, nil return repoImage, nil
} }
return nil, errors.Wrapf(err, imageError)
return nil, errors.Errorf("%s", imageError)
} }
// hasRegistry returns a bool/err response if the image has a registry in its // hasRegistry returns a bool/err response if the image has a registry in its
@ -307,7 +319,11 @@ func (ir *Runtime) GetImages() ([]*Image, error) {
return nil, err return nil, err
} }
for _, i := range images { for _, i := range images {
newImages = append(newImages, ir.newFromStorage(&i)) // iterating over these, be careful to not iterate on the literal
// pointer.
image := i
img := ir.newFromStorage(&image)
newImages = append(newImages, img)
} }
return newImages, nil return newImages, nil
} }
@ -338,10 +354,24 @@ func (i *Image) TagImage(tag string) error {
return i.imageruntime.store.SetNames(i.ID(), tags) return i.imageruntime.store.SetNames(i.ID(), tags)
} }
// UntagImage removes a tag from the given image
func (i *Image) UntagImage(tag string) error {
var newTags []string
tags := i.Names()
if !util.StringInSlice(tag, tags) {
return nil
}
for _, t := range tags {
if tag != t {
newTags = append(newTags, t)
}
}
i.reloadImage()
return i.imageruntime.store.SetNames(i.ID(), newTags)
}
// PushImage pushes the given image to a location described by the given path // PushImage pushes the given image to a location described by the given path
func (i *Image) PushImage(destination, manifestMIMEType, authFile, signaturePolicyPath string, writer io.Writer, forceCompress bool, signingOptions SigningOptions, dockerRegistryOptions *DockerRegistryOptions) error { func (i *Image) PushImage(destination, manifestMIMEType, authFile, signaturePolicyPath string, writer io.Writer, forceCompress bool, signingOptions SigningOptions, dockerRegistryOptions *DockerRegistryOptions) error {
// PushImage pushes the src image to the destination
//func PushImage(source, destination string, options CopyOptions) error {
if destination == "" { if destination == "" {
return errors.Wrapf(syscall.EINVAL, "destination image name must be specified") return errors.Wrapf(syscall.EINVAL, "destination image name must be specified")
} }
@ -395,6 +425,12 @@ func (i *Image) toStorageReference() (types.ImageReference, error) {
return is.Transport.ParseStoreReference(i.imageruntime.store, i.ID()) return is.Transport.ParseStoreReference(i.imageruntime.store, i.ID())
} }
// ToImageRef returns an image reference type from an image
// TODO: Hopefully we can remove this exported function for mheon
func (i *Image) ToImageRef() (types.Image, error) {
return i.toImageRef()
}
// toImageRef returns an Image Reference type from an image // toImageRef returns an Image Reference type from an image
func (i *Image) toImageRef() (types.Image, error) { func (i *Image) toImageRef() (types.Image, error) {
ref, err := is.Transport.ParseStoreReference(i.imageruntime.store, "@"+i.ID()) ref, err := is.Transport.ParseStoreReference(i.imageruntime.store, "@"+i.ID())
@ -431,5 +467,77 @@ func (i *Image) Size() (*uint64, error) {
} }
} }
return nil, errors.Errorf("unable to determine size") return nil, errors.Errorf("unable to determine size")
}
// DriverData gets the driver data from the store on a layer
func (i *Image) DriverData() (*inspect.Data, error) {
topLayer, err := i.Layer()
if err != nil {
return nil, err
}
return driver.GetDriverData(i.imageruntime.store, topLayer.ID)
}
// Layer returns the image's top layer
func (i *Image) Layer() (*storage.Layer, error) {
return i.imageruntime.store.Layer(i.image.TopLayer)
}
// History gets the history of an image and information about its layers
func (i *Image) History() ([]ociv1.History, []types.BlobInfo, error) {
img, err := i.toImageRef()
if err != nil {
return nil, nil, err
}
oci, err := img.OCIConfig()
if err != nil {
return nil, nil, err
}
return oci.History, img.LayerInfos(), nil
}
// Import imports and image into the store and returns an image
func Import(path, reference string, writer io.Writer, signingOptions SigningOptions, imageConfig ociv1.Image, runtime *Runtime) (*Image, error) {
file := TarballTransport + ":" + path
src, err := alltransports.ParseImageName(file)
if err != nil {
return nil, errors.Wrapf(err, "error parsing image name %q", path)
}
updater, ok := src.(tarball.ConfigUpdater)
if !ok {
return nil, errors.Wrapf(err, "unexpected type, a tarball reference should implement tarball.ConfigUpdater")
}
annotations := make(map[string]string)
// config imgspecv1.Image
err = updater.ConfigUpdate(imageConfig, annotations)
if err != nil {
return nil, errors.Wrapf(err, "error updating image config")
}
sc := common.GetSystemContext("", "", false)
// if reference not given, get the image digest
if reference == "" {
reference, err = getImageDigest(src, sc)
if err != nil {
return nil, err
}
}
policyContext, err := getPolicyContext(sc)
if err != nil {
return nil, err
}
defer policyContext.Destroy()
copyOptions := getCopyOptions(writer, "", nil, nil, signingOptions, "", "", false)
dest, err := is.Transport.ParseStoreReference(runtime.store, reference)
if err != nil {
errors.Wrapf(err, "error getting image reference for %q", reference)
}
if err = cp.Image(policyContext, dest, src, copyOptions); err != nil {
return nil, err
}
return runtime.NewFromLocal(reference)
} }

View File

@ -79,7 +79,7 @@ func TestImage_NewFromLocal(t *testing.T) {
writer = os.Stdout writer = os.Stdout
// Need images to be present for this test // Need images to be present for this test
ir, err := NewImageRuntime(so) ir, err := NewImageRuntimeFromOptions(so)
assert.NoError(t, err) assert.NoError(t, err)
bb, err := ir.New("docker.io/library/busybox:latest", "", "", writer, nil, SigningOptions{}) bb, err := ir.New("docker.io/library/busybox:latest", "", "", writer, nil, SigningOptions{})
assert.NoError(t, err) assert.NoError(t, err)
@ -115,7 +115,7 @@ func TestImage_New(t *testing.T) {
RunRoot: workdir, RunRoot: workdir,
GraphRoot: workdir, GraphRoot: workdir,
} }
ir, err := NewImageRuntime(so) ir, err := NewImageRuntimeFromOptions(so)
assert.NoError(t, err) assert.NoError(t, err)
// Build the list of pull names // Build the list of pull names
names = append(names, bbNames...) names = append(names, bbNames...)

View File

@ -177,8 +177,8 @@ func (i *Image) pullImage(writer io.Writer, authfile, signaturePolicyPath string
copyOptions := getCopyOptions(writer, signaturePolicyPath, dockerOptions, nil, signingOptions, authfile, "", false) copyOptions := getCopyOptions(writer, signaturePolicyPath, dockerOptions, nil, signingOptions, authfile, "", false)
for _, imageInfo := range pullStructs { for _, imageInfo := range pullStructs {
// Print the following statement only when pulling from a docker or atomic registry // Print the following statement only when pulling from a docker or atomic registry
if writer != nil && (imageInfo.srcRef.Transport().Name() == DockerTransport || imageInfo.srcRef.Transport().Name() == AtomicTransport) { if writer != nil && (strings.HasPrefix(DockerTransport, imageInfo.srcRef.Transport().Name()) || imageInfo.srcRef.Transport().Name() == AtomicTransport) {
io.WriteString(writer, fmt.Sprintf("Trying to pull %s...\n", imageInfo.image)) io.WriteString(writer, fmt.Sprintf("Trying to pull %s...", imageInfo.image))
} }
if err = cp.Image(policyContext, imageInfo.dstRef, imageInfo.srcRef, copyOptions); err != nil { if err = cp.Image(policyContext, imageInfo.dstRef, imageInfo.srcRef, copyOptions); err != nil {
if writer != nil { if writer != nil {

View File

@ -2,15 +2,14 @@ package image
import ( import (
"io" "io"
"strings"
cp "github.com/containers/image/copy" cp "github.com/containers/image/copy"
"github.com/containers/image/docker/reference" "github.com/containers/image/docker/reference"
"github.com/containers/storage"
"github.com/pkg/errors"
"github.com/containers/image/signature" "github.com/containers/image/signature"
"github.com/containers/image/types" "github.com/containers/image/types"
"strings" "github.com/containers/storage"
"github.com/pkg/errors"
) )
func getTags(nameInput string) (reference.NamedTagged, bool, error) { func getTags(nameInput string) (reference.NamedTagged, bool, error) {
@ -36,14 +35,19 @@ func findImageInRepotags(search imageParts, images []*Image) (*storage.Image, er
} }
if d.name == search.name && d.tag == search.tag { if d.name == search.name && d.tag == search.tag {
results = append(results, image.image) results = append(results, image.image)
break continue
}
// account for registry:/somedir/image
if strings.HasSuffix(d.name, search.name) && d.tag == search.tag {
results = append(results, image.image)
continue
} }
} }
} }
if len(results) == 0 { if len(results) == 0 {
return &storage.Image{}, errors.Errorf("unable to find a name and tag match for %s in repotags", search) return &storage.Image{}, errors.Errorf("unable to find a name and tag match for %s in repotags", search.name)
} else if len(results) > 1 { } else if len(results) > 1 {
return &storage.Image{}, errors.Errorf("found multiple name and tag matches for %s in repotags", search) return &storage.Image{}, errors.Errorf("found multiple name and tag matches for %s in repotags", search.name)
} }
return results[0], nil return results[0], nil
} }

View File

@ -4,18 +4,22 @@ import (
"encoding/json" "encoding/json"
"strings" "strings"
"github.com/containers/image/types"
"github.com/containers/storage"
digest "github.com/opencontainers/go-digest" digest "github.com/opencontainers/go-digest"
ociv1 "github.com/opencontainers/image-spec/specs-go/v1" ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/projectatomic/libpod/libpod/image"
"github.com/projectatomic/libpod/pkg/inspect" "github.com/projectatomic/libpod/pkg/inspect"
) )
func getImageData(img storage.Image, imgRef types.Image, size int64, driver *inspect.Data) (*inspect.ImageData, error) { // GetImageData returns an image's inspect data
imgSize, err := imgRef.Size() func GetImageData(img *image.Image) (*inspect.ImageData, error) {
imgRef, err := img.ToImageRef()
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "error reading size of image %q", img.ID) return nil, err
}
size, err := imgRef.Size()
if err != nil {
return nil, err
} }
manifest, manifestType, err := imgRef.Manifest() manifest, manifestType, err := imgRef.Manifest()
if err != nil { if err != nil {
@ -37,13 +41,17 @@ func getImageData(img storage.Image, imgRef types.Image, size int64, driver *ins
} }
var repoDigests []string var repoDigests []string
for _, name := range img.Names { for _, name := range img.Names() {
repoDigests = append(repoDigests, strings.SplitN(name, ":", 2)[0]+"@"+imgDigest.String()) repoDigests = append(repoDigests, strings.SplitN(name, ":", 2)[0]+"@"+imgDigest.String())
} }
driver, err := img.DriverData()
if err != nil {
return nil, err
}
data := &inspect.ImageData{ data := &inspect.ImageData{
ID: img.ID, ID: img.ID(),
RepoTags: img.Names, RepoTags: img.Names(),
RepoDigests: repoDigests, RepoDigests: repoDigests,
Comment: ociv1Img.History[0].Comment, Comment: ociv1Img.History[0].Comment,
Created: ociv1Img.Created, Created: ociv1Img.Created,
@ -53,7 +61,7 @@ func getImageData(img storage.Image, imgRef types.Image, size int64, driver *ins
ContainerConfig: &ociv1Img.Config, ContainerConfig: &ociv1Img.Config,
Version: info.DockerVersion, Version: info.DockerVersion,
Size: size, Size: size,
VirtualSize: size + imgSize, VirtualSize: size,
Annotations: annotations, Annotations: annotations,
Digest: imgDigest, Digest: imgDigest,
Labels: info.Labels, Labels: info.Labels,

View File

@ -13,6 +13,7 @@ import (
"github.com/containers/storage" "github.com/containers/storage"
"github.com/cri-o/ocicni/pkg/ocicni" "github.com/cri-o/ocicni/pkg/ocicni"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/projectatomic/libpod/libpod/image"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/ulule/deepcopier" "github.com/ulule/deepcopier"
) )
@ -69,6 +70,7 @@ type Runtime struct {
conmonPath string conmonPath string
valid bool valid bool
lock sync.RWMutex lock sync.RWMutex
imageRuntime *image.Runtime
} }
// RuntimeConfig contains configuration options used to set up the runtime // RuntimeConfig contains configuration options used to set up the runtime
@ -194,11 +196,9 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
return nil, errors.Wrapf(err, "error configuring runtime") return nil, errors.Wrapf(err, "error configuring runtime")
} }
} }
if err := makeRuntime(runtime); err != nil { if err := makeRuntime(runtime); err != nil {
return nil, err return nil, err
} }
return runtime, nil return runtime, nil
} }
@ -293,8 +293,20 @@ func makeRuntime(runtime *Runtime) error {
if err != nil { if err != nil {
return err return err
} }
runtime.store = store runtime.store = store
is.Transport.SetStore(store) is.Transport.SetStore(store)
// Set up image runtime and store in runtime
ir := image.NewImageRuntimeFromStore(runtime.store)
if err != nil {
return err
}
runtime.imageRuntime = ir
// Setting signaturepolicypath
ir.SignaturePolicyPath = runtime.config.SignaturePolicyPath
defer func() { defer func() {
if err != nil { if err != nil {
// Don't forcibly shut down // Don't forcibly shut down
@ -576,3 +588,8 @@ func SaveDefaultConfig(path string) error {
return ioutil.WriteFile(path, w.Bytes(), 0644) return ioutil.WriteFile(path, w.Bytes(), 0644)
} }
// ImageRuntime returns the imageruntime for image resolution
func (r *Runtime) ImageRuntime() *image.Runtime {
return r.imageRuntime
}

View File

@ -27,7 +27,7 @@ import (
ociv1 "github.com/opencontainers/image-spec/specs-go/v1" ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/projectatomic/libpod/libpod/common" "github.com/projectatomic/libpod/libpod/common"
"github.com/projectatomic/libpod/libpod/driver" "github.com/projectatomic/libpod/libpod/image"
"github.com/projectatomic/libpod/pkg/inspect" "github.com/projectatomic/libpod/pkg/inspect"
"github.com/projectatomic/libpod/pkg/util" "github.com/projectatomic/libpod/pkg/util"
) )
@ -152,7 +152,7 @@ func (r *Runtime) IsImageID(input string) (bool, error) {
return false, errors.Wrapf(err, "unable to get images") return false, errors.Wrapf(err, "unable to get images")
} }
for _, image := range images { for _, image := range images {
if strings.HasPrefix(image.ID, input) { if strings.HasPrefix(image.ID(), input) {
return true, nil return true, nil
} }
} }
@ -167,8 +167,8 @@ func (k *Image) GetNameByID() (string, error) {
return "", errors.Wrapf(err, "unable to get images") return "", errors.Wrapf(err, "unable to get images")
} }
for _, image := range images { for _, image := range images {
if strings.HasPrefix(image.ID, k.Name) { if strings.HasPrefix(image.ID(), k.Name) {
return image.Names[0], nil return image.Names()[0], nil
} }
} }
return "", errors.Errorf("unable to determine image for %s", k.Name) return "", errors.Errorf("unable to determine image for %s", k.Name)
@ -196,13 +196,13 @@ func (k *Image) GetImageID() (string, error) {
} }
for _, image := range images { for _, image := range images {
// Check if we have an ID match // Check if we have an ID match
if strings.HasPrefix(image.ID, k.Name) { if strings.HasPrefix(image.ID(), k.Name) {
return image.ID, nil return image.ID(), nil
} }
// Check if we have a name match, perhaps a tagged name // Check if we have a name match, perhaps a tagged name
for _, name := range image.Names { for _, name := range image.Names() {
if k.Name == name { if k.Name == name {
return image.ID, nil return image.ID(), nil
} }
} }
} }
@ -364,7 +364,7 @@ func (k *Image) GetLocalImageName() (string, string, error) {
return "", "", err return "", "", err
} }
for _, image := range localImages { for _, image := range localImages {
for _, name := range image.Names { for _, name := range image.Names() {
imgRef, err := reference.Parse(name) imgRef, err := reference.Parse(name)
if err != nil { if err != nil {
continue continue
@ -383,13 +383,13 @@ func (k *Image) GetLocalImageName() (string, string, error) {
if imageName == k.Name { if imageName == k.Name {
k.LocalName = name k.LocalName = name
return name, image.ID, nil return name, image.ID(), nil
} }
imageSplit := strings.Split(imageName, "/") imageSplit := strings.Split(imageName, "/")
baseName := imageSplit[len(imageSplit)-1] baseName := imageSplit[len(imageSplit)-1]
if baseName == k.Name { if baseName == k.Name {
k.LocalName = name k.LocalName = name
return name, image.ID, nil return name, image.ID(), nil
} }
} }
} }
@ -431,26 +431,6 @@ func (k *Image) Pull(writer io.Writer) error {
return nil return nil
} }
// Remove calls into container storage and deletes the image
func (k *Image) Remove(force bool) (string, error) {
if k.LocalName == "" {
// This populates the images local name
_, _, err := k.GetLocalImageName()
if err != nil {
return "", errors.Wrapf(err, "unable to find %s locally", k.Name)
}
}
iid, err := k.GetImageID()
if err != nil {
return "", errors.Wrapf(err, "unable to get image id")
}
image, err := k.runtime.GetImage(iid)
if err != nil {
return "", errors.Wrapf(err, "unable to remove %s", iid)
}
return k.runtime.RemoveImage(image, force)
}
// GetRegistries gets the searchable registries from the global registration file. // GetRegistries gets the searchable registries from the global registration file.
func GetRegistries() ([]string, error) { func GetRegistries() ([]string, error) {
registryConfigPath := "" registryConfigPath := ""
@ -497,7 +477,7 @@ func getRegistries() ([]string, error) {
// ImageFilter is a function to determine whether an image is included in // ImageFilter is a function to determine whether an image is included in
// command output. Images to be outputted are tested using the function. A true // command output. Images to be outputted are tested using the function. A true
// return will include the image, a false return will exclude it. // return will include the image, a false return will exclude it.
type ImageFilter func(*storage.Image, *inspect.ImageData) bool type ImageFilter func(*image.Image, *inspect.ImageData) bool
func (ips imageDecomposeStruct) returnFQName() string { func (ips imageDecomposeStruct) returnFQName() string {
return fmt.Sprintf("%s%s/%s:%s", ips.transport, ips.registry, ips.imageName, ips.tag) return fmt.Sprintf("%s%s/%s:%s", ips.transport, ips.registry, ips.imageName, ips.tag)
@ -854,50 +834,52 @@ func (r *Runtime) UntagImage(image *storage.Image, tag string) (string, error) {
// RemoveImage deletes an image from local storage // RemoveImage deletes an image from local storage
// Images being used by running containers can only be removed if force=true // Images being used by running containers can only be removed if force=true
func (r *Runtime) RemoveImage(image *storage.Image, force bool) (string, error) { func (r *Runtime) RemoveImage(image *image.Image, force bool) error {
r.lock.Lock() r.lock.Lock()
defer r.lock.Unlock() defer r.lock.Unlock()
if !r.valid { if !r.valid {
return "", ErrRuntimeStopped return ErrRuntimeStopped
} }
// Get all containers, filter to only those using the image, and remove those containers // Get all containers, filter to only those using the image, and remove those containers
ctrs, err := r.state.AllContainers() ctrs, err := r.state.AllContainers()
if err != nil { if err != nil {
return "", err return err
} }
imageCtrs := []*Container{} imageCtrs := []*Container{}
for _, ctr := range ctrs { for _, ctr := range ctrs {
if ctr.config.RootfsImageID == image.ID { if ctr.config.RootfsImageID == image.ID() {
imageCtrs = append(imageCtrs, ctr) imageCtrs = append(imageCtrs, ctr)
} }
} }
if len(imageCtrs) > 0 && len(image.Names) <= 1 { if len(imageCtrs) > 0 && len(image.Names()) <= 1 {
if force { if force {
for _, ctr := range imageCtrs { for _, ctr := range imageCtrs {
if err := r.removeContainer(ctr, true); err != nil { if err := r.removeContainer(ctr, true); err != nil {
return "", errors.Wrapf(err, "error removing image %s: container %s using image could not be removed", image.ID, ctr.ID()) return errors.Wrapf(err, "error removing image %s: container %s using image could not be removed", image.ID, ctr.ID())
} }
} }
} else { } else {
return "", fmt.Errorf("could not remove image %s as it is being used by %d containers", image.ID, len(imageCtrs)) return fmt.Errorf("could not remove image %s as it is being used by %d containers", image.ID, len(imageCtrs))
} }
} }
if len(image.Names) > 1 && !force { if len(image.Names()) > 1 && !force {
return "", fmt.Errorf("unable to delete %s (must force) - image is referred to in multiple tags", image.ID) return fmt.Errorf("unable to delete %s (must force) - image is referred to in multiple tags", image.ID)
} }
// If it is forced, we have to untag the image so that it can be deleted if len(image.Names()) > 1 && force {
if err = r.store.SetNames(image.ID, image.Names[:0]); err != nil { // If it is forced, we have to untag the image so that it can be deleted
return "", err if err = r.store.SetNames(image.ID(), image.Names()[:0]); err != nil {
return err
}
} }
_, err = r.store.DeleteImage(image.ID, true)
if err != nil { if err = image.Remove(force); err != nil {
return "", err return err
} }
return image.ID, nil return nil
} }
// GetImage retrieves an image matching the given name or hash from system // GetImage retrieves an image matching the given name or hash from system
@ -964,7 +946,7 @@ func (r *Runtime) getImageRef(image string) (types.Image, error) {
// Filters can be provided which will determine which images are included in the // Filters can be provided which will determine which images are included in the
// output. Multiple filters are handled by ANDing their output, so only images // output. Multiple filters are handled by ANDing their output, so only images
// matching all filters are included // matching all filters are included
func (r *Runtime) GetImages(params *ImageFilterParams, filters ...ImageFilter) ([]*storage.Image, error) { func (r *Runtime) GetImages(params *ImageFilterParams, filters ...ImageFilter) ([]*image.Image, error) {
r.lock.RLock() r.lock.RLock()
defer r.lock.RUnlock() defer r.lock.RUnlock()
@ -972,21 +954,21 @@ func (r *Runtime) GetImages(params *ImageFilterParams, filters ...ImageFilter) (
return nil, ErrRuntimeStopped return nil, ErrRuntimeStopped
} }
images, err := r.store.Images() images, err := r.imageRuntime.GetImages()
if err != nil { if err != nil {
return nil, err return nil, err
} }
var imagesFiltered []*image.Image
var imagesFiltered []*storage.Image
for _, img := range images { for _, img := range images {
info, err := r.getImageInspectInfo(img) info, err := GetImageData(img)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var names []string var names []string
if len(img.Names) > 0 { if len(img.Names()) > 0 {
names = img.Names names = img.Names()
} else { } else {
names = append(names, "<none>") names = append(names, "<none>")
} }
@ -996,13 +978,14 @@ func (r *Runtime) GetImages(params *ImageFilterParams, filters ...ImageFilter) (
params.ImageName = name params.ImageName = name
} }
for _, filter := range filters { for _, filter := range filters {
include = include && filter(&img, info) include = include && filter(img, info)
} }
if include { if include {
newImage := img newImage := img
newImage.Names = []string{name} // TODO I dont think this is needed. Will verify along the way
imagesFiltered = append(imagesFiltered, &newImage) //newImage.Names = []string{name}
imagesFiltered = append(imagesFiltered, newImage)
} }
} }
} }
@ -1037,92 +1020,9 @@ func (r *Runtime) GetHistory(image string) ([]ociv1.History, []types.BlobInfo, s
return oci.History, src.LayerInfos(), img.ID, nil return oci.History, src.LayerInfos(), img.ID, nil
} }
// ImportImage imports an OCI format image archive into storage as an image //Import imports an oci format image archive into storage as an image
func (r *Runtime) ImportImage(path string, options CopyOptions) (*storage.Image, error) { func (r *Runtime) Import(path, reference string, writer io.Writer, signingOptions image.SigningOptions, imageConfig ociv1.Image) (*image.Image, error) {
r.lock.RLock() return image.Import(path, reference, writer, signingOptions, imageConfig, r.imageRuntime)
defer r.lock.RUnlock()
if !r.valid {
return nil, ErrRuntimeStopped
}
file := TarballTransport + ":" + path
src, err := alltransports.ParseImageName(file)
if err != nil {
return nil, errors.Wrapf(err, "error parsing image name %q", path)
}
updater, ok := src.(tarball.ConfigUpdater)
if !ok {
return nil, errors.Wrapf(err, "unexpected type, a tarball reference should implement tarball.ConfigUpdater")
}
annotations := make(map[string]string)
err = updater.ConfigUpdate(options.ImageConfig, annotations)
if err != nil {
return nil, errors.Wrapf(err, "error updating image config")
}
var reference = options.Reference
sc := common.GetSystemContext("", "", false)
// if reference not given, get the image digest
if reference == "" {
reference, err = getImageDigest(src, sc)
if err != nil {
return nil, err
}
}
policyContext, err := getPolicyContext(sc)
if err != nil {
return nil, err
}
defer policyContext.Destroy()
copyOptions := common.GetCopyOptions(options.Writer, "", nil, nil, common.SigningOptions{}, "", "", false)
dest, err := is.Transport.ParseStoreReference(r.store, reference)
if err != nil {
errors.Wrapf(err, "error getting image reference for %q", options.Reference)
}
if err = cp.Image(policyContext, dest, src, copyOptions); err != nil {
return nil, err
}
// Use no lock version of GetImage
return r.getImage(reference)
}
// GetImageInspectInfo returns the inspect information of an image
func (r *Runtime) GetImageInspectInfo(image storage.Image) (*inspect.ImageData, error) {
r.lock.RLock()
defer r.lock.RUnlock()
if !r.valid {
return nil, ErrRuntimeStopped
}
return r.getImageInspectInfo(image)
}
func (r *Runtime) getImageInspectInfo(image storage.Image) (*inspect.ImageData, error) {
imgRef, err := r.getImageRef("@" + image.ID)
if err != nil {
return nil, errors.Wrapf(err, "error reading image %q", image.ID)
}
layer, err := r.store.Layer(image.TopLayer)
if err != nil {
return nil, errors.Wrapf(err, "error reading information about layer %q", image.TopLayer)
}
size, err := r.store.DiffSize(layer.Parent, layer.ID)
if err != nil {
return nil, errors.Wrapf(err, "error determining size of layer %q", layer.ID)
}
driverData, err := driver.GetDriverData(r.store, layer.ID)
if err != nil {
return nil, errors.Wrapf(err, "error getting graph driver info %q", image.ID)
}
return getImageData(image, imgRef, size, driverData)
} }
// ParseImageFilter takes a set of images and a filter string as input, and returns the libpod.ImageFilterParams struct // ParseImageFilter takes a set of images and a filter string as input, and returns the libpod.ImageFilterParams struct
@ -1145,7 +1045,7 @@ func (r *Runtime) ParseImageFilter(imageInput, filter string) (*ImageFilterParam
return &params, nil return &params, nil
} }
images, err := r.store.Images() images, err := r.imageRuntime.GetImages()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1164,7 +1064,7 @@ func (r *Runtime) ParseImageFilter(imageInput, filter string) (*ImageFilterParam
params.Label = pair[1] params.Label = pair[1]
case "before": case "before":
if img, err := findImageInSlice(images, pair[1]); err == nil { if img, err := findImageInSlice(images, pair[1]); err == nil {
info, err := r.GetImageInspectInfo(img) info, err := GetImageData(img)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1174,7 +1074,7 @@ func (r *Runtime) ParseImageFilter(imageInput, filter string) (*ImageFilterParam
} }
case "since": case "since":
if img, err := findImageInSlice(images, pair[1]); err == nil { if img, err := findImageInSlice(images, pair[1]); err == nil {
info, err := r.GetImageInspectInfo(img) info, err := GetImageData(img)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1240,18 +1140,18 @@ func ParseImageNames(names []string) (tags, digests []string, err error) {
return tags, digests, nil return tags, digests, nil
} }
func findImageInSlice(images []storage.Image, ref string) (storage.Image, error) { func findImageInSlice(images []*image.Image, ref string) (*image.Image, error) {
for _, image := range images { for _, image := range images {
if MatchesID(image.ID, ref) { if MatchesID(image.ID(), ref) {
return image, nil return image, nil
} }
for _, name := range image.Names { for _, name := range image.Names() {
if MatchesReference(name, ref) { if MatchesReference(name, ref) {
return image, nil return image, nil
} }
} }
} }
return storage.Image{}, errors.New("could not find image") return nil, errors.New("could not find image")
} }
// getImageDigest creates an image object and uses the hex value of the digest as the image ID // getImageDigest creates an image object and uses the hex value of the digest as the image ID

View File

@ -140,7 +140,7 @@ var _ = Describe("Podman pull", func() {
clean.WaitWithDefaultTimeout() clean.WaitWithDefaultTimeout()
}) })
It("podman pull from local directory", func() { It("podman pull check quiet", func() {
podmanTest.RestoreArtifact(ALPINE) podmanTest.RestoreArtifact(ALPINE)
setup := podmanTest.Podman([]string{"images", ALPINE, "-q", "--no-trunc"}) setup := podmanTest.Podman([]string{"images", ALPINE, "-q", "--no-trunc"})
setup.WaitWithDefaultTimeout() setup.WaitWithDefaultTimeout()