vendor containers/common@main

The `IgnorePlatform` options has been removed from the
`LookupImageOptions` in libimage to properly support multi-arch images.

Skip one buildah-bud test which requires updated CI images.  This is
currently being done in github.com/containers/podman/pull/10829 but
we need to unblock merging common and buildah into podman.

[NO TESTS NEEDED]

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
Valentin Rothberg
2021-07-02 14:37:30 +02:00
parent f0cd16cb32
commit e1ac0c3033
26 changed files with 303 additions and 146 deletions

View File

@ -63,14 +63,14 @@ func (r *Runtime) compileImageFilters(ctx context.Context, filters []string) ([]
switch key {
case "after", "since":
img, _, err := r.LookupImage(value, &LookupImageOptions{IgnorePlatform: true})
img, _, err := r.LookupImage(value, nil)
if err != nil {
return nil, errors.Wrapf(err, "could not find local image for filter %q", filter)
}
filterFuncs = append(filterFuncs, filterAfter(img.Created()))
case "before":
img, _, err := r.LookupImage(value, &LookupImageOptions{IgnorePlatform: true})
img, _, err := r.LookupImage(value, nil)
if err != nil {
return nil, errors.Wrapf(err, "could not find local image for filter %q", filter)
}

View File

@ -86,16 +86,12 @@ func (r *Runtime) Import(ctx context.Context, path string, options *ImportOption
return "", err
}
name := options.Tag
if name == "" {
name, err = getImageDigest(ctx, srcRef, r.systemContextCopy())
if err != nil {
return "", err
}
name = "sha256:" + name[1:] // strip leading "@"
id, err := getImageDigest(ctx, srcRef, r.systemContextCopy())
if err != nil {
return "", err
}
destRef, err := storageTransport.Transport.ParseStoreReference(r.store, name)
destRef, err := storageTransport.Transport.ParseStoreReference(r.store, id)
if err != nil {
return "", err
}
@ -110,5 +106,19 @@ func (r *Runtime) Import(ctx context.Context, path string, options *ImportOption
return "", err
}
return name, nil
// Strip the leading @ off the id.
name := id[1:]
// If requested, tag the imported image.
if options.Tag != "" {
image, _, err := r.LookupImage(name, nil)
if err != nil {
return "", errors.Wrap(err, "looking up imported image")
}
if err := image.Tag(options.Tag); err != nil {
return "", err
}
}
return "sha256:" + name, nil
}

View File

@ -78,7 +78,6 @@ func (r *Runtime) LookupManifestList(name string) (*ManifestList, error) {
func (r *Runtime) lookupManifestList(name string) (*Image, manifests.List, error) {
lookupOptions := &LookupImageOptions{
IgnorePlatform: true,
lookupManifest: true,
}
image, _, err := r.LookupImage(name, lookupOptions)

View File

@ -61,7 +61,7 @@ func (r *Runtime) Pull(ctx context.Context, name string, pullPolicy config.PullP
if pullPolicy == config.PullPolicyAlways {
return nil, errors.Errorf("pull policy is always but image has been referred to by ID (%s)", name)
}
local, _, err := r.LookupImage(name, &LookupImageOptions{IgnorePlatform: true})
local, _, err := r.LookupImage(name, nil)
if err != nil {
return nil, err
}
@ -146,7 +146,7 @@ func (r *Runtime) Pull(ctx context.Context, name string, pullPolicy config.PullP
localImages := []*Image{}
for _, name := range pulledImages {
local, _, err := r.LookupImage(name, &LookupImageOptions{IgnorePlatform: true})
local, _, err := r.LookupImage(name, nil)
if err != nil {
return nil, errors.Wrapf(err, "error locating pulled image %q name in containers storage", name)
}
@ -362,15 +362,13 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
// resolved name for pulling. Assume we're doing a `pull foo`.
// If there's already a local image "localhost/foo", then we should
// attempt pulling that instead of doing the full short-name dance.
lookupOptions := &LookupImageOptions{
// NOTE: we must ignore the platform of a local image when
// doing lookups. Some images set an incorrect or even invalid
// platform (see containers/podman/issues/10682). Doing the
// lookup while ignoring the platform checks prevents
// redundantly downloading the same image.
IgnorePlatform: true,
}
localImage, resolvedImageName, err = r.LookupImage(imageName, lookupOptions)
//
// NOTE: we must ignore the platform of a local image when doing
// lookups here, even if arch/os/variant is set. Some images set an
// incorrect or even invalid platform (see containers/podman/issues/10682).
// Doing the lookup while ignoring the platform checks prevents
// redundantly downloading the same image.
localImage, resolvedImageName, err = r.LookupImage(imageName, nil)
if err != nil && errors.Cause(err) != storage.ErrImageUnknown {
logrus.Errorf("Looking up %s in local storage: %v", imageName, err)
}

View File

@ -31,8 +31,7 @@ func (r *Runtime) Push(ctx context.Context, source, destination string, options
// Look up the local image. Note that we need to ignore the platform
// and push what the user specified (containers/podman/issues/10344).
lookupOptions := &LookupImageOptions{IgnorePlatform: true}
image, resolvedSource, err := r.LookupImage(source, lookupOptions)
image, resolvedSource, err := r.LookupImage(source, nil)
if err != nil {
return nil, err
}

View File

@ -4,7 +4,6 @@ import (
"context"
"os"
"path/filepath"
"runtime"
"strings"
"github.com/containers/image/v5/docker/reference"
@ -142,7 +141,7 @@ func (r *Runtime) storageToImage(storageImage *storage.Image, ref types.ImageRef
// Exists returns true if the specicifed image exists in the local containers
// storage. Note that it may return false if an image corrupted.
func (r *Runtime) Exists(name string) (bool, error) {
image, _, err := r.LookupImage(name, &LookupImageOptions{IgnorePlatform: true})
image, _, err := r.LookupImage(name, nil)
if err != nil && errors.Cause(err) != storage.ErrImageUnknown {
return false, err
}
@ -158,11 +157,6 @@ func (r *Runtime) Exists(name string) (bool, error) {
// LookupImageOptions allow for customizing local image lookups.
type LookupImageOptions struct {
// If set, the image will be purely looked up by name. No matching to
// the current platform will be performed. This can be helpful when
// the platform does not matter, for instance, for image removal.
IgnorePlatform bool
// Lookup an image matching the specified architecture.
Architecture string
// Lookup an image matching the specified OS.
@ -173,13 +167,23 @@ type LookupImageOptions struct {
// If set, do not look for items/instances in the manifest list that
// match the current platform but return the manifest list as is.
lookupManifest bool
// If the image resolves to a manifest list, we usually lookup a
// matching instance and error if none could be found. In this case,
// just return the manifest list. Required for image removal.
returnManifestIfNoInstance bool
}
// Lookup Image looks up `name` in the local container storage matching the
// specified SystemContext. Returns the image and the name it has been found
// with. Note that name may also use the `containers-storage:` prefix used to
// refer to the containers-storage transport. Returns storage.ErrImageUnknown
// if the image could not be found.
// Lookup Image looks up `name` in the local container storage. Returns the
// image and the name it has been found with. Note that name may also use the
// `containers-storage:` prefix used to refer to the containers-storage
// transport. Returns storage.ErrImageUnknown if the image could not be found.
//
// Unless specified via the options, the image will be looked up by name only
// without matching the architecture, os or variant. An exception is if the
// image resolves to a manifest list, where an instance of the manifest list
// matching the local or specified platform (via options.{Architecture,OS,Variant})
// is returned.
//
// If the specified name uses the `containers-storage` transport, the resolved
// name is empty.
@ -221,23 +225,17 @@ func (r *Runtime) LookupImage(name string, options *LookupImageOptions) (*Image,
name = strings.TrimPrefix(name, "sha256:")
}
// Set the platform for matching local images.
if !options.IgnorePlatform {
if options.Architecture == "" {
options.Architecture = r.systemContext.ArchitectureChoice
}
if options.Architecture == "" {
options.Architecture = runtime.GOARCH
}
if options.OS == "" {
options.OS = r.systemContext.OSChoice
}
if options.OS == "" {
options.OS = runtime.GOOS
}
if options.Variant == "" {
options.Variant = r.systemContext.VariantChoice
}
// Unless specified, set the platform specified in the system context
// for later platform matching. Builder likes to set these things via
// the system context at runtime creation.
if options.Architecture == "" {
options.Architecture = r.systemContext.ArchitectureChoice
}
if options.OS == "" {
options.OS = r.systemContext.OSChoice
}
if options.Variant == "" {
options.Variant = r.systemContext.VariantChoice
}
// First, check if we have an exact match in the storage. Maybe an ID
@ -327,10 +325,8 @@ func (r *Runtime) lookupImageInLocalStorage(name, candidate string, options *Loo
}
instance, err := manifestList.LookupInstance(context.Background(), options.Architecture, options.OS, options.Variant)
if err != nil {
// NOTE: If we are not looking for a specific platform
// and already found the manifest list, then return it
// instead of the error.
if options.IgnorePlatform {
if options.returnManifestIfNoInstance {
logrus.Debug("No matching instance was found: returning manifest list instead")
return image, nil
}
return nil, errors.Wrap(storage.ErrImageUnknown, err.Error())
@ -342,10 +338,6 @@ func (r *Runtime) lookupImageInLocalStorage(name, candidate string, options *Loo
image = instance
}
if options.IgnorePlatform {
return image, nil
}
matches, err := r.imageReferenceMatchesContext(ref, options)
if err != nil {
return nil, err
@ -440,7 +432,7 @@ func (r *Runtime) ResolveName(name string) (string, error) {
if name == "" {
return "", nil
}
image, resolvedName, err := r.LookupImage(name, &LookupImageOptions{IgnorePlatform: true})
image, resolvedName, err := r.LookupImage(name, nil)
if err != nil && errors.Cause(err) != storage.ErrImageUnknown {
return "", err
}
@ -460,9 +452,10 @@ func (r *Runtime) ResolveName(name string) (string, error) {
// imageReferenceMatchesContext return true if the specified reference matches
// the platform (os, arch, variant) as specified by the lookup options.
func (r *Runtime) imageReferenceMatchesContext(ref types.ImageReference, options *LookupImageOptions) (bool, error) {
if options.IgnorePlatform {
if options.Architecture+options.OS+options.Variant == "" {
return true, nil
}
ctx := context.Background()
img, err := ref.NewImage(ctx, &r.systemContext)
if err != nil {
@ -473,12 +466,18 @@ func (r *Runtime) imageReferenceMatchesContext(ref types.ImageReference, options
if err != nil {
return false, err
}
if options.OS == data.Os && options.Architecture == data.Architecture {
if options.Variant == "" || options.Variant == data.Variant {
return true, nil
}
if options.Architecture != "" && options.Architecture != data.Architecture {
return false, err
}
return false, nil
if options.OS != "" && options.OS != data.Os {
return false, err
}
if options.Variant != "" && options.Variant != data.Variant {
return false, err
}
return true, nil
}
// ListImagesOptions allow for customizing listing images.
@ -503,9 +502,8 @@ func (r *Runtime) ListImages(ctx context.Context, names []string, options *ListI
var images []*Image
if len(names) > 0 {
lookupOpts := LookupImageOptions{IgnorePlatform: true}
for _, name := range names {
image, _, err := r.LookupImage(name, &lookupOpts)
image, _, err := r.LookupImage(name, nil)
if err != nil {
return nil, err
}
@ -604,9 +602,8 @@ func (r *Runtime) RemoveImages(ctx context.Context, names []string, options *Rem
// Look up the images one-by-one. That allows for removing
// images that have been looked up successfully while reporting
// lookup errors at the end.
lookupOptions := LookupImageOptions{IgnorePlatform: true}
for _, name := range names {
img, resolvedName, err := r.LookupImage(name, &lookupOptions)
img, resolvedName, err := r.LookupImage(name, &LookupImageOptions{returnManifestIfNoInstance: true})
if err != nil {
appendError(err)
continue

View File

@ -74,7 +74,7 @@ func (r *Runtime) Save(ctx context.Context, names []string, format, path string,
// saveSingleImage saves the specified image name to the specified path.
// Supported formats are "oci-archive", "oci-dir" and "docker-dir".
func (r *Runtime) saveSingleImage(ctx context.Context, name, format, path string, options *SaveOptions) error {
image, imageName, err := r.LookupImage(name, &LookupImageOptions{IgnorePlatform: true})
image, imageName, err := r.LookupImage(name, nil)
if err != nil {
return err
}
@ -155,7 +155,7 @@ func (r *Runtime) saveDockerArchive(ctx context.Context, names []string, path st
visitedNames := make(map[string]bool) // filters duplicate names
for _, name := range names {
// Look up local images.
image, imageName, err := r.LookupImage(name, &LookupImageOptions{IgnorePlatform: true})
image, imageName, err := r.LookupImage(name, nil)
if err != nil {
return err
}

View File

@ -243,6 +243,12 @@ default_sysctls = [
# The network table contains settings pertaining to the management of
# CNI plugins.
[secrets]
# driver = "file"
[secrets.opts]
# root = "/example/directory"
[network]
# Path to directory where CNI plugin binaries are located.
@ -503,9 +509,3 @@ default_sysctls = [
# TOML does not provide a way to end a table other than a further table being
# defined, so every key hereafter will be part of [volume_plugins] and not the
# main config.
[secret]
# driver = "file"
[secret.opts]
# root = "/example/directory"