mirror of
https://github.com/containers/podman.git
synced 2025-10-20 20:54:45 +08:00
Update vendor of containers/buildah
Changes since 2022-05-31: - add --omit-history option (buildah PR 4028) Signed-off-by: Ed Santiago <santiago@redhat.com> Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
4
vendor/github.com/containers/common/libimage/copier.go
generated
vendored
4
vendor/github.com/containers/common/libimage/copier.go
generated
vendored
@ -139,7 +139,7 @@ type CopyOptions struct {
|
||||
// copier is an internal helper to conveniently copy images.
|
||||
type copier struct {
|
||||
imageCopyOptions copy.Options
|
||||
retryOptions retry.RetryOptions
|
||||
retryOptions retry.Options
|
||||
systemContext *types.SystemContext
|
||||
policyContext *signature.PolicyContext
|
||||
|
||||
@ -370,7 +370,7 @@ func (c *copier) copy(ctx context.Context, source, destination types.ImageRefere
|
||||
}
|
||||
return err
|
||||
}
|
||||
return returnManifest, retry.RetryIfNecessary(ctx, f, &c.retryOptions)
|
||||
return returnManifest, retry.IfNecessary(ctx, f, &c.retryOptions)
|
||||
}
|
||||
|
||||
// checkRegistrySourcesAllows checks the $BUILD_REGISTRY_SOURCES environment
|
||||
|
2
vendor/github.com/containers/common/libimage/inspect.go
generated
vendored
2
vendor/github.com/containers/common/libimage/inspect.go
generated
vendored
@ -216,7 +216,7 @@ func (i *Image) inspectInfo(ctx context.Context) (*types.ImageInspectInfo, error
|
||||
return nil, err
|
||||
}
|
||||
|
||||
img, err := ref.NewImage(ctx, i.runtime.systemContextCopy())
|
||||
img, err := ref.NewImage(ctx, &i.runtime.systemContext)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
63
vendor/github.com/containers/common/libimage/platform.go
generated
vendored
Normal file
63
vendor/github.com/containers/common/libimage/platform.go
generated
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
package libimage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// PlatformPolicy controls the behavior of image-platform matching.
|
||||
type PlatformPolicy int
|
||||
|
||||
const (
|
||||
// Only debug log if an image does not match the expected platform.
|
||||
PlatformPolicyDefault PlatformPolicy = iota
|
||||
// Warn if an image does not match the expected platform.
|
||||
PlatformPolicyWarn
|
||||
)
|
||||
|
||||
func toPlatformString(architecture, os, variant string) string {
|
||||
if variant == "" {
|
||||
return fmt.Sprintf("%s/%s", os, architecture)
|
||||
}
|
||||
return fmt.Sprintf("%s/%s/%s", os, architecture, variant)
|
||||
}
|
||||
|
||||
// Checks whether the image matches the specified platform.
|
||||
// Returns
|
||||
// * 1) a matching error that can be used for logging (or returning) what does not match
|
||||
// * 2) a bool indicating whether architecture, os or variant were set (some callers need that to decide whether they need to throw an error)
|
||||
// * 3) a fatal error that occurred prior to check for matches (e.g., storage errors etc.)
|
||||
func (i *Image) matchesPlatform(ctx context.Context, architecture, os, variant string) (error, bool, error) {
|
||||
customPlatform := len(architecture)+len(os)+len(variant) != 0
|
||||
|
||||
if len(architecture) == 0 {
|
||||
architecture = runtime.GOARCH
|
||||
}
|
||||
if len(os) == 0 {
|
||||
os = runtime.GOOS
|
||||
}
|
||||
|
||||
inspectInfo, err := i.inspectInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, customPlatform, fmt.Errorf("inspecting image: %w", err)
|
||||
}
|
||||
|
||||
matches := true
|
||||
switch {
|
||||
case architecture != inspectInfo.Architecture:
|
||||
matches = false
|
||||
case os != inspectInfo.Os:
|
||||
matches = false
|
||||
case variant != "" && variant != inspectInfo.Variant:
|
||||
matches = false
|
||||
}
|
||||
|
||||
if matches {
|
||||
return nil, customPlatform, nil
|
||||
}
|
||||
|
||||
imagePlatform := toPlatformString(inspectInfo.Architecture, inspectInfo.Os, inspectInfo.Variant)
|
||||
expectedPlatform := toPlatformString(architecture, os, variant)
|
||||
return fmt.Errorf("image platform (%s) does not match the expected platform (%s)", imagePlatform, expectedPlatform), customPlatform, nil
|
||||
}
|
23
vendor/github.com/containers/common/libimage/pull.go
generated
vendored
23
vendor/github.com/containers/common/libimage/pull.go
generated
vendored
@ -161,11 +161,30 @@ func (r *Runtime) Pull(ctx context.Context, name string, pullPolicy config.PullP
|
||||
|
||||
localImages := []*Image{}
|
||||
for _, name := range pulledImages {
|
||||
local, _, err := r.LookupImage(name, nil)
|
||||
image, _, err := r.LookupImage(name, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error locating pulled image %q name in containers storage", name)
|
||||
}
|
||||
localImages = append(localImages, local)
|
||||
|
||||
// Note that we can ignore the 2nd return value here. Some
|
||||
// images may ship with "wrong" platform, but we already warn
|
||||
// about it. Throwing an error is not (yet) the plan.
|
||||
matchError, _, err := image.matchesPlatform(ctx, options.Architecture, options.OS, options.Variant)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("checking platform of image %s: %w", name, err)
|
||||
}
|
||||
|
||||
// If the image does not match the expected/requested platform,
|
||||
// make sure to leave some breadcrumbs for the user.
|
||||
if matchError != nil {
|
||||
if options.Writer == nil {
|
||||
logrus.Warnf("%v", matchError)
|
||||
} else {
|
||||
fmt.Fprintf(options.Writer, "WARNING: %v\n", matchError)
|
||||
}
|
||||
}
|
||||
|
||||
localImages = append(localImages, image)
|
||||
}
|
||||
|
||||
return localImages, pullError
|
||||
|
74
vendor/github.com/containers/common/libimage/runtime.go
generated
vendored
74
vendor/github.com/containers/common/libimage/runtime.go
generated
vendored
@ -182,6 +182,9 @@ type LookupImageOptions struct {
|
||||
// Lookup an image matching the specified variant.
|
||||
Variant string
|
||||
|
||||
// Controls the behavior when checking the platform of an image.
|
||||
PlatformPolicy PlatformPolicy
|
||||
|
||||
// If set, do not look for items/instances in the manifest list that
|
||||
// match the current platform but return the manifest list as is.
|
||||
// only check for manifest list, return ErrNotAManifestList if not found.
|
||||
@ -378,21 +381,36 @@ func (r *Runtime) lookupImageInLocalStorage(name, candidate string, options *Loo
|
||||
image = instance
|
||||
}
|
||||
|
||||
matches, err := r.imageReferenceMatchesContext(ref, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// NOTE: if the user referenced by ID we must optimistically assume
|
||||
// that they know what they're doing. Given, we already did the
|
||||
// manifest limbo above, we may already have resolved it.
|
||||
if !matches && !strings.HasPrefix(image.ID(), candidate) {
|
||||
return nil, nil
|
||||
}
|
||||
// Also print the string within the storage transport. That may aid in
|
||||
// debugging when using additional stores since we see explicitly where
|
||||
// the store is and which driver (options) are used.
|
||||
logrus.Debugf("Found image %q as %q in local containers storage (%s)", name, candidate, ref.StringWithinTransport())
|
||||
|
||||
// Do not perform any further platform checks if the image was
|
||||
// requested by ID. In that case, we must assume that the user/tool
|
||||
// know what they're doing.
|
||||
if strings.HasPrefix(image.ID(), candidate) {
|
||||
return image, nil
|
||||
}
|
||||
|
||||
// Ignore the (fatal) error since the image may be corrupted, which
|
||||
// will bubble up at other places. During lookup, we just return it as
|
||||
// is.
|
||||
if matchError, customPlatform, _ := image.matchesPlatform(context.Background(), options.Architecture, options.OS, options.Variant); matchError != nil {
|
||||
if customPlatform {
|
||||
logrus.Debugf("%v", matchError)
|
||||
// Return nil if the user clearly requested a custom
|
||||
// platform and the located image does not match.
|
||||
return nil, nil
|
||||
}
|
||||
switch options.PlatformPolicy {
|
||||
case PlatformPolicyDefault:
|
||||
logrus.Debugf("%v", matchError)
|
||||
case PlatformPolicyWarn:
|
||||
logrus.Warnf("%v", matchError)
|
||||
}
|
||||
}
|
||||
|
||||
return image, nil
|
||||
}
|
||||
|
||||
@ -497,40 +515,6 @@ func (r *Runtime) ResolveName(name string) (string, error) {
|
||||
return normalized.String(), nil
|
||||
}
|
||||
|
||||
// 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.Architecture+options.OS+options.Variant == "" {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
img, err := ref.NewImage(ctx, &r.systemContext)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer img.Close()
|
||||
data, err := img.Inspect(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if options.Architecture != "" && options.Architecture != data.Architecture {
|
||||
logrus.Debugf("architecture %q does not match architecture %q of image %s", options.Architecture, data.Architecture, ref)
|
||||
return false, nil
|
||||
}
|
||||
if options.OS != "" && options.OS != data.Os {
|
||||
logrus.Debugf("OS %q does not match OS %q of image %s", options.OS, data.Os, ref)
|
||||
return false, nil
|
||||
}
|
||||
if options.Variant != "" && options.Variant != data.Variant {
|
||||
logrus.Debugf("variant %q does not match variant %q of image %s", options.Variant, data.Variant, ref)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// IsExternalContainerFunc allows for checking whether the specified container
|
||||
// is an external one. The definition of an external container can be set by
|
||||
// callers.
|
||||
|
96
vendor/github.com/containers/common/pkg/completion/command.go
generated
vendored
96
vendor/github.com/containers/common/pkg/completion/command.go
generated
vendored
@ -1,96 +0,0 @@
|
||||
package completion
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const (
|
||||
completionDescription = `Generate shell autocompletions.
|
||||
Valid arguments are bash, zsh, fish and powershell.`
|
||||
|
||||
bash = "bash"
|
||||
zsh = "zsh"
|
||||
fish = "fish"
|
||||
powershell = "powershell"
|
||||
)
|
||||
|
||||
var (
|
||||
file string
|
||||
noDesc bool
|
||||
shells = []string{bash, zsh, fish, powershell}
|
||||
)
|
||||
|
||||
// AddCompletionCommand adds the completion command to the given command which should be the root command.
|
||||
// This command can be used the generate the cobra shell completion scripts for bash, zsh, fish and powershell.
|
||||
func AddCompletionCommand(rootCmd *cobra.Command) {
|
||||
completionCmd := &cobra.Command{
|
||||
Use: fmt.Sprintf("completion [options] {%s}", strings.Join(shells, "|")),
|
||||
Short: "Generate shell autocompletions",
|
||||
Long: completionDescription,
|
||||
ValidArgs: shells,
|
||||
Args: cobra.ExactValidArgs(1),
|
||||
RunE: completion,
|
||||
Example: fmt.Sprintf(`%[1]s completion bash
|
||||
%[1]s completion zsh -f _%[1]s
|
||||
%[1]s completion fish --no-desc`, rootCmd.Name()),
|
||||
// don't show this command to users
|
||||
Hidden: true,
|
||||
}
|
||||
|
||||
flags := completionCmd.Flags()
|
||||
fileFlagName := "file"
|
||||
flags.StringVarP(&file, fileFlagName, "f", "", "Output the completion to file rather than stdout.")
|
||||
_ = completionCmd.RegisterFlagCompletionFunc(fileFlagName, AutocompleteDefault)
|
||||
|
||||
flags.BoolVar(&noDesc, "no-desc", false, "Don't include descriptions in the completion output.")
|
||||
|
||||
rootCmd.AddCommand(completionCmd)
|
||||
}
|
||||
|
||||
func completion(cmd *cobra.Command, args []string) error {
|
||||
var w io.Writer
|
||||
|
||||
if file != "" {
|
||||
file, err := os.Create(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
w = file
|
||||
} else {
|
||||
w = os.Stdout
|
||||
}
|
||||
|
||||
var err error
|
||||
switch args[0] {
|
||||
case bash:
|
||||
err = cmd.Root().GenBashCompletionV2(w, !noDesc)
|
||||
case zsh:
|
||||
if noDesc {
|
||||
err = cmd.Root().GenZshCompletionNoDesc(w)
|
||||
} else {
|
||||
err = cmd.Root().GenZshCompletion(w)
|
||||
}
|
||||
case fish:
|
||||
err = cmd.Root().GenFishCompletion(w, !noDesc)
|
||||
case powershell:
|
||||
if noDesc {
|
||||
err = cmd.Root().GenPowerShellCompletion(w)
|
||||
} else {
|
||||
err = cmd.Root().GenPowerShellCompletionWithDesc(w)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = io.WriteString(w, fmt.Sprintf(
|
||||
"# This file is generated with %q; DO NOT EDIT!\n", cmd.CommandPath(),
|
||||
))
|
||||
return err
|
||||
}
|
41
vendor/github.com/containers/common/pkg/retry/retry.go
generated
vendored
41
vendor/github.com/containers/common/pkg/retry/retry.go
generated
vendored
@ -16,26 +16,29 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// RetryOptions defines the option to retry
|
||||
// revive does not like the name because the package is already called retry
|
||||
//nolint:revive
|
||||
type RetryOptions struct {
|
||||
MaxRetry int // The number of times to possibly retry
|
||||
Delay time.Duration // The delay to use between retries, if set
|
||||
// Options defines the option to retry.
|
||||
type Options struct {
|
||||
MaxRetry int // The number of times to possibly retry.
|
||||
Delay time.Duration // The delay to use between retries, if set.
|
||||
}
|
||||
|
||||
// RetryIfNecessary retries the operation in exponential backoff with the retryOptions
|
||||
//
|
||||
// revive does not like the name because the package is already called retry
|
||||
//nolint:revive
|
||||
func RetryIfNecessary(ctx context.Context, operation func() error, retryOptions *RetryOptions) error {
|
||||
// RetryOptions is deprecated, use Options.
|
||||
type RetryOptions = Options // nolint:revive
|
||||
|
||||
// RetryIfNecessary deprecated function use IfNecessary.
|
||||
func RetryIfNecessary(ctx context.Context, operation func() error, options *Options) error { // nolint:revive
|
||||
return IfNecessary(ctx, operation, options)
|
||||
}
|
||||
|
||||
// IfNecessary retries the operation in exponential backoff with the retry Options.
|
||||
func IfNecessary(ctx context.Context, operation func() error, options *Options) error {
|
||||
err := operation()
|
||||
for attempt := 0; err != nil && isRetryable(err) && attempt < retryOptions.MaxRetry; attempt++ {
|
||||
for attempt := 0; err != nil && isRetryable(err) && attempt < options.MaxRetry; attempt++ {
|
||||
delay := time.Duration(int(math.Pow(2, float64(attempt)))) * time.Second
|
||||
if retryOptions.Delay != 0 {
|
||||
delay = retryOptions.Delay
|
||||
if options.Delay != 0 {
|
||||
delay = options.Delay
|
||||
}
|
||||
logrus.Warnf("Failed, retrying in %s ... (%d/%d). Error: %v", delay, attempt+1, retryOptions.MaxRetry, err)
|
||||
logrus.Warnf("Failed, retrying in %s ... (%d/%d). Error: %v", delay, attempt+1, options.MaxRetry, err)
|
||||
select {
|
||||
case <-time.After(delay):
|
||||
break
|
||||
@ -96,6 +99,14 @@ func isRetryable(err error) bool {
|
||||
}
|
||||
}
|
||||
return true
|
||||
case net.Error:
|
||||
if e.Timeout() {
|
||||
return true
|
||||
}
|
||||
if unwrappable, ok := e.(unwrapper); ok {
|
||||
err = unwrappable.Unwrap()
|
||||
return isRetryable(err)
|
||||
}
|
||||
case unwrapper: // Test this last, because various error types might implement .Unwrap()
|
||||
err = e.Unwrap()
|
||||
return isRetryable(err)
|
||||
|
Reference in New Issue
Block a user