Stage 4 Image cleanup

Cull funcs from runtime_img.go which are no longer needed.  Also, fix any remaining
spots that use the old image technique.

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

Closes: #532
Approved by: mheon
This commit is contained in:
baude
2018-03-22 10:17:50 -05:00
committed by Atomic Bot
parent 8ca3bcc85d
commit f7c8dd5836
13 changed files with 155 additions and 1201 deletions

View File

@ -82,7 +82,7 @@ var (
func imagesCmd(c *cli.Context) error {
var (
filterFuncs []libpod.ImageResultFilter
filterFuncs []image.ResultFilter
newImage *image.Image
)
if err := validateFlags(c, imagesFlags); err != nil {
@ -136,7 +136,7 @@ func imagesCmd(c *cli.Context) error {
var filteredImages []*image.Image
// filter the images
if len(c.StringSlice("filter")) > 0 || newImage != nil {
filteredImages = libpod.FilterImages(images, filterFuncs)
filteredImages = image.FilterImages(images, filterFuncs)
} else {
filteredImages = images
}
@ -266,8 +266,8 @@ func (i *imagesTemplateParams) HeaderMap() map[string]string {
// CreateFilterFuncs returns an array of filter functions based on the user inputs
// and is later used to filter images for output
func CreateFilterFuncs(r *libpod.Runtime, c *cli.Context, image *image.Image) ([]libpod.ImageResultFilter, error) {
var filterFuncs []libpod.ImageResultFilter
func CreateFilterFuncs(r *libpod.Runtime, c *cli.Context, img *image.Image) ([]image.ResultFilter, error) {
var filterFuncs []image.ResultFilter
for _, filter := range c.StringSlice("filter") {
splitFilter := strings.Split(filter, "=")
switch splitFilter[0] {
@ -276,24 +276,24 @@ func CreateFilterFuncs(r *libpod.Runtime, c *cli.Context, image *image.Image) ([
if err != nil {
return nil, errors.Wrapf(err, "unable to find image % in local stores", splitFilter[1])
}
filterFuncs = append(filterFuncs, libpod.ImageCreatedBefore(before.Created()))
filterFuncs = append(filterFuncs, image.CreatedBeforeFilter(before.Created()))
case "after":
after, err := r.ImageRuntime().NewFromLocal(splitFilter[1])
if err != nil {
return nil, errors.Wrapf(err, "unable to find image % in local stores", splitFilter[1])
}
filterFuncs = append(filterFuncs, libpod.ImageCreatedAfter(after.Created()))
filterFuncs = append(filterFuncs, image.CreatedAfterFilter(after.Created()))
case "dangling":
filterFuncs = append(filterFuncs, libpod.ImageDangling())
filterFuncs = append(filterFuncs, image.DanglingFilter())
case "label":
labelFilter := strings.Join(splitFilter[1:], "=")
filterFuncs = append(filterFuncs, libpod.ImageLabel(labelFilter))
filterFuncs = append(filterFuncs, image.LabelFilter(labelFilter))
default:
return nil, errors.Errorf("invalid filter %s ", splitFilter[0])
}
}
if image != nil {
filterFuncs = append(filterFuncs, libpod.OutputImageFilter(image))
if img != nil {
filterFuncs = append(filterFuncs, image.OutputImageFilter(img))
}
return filterFuncs, nil
}

View File

@ -107,7 +107,7 @@ func importCmd(c *cli.Context) error {
source = file
}
newImage, err := runtime.Import(source, reference, writer, image.SigningOptions{}, config)
newImage, err := runtime.ImageRuntime().Import(source, reference, writer, image.SigningOptions{}, config)
if err == nil {
fmt.Println(newImage.ID())
}

View File

@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
"github.com/projectatomic/libpod/libpod"
libpodImage "github.com/projectatomic/libpod/libpod/image"
"github.com/urfave/cli"
)
@ -44,6 +45,7 @@ func loadCmd(c *cli.Context) error {
args := c.Args()
var image string
if len(args) == 1 {
image = args[0]
}
@ -96,28 +98,23 @@ func loadCmd(c *cli.Context) error {
writer = os.Stderr
}
options := libpod.CopyOptions{
SignaturePolicyPath: c.String("signature-policy"),
Writer: writer,
}
src := libpod.DockerArchive + ":" + input
imgName, err := runtime.PullImage(src, options)
newImage, err := runtime.ImageRuntime().New(src, c.String("signature-policy"), "", writer, &libpodImage.DockerRegistryOptions{}, libpodImage.SigningOptions{})
if err != nil {
// generate full src name with specified image:tag
fullSrc := libpod.OCIArchive + ":" + input
if image != "" {
fullSrc = fullSrc + ":" + image
}
imgName, err = runtime.PullImage(fullSrc, options)
newImage, err = runtime.ImageRuntime().New(fullSrc, c.String("signature-policy"), "", writer, &libpodImage.DockerRegistryOptions{}, libpodImage.SigningOptions{})
if err != nil {
src = libpod.DirTransport + ":" + input
imgName, err = runtime.PullImage(src, options)
newImage, err = runtime.ImageRuntime().New(src, c.String("signature-policy"), "", writer, &libpodImage.DockerRegistryOptions{}, libpodImage.SigningOptions{})
if err != nil {
return errors.Wrapf(err, "error pulling %q", src)
}
}
}
fmt.Println("Loaded image: ", imgName)
fmt.Println("Loaded image: ", newImage.InputName)
return nil
}

View File

@ -8,8 +8,7 @@ import (
"github.com/containers/image/types"
"github.com/pkg/errors"
"github.com/projectatomic/libpod/libpod"
"github.com/projectatomic/libpod/libpod/common"
image2 "github.com/projectatomic/libpod/libpod/image"
"github.com/projectatomic/libpod/pkg/util"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
@ -94,27 +93,19 @@ func pullCmd(c *cli.Context) error {
writer = os.Stderr
}
options := libpod.CopyOptions{
SignaturePolicyPath: c.String("signature-policy"),
AuthFile: c.String("authfile"),
DockerRegistryOptions: common.DockerRegistryOptions{
DockerRegistryCreds: registryCreds,
DockerCertPath: c.String("cert-dir"),
DockerInsecureSkipTLSVerify: !c.BoolT("tls-verify"),
},
Writer: writer,
dockerRegistryOptions := image2.DockerRegistryOptions{
DockerRegistryCreds: registryCreds,
DockerCertPath: c.String("cert-dir"),
DockerInsecureSkipTLSVerify: !c.BoolT("tls-verify"),
}
if _, err := runtime.PullImage(image, options); err != nil {
newImage, err := runtime.ImageRuntime().New(image, c.String("signature-policy"), c.String("authfile"), writer, &dockerRegistryOptions, image2.SigningOptions{})
if err != nil {
return errors.Wrapf(err, "error pulling image %q", image)
}
newImage := runtime.NewImage(image)
iid, err := newImage.GetImageID()
// Intentially choosing to ignore if there is an error because
// outputting the image ID is a NTH and not integral to the pull
if err == nil {
fmt.Println(iid)
}
fmt.Println(newImage.ID())
return nil
}

View File

@ -8,11 +8,10 @@ import (
"github.com/containers/image/manifest"
"github.com/containers/image/types"
"github.com/containers/storage/pkg/archive"
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/projectatomic/libpod/libpod"
"github.com/projectatomic/libpod/libpod/common"
"github.com/projectatomic/libpod/libpod/image"
"github.com/projectatomic/libpod/pkg/util"
"github.com/urfave/cli"
)
@ -135,23 +134,22 @@ func pushCmd(c *cli.Context) error {
}
}
options := libpod.CopyOptions{
Compression: archive.Uncompressed,
SignaturePolicyPath: c.String("signature-policy"),
DockerRegistryOptions: common.DockerRegistryOptions{
DockerRegistryCreds: registryCreds,
DockerCertPath: certPath,
DockerInsecureSkipTLSVerify: skipVerify,
},
SigningOptions: common.SigningOptions{
RemoveSignatures: removeSignatures,
SignBy: signBy,
},
AuthFile: c.String("authfile"),
Writer: writer,
ManifestMIMEType: manifestType,
ForceCompress: c.Bool("compress"),
dockerRegistryOptions := image.DockerRegistryOptions{
DockerRegistryCreds: registryCreds,
DockerCertPath: certPath,
DockerInsecureSkipTLSVerify: skipVerify,
}
return runtime.PushImage(srcName, destName, options)
so := image.SigningOptions{
RemoveSignatures: removeSignatures,
SignBy: signBy,
}
newImage, err := runtime.ImageRuntime().NewFromLocal(srcName)
if err != nil {
return err
}
//return runtime.PushImage(srcName, destName, options)
return newImage.PushImage(destName, manifestType, c.String("authfile"), c.String("signature-policy"), writer, c.Bool("compress"), so, &dockerRegistryOptions)
}

View File

@ -5,7 +5,6 @@ import (
"os"
"github.com/pkg/errors"
"github.com/projectatomic/libpod/libpod"
"github.com/projectatomic/libpod/libpod/image"
"github.com/urfave/cli"
)
@ -56,7 +55,7 @@ func rmiCmd(c *cli.Context) error {
var lastError error
var imagesToDelete []*image.Image
if removeAll {
imagesToDelete, err = runtime.GetImages(&libpod.ImageFilterParams{})
imagesToDelete, err = runtime.ImageRuntime().GetImages()
if err != nil {
return errors.Wrapf(err, "unable to query local images")
}

View File

@ -9,6 +9,7 @@ import (
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/projectatomic/libpod/libpod"
libpodImage "github.com/projectatomic/libpod/libpod/image"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@ -104,13 +105,6 @@ func saveCmd(c *cli.Context) error {
return errors.Errorf("unknown format option %q", c.String("format"))
}
saveOpts := libpod.CopyOptions{
SignaturePolicyPath: "",
Writer: writer,
ManifestMIMEType: manifestType,
ForceCompress: c.Bool("compress"),
}
// only one image is supported for now
// future pull requests will fix this
for _, image := range args {
@ -119,7 +113,11 @@ func saveCmd(c *cli.Context) error {
if strings.Contains(dst, libpod.OCIArchive) || strings.Contains(dst, libpod.DockerArchive) {
dest = dst + ":" + image
}
if err := runtime.PushImage(image, dest, saveOpts); err != nil {
newImage, err := runtime.ImageRuntime().NewFromLocal(image)
if err != nil {
return err
}
if err := newImage.PushImage(dest, manifestType, "", "", writer, c.Bool("compress"), libpodImage.SigningOptions{}, &libpodImage.DockerRegistryOptions{}); err != nil {
if err2 := os.Remove(output); err2 != nil {
logrus.Errorf("error deleting %q: %v", output, err)
}

View File

@ -565,7 +565,7 @@ func (c *Container) Commit(pause bool, reference string, writer io.Writer, signi
if err := c.export(tempFile.Name()); err != nil {
return nil, err
}
return image.Import(tempFile.Name(), reference, writer, signingOptions, imageConfig, c.runtime.imageRuntime)
return c.runtime.imageRuntime.Import(tempFile.Name(), reference, writer, signingOptions, imageConfig)
}
// Wait blocks on a container to exit and returns its exit code

View File

@ -27,7 +27,7 @@ func (r *Runtime) GetDiff(from, to string) ([]archive.Change, error) {
// If the id matches a layer, the top layer id is returned
func (r *Runtime) getLayerID(id string) (string, error) {
var toLayer string
toImage, err := r.GetImage(id)
toImage, err := r.imageRuntime.NewFromLocal(id)
if err != nil {
toCtr, err := r.store.Container(id)
if err != nil {
@ -39,7 +39,7 @@ func (r *Runtime) getLayerID(id string) (string, error) {
toLayer = toCtr.LayerID
}
} else {
toLayer = toImage.TopLayer
toLayer = toImage.TopLayer()
}
return toLayer, nil
}

82
libpod/image/filters.go Normal file
View File

@ -0,0 +1,82 @@
package image
import (
"strings"
"time"
"github.com/projectatomic/libpod/pkg/inspect"
)
// ResultFilter is a mock function for image filtering
type ResultFilter func(*Image) bool
// Filter is a function to determine whether an image is included in
// command output. Images to be outputted are tested using the function. A true
// return will include the image, a false return will exclude it.
type Filter func(*Image, *inspect.ImageData) bool
// CreatedBeforeFilter allows you to filter on images created before
// the given time.Time
func CreatedBeforeFilter(createTime time.Time) ResultFilter {
return func(i *Image) bool {
return i.Created().Before(createTime)
}
}
// CreatedAfterFilter allows you to filter on images created after
// the given time.Time
func CreatedAfterFilter(createTime time.Time) ResultFilter {
return func(i *Image) bool {
return i.Created().After(createTime)
}
}
// DanglingFilter allows you to filter images for dangling images
func DanglingFilter() ResultFilter {
return func(i *Image) bool {
return i.Dangling()
}
}
// LabelFilter allows you to filter by images labels key and/or value
func LabelFilter(labelfilter string) ResultFilter {
// We need to handle both label=key and label=key=value
return func(i *Image) bool {
var value string
splitFilter := strings.Split(labelfilter, "=")
key := splitFilter[0]
if len(splitFilter) > 1 {
value = splitFilter[1]
}
labels, err := i.Labels()
if err != nil {
return false
}
if len(strings.TrimSpace(labels[key])) > 0 && len(strings.TrimSpace(value)) == 0 {
return true
}
return labels[key] == value
}
}
// OutputImageFilter allows you to filter by an a specific image name
func OutputImageFilter(userImage *Image) ResultFilter {
return func(i *Image) bool {
return userImage.ID() == i.ID()
}
}
// FilterImages filters images using a set of predefined fitler funcs
func FilterImages(images []*Image, filters []ResultFilter) []*Image {
var filteredImages []*Image
for _, image := range images {
include := true
for _, filter := range filters {
include = include && filter(image)
}
if include {
filteredImages = append(filteredImages, image)
}
}
return filteredImages
}

View File

@ -641,7 +641,7 @@ func (i *Image) Inspect() (*inspect.ImageData, error) {
}
// 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) {
func (ir *Runtime) Import(path, reference string, writer io.Writer, signingOptions SigningOptions, imageConfig ociv1.Image) (*Image, error) {
file := TarballTransport + ":" + path
src, err := alltransports.ParseImageName(file)
if err != nil {
@ -676,14 +676,14 @@ func Import(path, reference string, writer io.Writer, signingOptions SigningOpti
}
defer policyContext.Destroy()
copyOptions := getCopyOptions(writer, "", nil, nil, signingOptions, "", "", false)
dest, err := is.Transport.ParseStoreReference(runtime.store, reference)
dest, err := is.Transport.ParseStoreReference(ir.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)
return ir.NewFromLocal(reference)
}
// MatchRepoTag takes a string and tries to match it against an

File diff suppressed because it is too large Load Diff

View File

@ -47,11 +47,6 @@ func FuncTimer(funcName string) {
fmt.Printf("%s executed in %d ms\n", funcName, elapsed)
}
// hasTransport determines if the image string contains '://', returns bool
func hasTransport(image string) bool {
return strings.Contains(image, "://")
}
// CopyStringStringMap deep copies a map[string]string and returns the result
func CopyStringStringMap(m map[string]string) map[string]string {
n := map[string]string{}