diff --git a/cmd/buildah/addcopy.go b/cmd/buildah/addcopy.go index cf6e2388738..cbb255810df 100644 --- a/cmd/buildah/addcopy.go +++ b/cmd/buildah/addcopy.go @@ -171,20 +171,20 @@ func addAndCopyCmd(c *cobra.Command, args []string, verb string, iopts addCopyRe if err2 != nil { return fmt.Errorf("unable to obtain decrypt config: %w", err2) } - var pullPushRetryDelay time.Duration - pullPushRetryDelay, err = time.ParseDuration(iopts.retryDelay) - if err != nil { - return fmt.Errorf("unable to parse value provided %q as --retry-delay: %w", iopts.retryDelay, err) - } options := buildah.BuilderOptions{ FromImage: iopts.from, BlobDirectory: iopts.blobCache, SignaturePolicyPath: iopts.signaturePolicy, SystemContext: systemContext, MaxPullRetries: iopts.retry, - PullRetryDelay: pullPushRetryDelay, OciDecryptConfig: decryptConfig, } + if iopts.retryDelay != "" { + options.PullRetryDelay, err = time.ParseDuration(iopts.retryDelay) + if err != nil { + return fmt.Errorf("unable to parse value provided %q as --retry-delay: %w", iopts.retryDelay, err) + } + } if !iopts.quiet { options.ReportWriter = os.Stderr } diff --git a/cmd/buildah/from.go b/cmd/buildah/from.go index eae18f8e36f..a0851f74437 100644 --- a/cmd/buildah/from.go +++ b/cmd/buildah/from.go @@ -269,12 +269,6 @@ func fromCmd(c *cobra.Command, args []string, iopts fromReply) error { return fmt.Errorf("unable to obtain decrypt config: %w", err) } - var pullPushRetryDelay time.Duration - pullPushRetryDelay, err = time.ParseDuration(iopts.RetryDelay) - if err != nil { - return fmt.Errorf("unable to parse value provided %q as --retry-delay: %w", iopts.RetryDelay, err) - } - options := buildah.BuilderOptions{ FromImage: args[0], Container: iopts.name, @@ -296,10 +290,16 @@ func fromCmd(c *cobra.Command, args []string, iopts fromReply) error { BlobDirectory: iopts.BlobCache, Devices: devices, MaxPullRetries: iopts.Retry, - PullRetryDelay: pullPushRetryDelay, OciDecryptConfig: decConfig, } + if iopts.RetryDelay != "" { + options.PullRetryDelay, err = time.ParseDuration(iopts.RetryDelay) + if err != nil { + return fmt.Errorf("unable to parse value provided %q as --retry-delay: %w", iopts.RetryDelay, err) + } + } + if !iopts.quiet { options.ReportWriter = os.Stderr } diff --git a/cmd/buildah/manifest.go b/cmd/buildah/manifest.go index fc2e44bac40..c165d1f94eb 100644 --- a/cmd/buildah/manifest.go +++ b/cmd/buildah/manifest.go @@ -268,8 +268,8 @@ func init() { } flags.BoolVar(&manifestPushOpts.tlsVerify, "tls-verify", true, "require HTTPS and verify certificates when accessing the registry. TLS verification cannot be used when talking to an insecure registry.") flags.BoolVarP(&manifestPushOpts.quiet, "quiet", "q", false, "don't output progress information when pushing lists") - flags.IntVar(&manifestPushOpts.retry, "retry", cli.MaxPullPushRetries, "number of times to retry in case of failure when performing push") - flags.StringVar(&manifestPushOpts.retryDelay, "retry-delay", cli.PullPushRetryDelay.String(), "delay between retries in case of push failures") + flags.IntVar(&manifestPushOpts.retry, "retry", int(defaultContainerConfig.Engine.Retry), "number of times to retry in case of failure when performing push") + flags.StringVar(&manifestPushOpts.retryDelay, "retry-delay", defaultContainerConfig.Engine.RetryDelay, "delay between retries in case of push failures") flags.SetNormalizeFunc(cli.AliasFlags) manifestCommand.AddCommand(manifestPushCommand) @@ -1161,10 +1161,6 @@ func manifestPush(systemContext *types.SystemContext, store storage.Store, listI } retry := uint(opts.retry) - retryDelay, err := time.ParseDuration(opts.retryDelay) - if err != nil { - return fmt.Errorf("unable to parse retryDelay %q: %w", opts.retryDelay, err) - } options := manifests.PushOptions{ Store: store, @@ -1177,7 +1173,13 @@ func manifestPush(systemContext *types.SystemContext, store storage.Store, listI AddCompression: opts.addCompression, ForceCompressionFormat: opts.forceCompressionFormat, MaxRetries: &retry, - RetryDelay: &retryDelay, + } + if opts.retryDelay != "" { + retryDelay, err := time.ParseDuration(opts.retryDelay) + if err != nil { + return fmt.Errorf("unable to parse retryDelay %q: %w", opts.retryDelay, err) + } + options.RetryDelay = &retryDelay } if opts.all { options.ImageListSelection = cp.CopyAllImages diff --git a/cmd/buildah/pull.go b/cmd/buildah/pull.go index 74fe950dca3..72b0b1c999e 100644 --- a/cmd/buildah/pull.go +++ b/cmd/buildah/pull.go @@ -74,8 +74,8 @@ func init() { flags.StringSlice("platform", []string{parse.DefaultPlatform()}, "prefer OS/ARCH instead of the current operating system and architecture for choosing images") flags.String("variant", "", "override the `variant` of the specified image") flags.BoolVar(&opts.tlsVerify, "tls-verify", true, "require HTTPS and verify certificates when accessing the registry. TLS verification cannot be used when talking to an insecure registry.") - flags.IntVar(&opts.retry, "retry", cli.MaxPullPushRetries, "number of times to retry in case of failure when performing pull") - flags.StringVar(&opts.retryDelay, "retry-delay", cli.PullPushRetryDelay.String(), "delay between retries in case of pull failures") + flags.IntVar(&opts.retry, "retry", int(defaultContainerConfig.Engine.Retry), "number of times to retry in case of failure when performing pull") + flags.StringVar(&opts.retryDelay, "retry-delay", defaultContainerConfig.Engine.RetryDelay, "delay between retries in case of pull failures") if err := flags.MarkHidden("blob-cache"); err != nil { panic(fmt.Sprintf("error marking blob-cache as hidden: %v", err)) } @@ -123,11 +123,6 @@ func pullCmd(c *cobra.Command, args []string, iopts pullOptions) error { if !ok { return fmt.Errorf("unsupported pull policy %q", iopts.pullPolicy) } - var pullPushRetryDelay time.Duration - pullPushRetryDelay, err = time.ParseDuration(iopts.retryDelay) - if err != nil { - return fmt.Errorf("unable to parse value provided %q as --retry-delay: %w", iopts.retryDelay, err) - } options := buildah.PullOptions{ SignaturePolicyPath: iopts.signaturePolicy, Store: store, @@ -137,11 +132,17 @@ func pullCmd(c *cobra.Command, args []string, iopts pullOptions) error { ReportWriter: os.Stderr, RemoveSignatures: iopts.removeSignatures, MaxRetries: iopts.retry, - RetryDelay: pullPushRetryDelay, OciDecryptConfig: decConfig, PullPolicy: policy, } + if iopts.retryDelay != "" { + options.RetryDelay, err = time.ParseDuration(iopts.retryDelay) + if err != nil { + return fmt.Errorf("unable to parse value provided %q as --retry-delay: %w", iopts.retryDelay, err) + } + } + if iopts.quiet { options.ReportWriter = nil // Turns off logging output } diff --git a/cmd/buildah/push.go b/cmd/buildah/push.go index 3086dae8283..1b443a34244 100644 --- a/cmd/buildah/push.go +++ b/cmd/buildah/push.go @@ -92,8 +92,8 @@ func init() { flags.StringVar(&opts.compressionFormat, "compression-format", "", "compression format to use") flags.IntVar(&opts.compressionLevel, "compression-level", 0, "compression level to use") flags.BoolVarP(&opts.quiet, "quiet", "q", false, "don't output progress information when pushing images") - flags.IntVar(&opts.retry, "retry", cli.MaxPullPushRetries, "number of times to retry in case of failure when performing push/pull") - flags.StringVar(&opts.retryDelay, "retry-delay", cli.PullPushRetryDelay.String(), "delay between retries in case of push/pull failures") + flags.IntVar(&opts.retry, "retry", int(defaultContainerConfig.Engine.Retry), "number of times to retry in case of failure when performing push") + flags.StringVar(&opts.retryDelay, "retry-delay", defaultContainerConfig.Engine.RetryDelay, "delay between retries in case of push failures") flags.BoolVar(&opts.rm, "rm", false, "remove the manifest list if push succeeds") flags.BoolVarP(&opts.removeSignatures, "remove-signatures", "", false, "don't copy signatures when pushing image") flags.StringVar(&opts.signBy, "sign-by", "", "sign the image using a GPG key with the specified `FINGERPRINT`") @@ -194,11 +194,6 @@ func pushCmd(c *cobra.Command, args []string, iopts pushOptions) error { return fmt.Errorf("unable to obtain encryption config: %w", err) } - var pullPushRetryDelay time.Duration - pullPushRetryDelay, err = time.ParseDuration(iopts.retryDelay) - if err != nil { - return fmt.Errorf("unable to parse value provided %q as --retry-delay: %w", iopts.retryDelay, err) - } if c.Flag("compression-format").Changed { if !c.Flag("force-compression").Changed { // If `compression-format` is set and no value for `--force-compression` @@ -217,11 +212,16 @@ func pushCmd(c *cobra.Command, args []string, iopts pushOptions) error { RemoveSignatures: iopts.removeSignatures, SignBy: iopts.signBy, MaxRetries: iopts.retry, - RetryDelay: pullPushRetryDelay, OciEncryptConfig: encConfig, OciEncryptLayers: encLayers, ForceCompressionFormat: iopts.forceCompressionFormat, } + if iopts.retryDelay != "" { + options.RetryDelay, err = time.ParseDuration(iopts.retryDelay) + if err != nil { + return fmt.Errorf("unable to parse value provided %q as --retry-delay: %w", iopts.retryDelay, err) + } + } if !iopts.quiet { options.ReportWriter = os.Stderr } diff --git a/pkg/cli/build.go b/pkg/cli/build.go index 6a15b60c9ae..fec10f06acf 100644 --- a/pkg/cli/build.go +++ b/pkg/cli/build.go @@ -316,13 +316,6 @@ func GenBuildOptions(c *cobra.Command, inputArgs []string, iopts BuildOptions) ( iopts.NoCache = true } } - var pullPushRetryDelay time.Duration - pullPushRetryDelay, err = time.ParseDuration(iopts.RetryDelay) - if err != nil { - return options, nil, nil, fmt.Errorf("unable to parse value provided %q as --retry-delay: %w", iopts.RetryDelay, err) - } - // Following log line is used in integration test. - logrus.Debugf("Setting MaxPullPushRetries to %d and PullPushRetryDelay to %v", iopts.Retry, pullPushRetryDelay) if c.Flag("network").Changed && c.Flag("isolation").Changed { if isolation == define.IsolationChroot { @@ -405,7 +398,6 @@ func GenBuildOptions(c *cobra.Command, inputArgs []string, iopts BuildOptions) ( OutputFormat: format, Platforms: platforms, PullPolicy: pullPolicy, - PullPushRetryDelay: pullPushRetryDelay, Quiet: iopts.Quiet, RemoveIntermediateCtrs: iopts.Rm, ReportWriter: reporter, @@ -424,6 +416,15 @@ func GenBuildOptions(c *cobra.Command, inputArgs []string, iopts BuildOptions) ( UnsetEnvs: iopts.UnsetEnvs, UnsetLabels: iopts.UnsetLabels, } + if iopts.RetryDelay != "" { + options.PullPushRetryDelay, err = time.ParseDuration(iopts.RetryDelay) + if err != nil { + return options, nil, nil, fmt.Errorf("unable to parse value provided %q as --retry-delay: %w", iopts.RetryDelay, err) + } + // Following log line is used in integration test. + logrus.Debugf("Setting MaxPullPushRetries to %d and PullPushRetryDelay to %v", iopts.Retry, options.PullPushRetryDelay) + } + if iopts.Quiet { options.ReportWriter = io.Discard } diff --git a/pkg/cli/common.go b/pkg/cli/common.go index da33983f486..ba29fe03dd6 100644 --- a/pkg/cli/common.go +++ b/pkg/cli/common.go @@ -392,8 +392,8 @@ func GetFromAndBudFlags(flags *FromAndBudResults, usernsResults *UserNSResults, fs.StringVar(&flags.Isolation, "isolation", DefaultIsolation(), "`type` of process isolation to use. Use BUILDAH_ISOLATION environment variable to override.") fs.StringVarP(&flags.Memory, "memory", "m", "", "memory limit (format: [], where unit = b, k, m or g)") fs.StringVar(&flags.MemorySwap, "memory-swap", "", "swap limit equal to memory plus swap: '-1' to enable unlimited swap") - fs.IntVar(&flags.Retry, "retry", MaxPullPushRetries, "number of times to retry in case of failure when performing push/pull") - fs.StringVar(&flags.RetryDelay, "retry-delay", PullPushRetryDelay.String(), "delay between retries in case of push/pull failures") + fs.IntVar(&flags.Retry, "retry", int(defaultContainerConfig.Engine.Retry), "number of times to retry in case of failure when performing push/pull") + fs.StringVar(&flags.RetryDelay, "retry-delay", defaultContainerConfig.Engine.RetryDelay, "delay between retries in case of push/pull failures") fs.String("arch", runtime.GOARCH, "set the ARCH of the image to the provided value instead of the architecture of the host") fs.String("os", runtime.GOOS, "prefer `OS` instead of the running OS when pulling images") fs.StringSlice("platform", []string{parse.DefaultPlatform()}, "set the `OS/ARCH[/VARIANT]` of the image to the provided value instead of the current operating system and architecture of the host (for example \"linux/arm\")") diff --git a/tests/bud.bats b/tests/bud.bats index b20b4d1257d..e5bf859d58d 100644 --- a/tests/bud.bats +++ b/tests/bud.bats @@ -6618,10 +6618,10 @@ _EOF skip_if_no_runtime _prefetch alpine - run podman run --rm alpine sh -c "echo -n Files=; awk '/open files/{print \$4 \"/\" \$5}' /proc/self/limits" + run podman --events-backend=none run --rm alpine sh -c "echo -n Files=; awk '/open files/{print \$4 \"/\" \$5}' /proc/self/limits" podman_files=$output - run podman run --rm alpine sh -c "echo -n Processes=; awk '/processes/{print \$3 \"/\" \$4}' /proc/self/limits" + run podman --events-backend=none run --rm alpine sh -c "echo -n Processes=; awk '/processes/{print \$3 \"/\" \$4}' /proc/self/limits" podman_processes=$output CONTAINERS_CONF=/dev/null run_buildah build --no-cache --pull=false $WITH_POLICY_JSON -t foo/bar $BUDFILES/bud.limits diff --git a/tests/containers_conf.bats b/tests/containers_conf.bats index e90de6662d9..491e7170425 100644 --- a/tests/containers_conf.bats +++ b/tests/containers_conf.bats @@ -138,3 +138,32 @@ _EOF fi } + + +@test "containers.conf retry" { + cat >${TEST_SCRATCH_DIR}/containers.conf << EOF +[engine] +retry=10 +retry_delay="5s" +EOF + _prefetch alpine + CONTAINERS_CONF=${TEST_SCRATCH_DIR}/containers.conf run_buildah build --help + expect_output --substring "retry.*\(default 10\)" + expect_output --substring "retry-delay.*\(default \"5s\"\)" + + CONTAINERS_CONF=${TEST_SCRATCH_DIR}/containers.conf run_buildah push --help + expect_output --substring "retry.*\(default 10\)" + expect_output --substring "retry-delay.*\(default \"5s\"\)" + + CONTAINERS_CONF=${TEST_SCRATCH_DIR}/containers.conf run_buildah pull --help + expect_output --substring "retry.*\(default 10\)" + expect_output --substring "retry-delay.*\(default \"5s\"\)" + + CONTAINERS_CONF=${TEST_SCRATCH_DIR}/containers.conf run_buildah from --help + expect_output --substring "retry.*\(default 10\)" + expect_output --substring "retry-delay.*\(default \"5s\"\)" + + CONTAINERS_CONF=${TEST_SCRATCH_DIR}/containers.conf run_buildah manifest push --help + expect_output --substring "retry.*\(default 10\)" + expect_output --substring "retry-delay.*\(default \"5s\"\)" +}