mirror of
https://github.com/containers/skopeo.git
synced 2025-07-04 02:16:56 +00:00
add command timeout support for skopeo
* add global command-timeout option for skopeo
This commit is contained in:
parent
b52e700666
commit
3456577268
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@ -88,7 +87,10 @@ func copyHandler(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = copy.Image(context.Background(), policyContext, destRef, srcRef, ©.Options{
|
ctx, cancel := commandTimeoutContextFromGlobalOptions(c)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
_, err = copy.Image(ctx, policyContext, destRef, srcRef, ©.Options{
|
||||||
RemoveSignatures: removeSignatures,
|
RemoveSignatures: removeSignatures,
|
||||||
SignBy: signBy,
|
SignBy: signBy,
|
||||||
ReportWriter: os.Stdout,
|
ReportWriter: os.Stdout,
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
@ -25,7 +24,10 @@ func deleteHandler(c *cli.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return ref.DeleteImage(context.Background(), sys)
|
|
||||||
|
ctx, cancel := commandTimeoutContextFromGlobalOptions(c)
|
||||||
|
defer cancel()
|
||||||
|
return ref.DeleteImage(ctx, sys)
|
||||||
}
|
}
|
||||||
|
|
||||||
var deleteCmd = cli.Command{
|
var deleteCmd = cli.Command{
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
@ -67,7 +66,8 @@ var inspectCmd = cli.Command{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) (retErr error) {
|
Action: func(c *cli.Context) (retErr error) {
|
||||||
ctx := context.Background()
|
ctx, cancel := commandTimeoutContextFromGlobalOptions(c)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
img, err := parseImage(ctx, c)
|
img, err := parseImage(ctx, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@ -26,7 +25,8 @@ var layersCmd = cli.Command{
|
|||||||
return errors.New("Usage: layers imageReference [layer...]")
|
return errors.New("Usage: layers imageReference [layer...]")
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx, cancel := commandTimeoutContextFromGlobalOptions(c)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
sys, err := contextFromGlobalOptions(c, "")
|
sys, err := contextFromGlobalOptions(c, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -60,6 +60,10 @@ func createApp() *cli.App {
|
|||||||
Value: "",
|
Value: "",
|
||||||
Usage: "use `OS` instead of the running OS for choosing images",
|
Usage: "use `OS` instead of the running OS for choosing images",
|
||||||
},
|
},
|
||||||
|
cli.DurationFlag{
|
||||||
|
Name: "command-timeout",
|
||||||
|
Usage: "timeout for the command execution",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
app.Before = func(c *cli.Context) error {
|
app.Before = func(c *cli.Context) error {
|
||||||
if c.GlobalBool("debug") {
|
if c.GlobalBool("debug") {
|
||||||
|
@ -40,6 +40,15 @@ func contextFromGlobalOptions(c *cli.Context, flagPrefix string) (*types.SystemC
|
|||||||
return ctx, nil
|
return ctx, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func commandTimeoutContextFromGlobalOptions(c *cli.Context) (context.Context, context.CancelFunc) {
|
||||||
|
ctx := context.Background()
|
||||||
|
var cancel context.CancelFunc = func() {}
|
||||||
|
if c.GlobalDuration("command-timeout") > 0 {
|
||||||
|
ctx, cancel = context.WithTimeout(ctx, c.GlobalDuration("command-timeout"))
|
||||||
|
}
|
||||||
|
return ctx, cancel
|
||||||
|
}
|
||||||
|
|
||||||
func parseCreds(creds string) (string, string, error) {
|
func parseCreds(creds string) (string, string, error) {
|
||||||
if creds == "" {
|
if creds == "" {
|
||||||
return "", "", errors.New("credentials can't be empty")
|
return "", "", errors.New("credentials can't be empty")
|
||||||
|
@ -110,6 +110,7 @@ _skopeo_skopeo() {
|
|||||||
--registries.d
|
--registries.d
|
||||||
--override-arch
|
--override-arch
|
||||||
--override-os
|
--override-os
|
||||||
|
--command-timeout
|
||||||
"
|
"
|
||||||
local boolean_options="
|
local boolean_options="
|
||||||
--insecure-policy
|
--insecure-policy
|
||||||
|
@ -59,6 +59,8 @@ Most commands refer to container images, using a _transport_`:`_details_ format.
|
|||||||
|
|
||||||
**--override-os** _OS_ Use _OS_ instead of the running OS for choosing images.
|
**--override-os** _OS_ Use _OS_ instead of the running OS for choosing images.
|
||||||
|
|
||||||
|
**--command-timeout** _duration_ Timeout for the command execution.
|
||||||
|
|
||||||
**--help**|**-h** Show help
|
**--help**|**-h** Show help
|
||||||
|
|
||||||
**--version**|**-v** print the version number
|
**--version**|**-v** print the version number
|
||||||
|
Loading…
Reference in New Issue
Block a user