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

@ -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