diff --git a/cmd/skopeo/copy.go b/cmd/skopeo/copy.go index 8f8825870d..448b09628e 100644 --- a/cmd/skopeo/copy.go +++ b/cmd/skopeo/copy.go @@ -1,6 +1,7 @@ package main import ( + "context" "errors" "fmt" "os" @@ -30,36 +31,36 @@ func contextsFromGlobalOptions(c *cli.Context) (*types.SystemContext, *types.Sys return sourceCtx, destinationCtx, nil } -func copyHandler(context *cli.Context) error { - if len(context.Args()) != 2 { +func copyHandler(c *cli.Context) error { + if len(c.Args()) != 2 { return errors.New("Usage: copy source destination") } - policyContext, err := getPolicyContext(context) + policyContext, err := getPolicyContext(c) if err != nil { return fmt.Errorf("Error loading trust policy: %v", err) } defer policyContext.Destroy() - srcRef, err := alltransports.ParseImageName(context.Args()[0]) + srcRef, err := alltransports.ParseImageName(c.Args()[0]) if err != nil { - return fmt.Errorf("Invalid source name %s: %v", context.Args()[0], err) + return fmt.Errorf("Invalid source name %s: %v", c.Args()[0], err) } - destRef, err := alltransports.ParseImageName(context.Args()[1]) + destRef, err := alltransports.ParseImageName(c.Args()[1]) if err != nil { - return fmt.Errorf("Invalid destination name %s: %v", context.Args()[1], err) + return fmt.Errorf("Invalid destination name %s: %v", c.Args()[1], err) } - signBy := context.String("sign-by") - removeSignatures := context.Bool("remove-signatures") + signBy := c.String("sign-by") + removeSignatures := c.Bool("remove-signatures") - sourceCtx, destinationCtx, err := contextsFromGlobalOptions(context) + sourceCtx, destinationCtx, err := contextsFromGlobalOptions(c) if err != nil { return err } var manifestType string - if context.IsSet("format") { - switch context.String("format") { + if c.IsSet("format") { + switch c.String("format") { case "oci": manifestType = imgspecv1.MediaTypeImageManifest case "v2s1": @@ -67,11 +68,11 @@ func copyHandler(context *cli.Context) error { case "v2s2": manifestType = manifest.DockerV2Schema2MediaType default: - return fmt.Errorf("unknown format %q. Choose on of the supported formats: 'oci', 'v2s1', or 'v2s2'", context.String("format")) + return fmt.Errorf("unknown format %q. Choose on of the supported formats: 'oci', 'v2s1', or 'v2s2'", c.String("format")) } } - return copy.Image(policyContext, destRef, srcRef, ©.Options{ + return copy.Image(context.Background(), policyContext, destRef, srcRef, ©.Options{ RemoveSignatures: removeSignatures, SignBy: signBy, ReportWriter: os.Stdout, diff --git a/cmd/skopeo/delete.go b/cmd/skopeo/delete.go index afe99f0ba5..4cc63b00eb 100644 --- a/cmd/skopeo/delete.go +++ b/cmd/skopeo/delete.go @@ -1,6 +1,7 @@ package main import ( + "context" "errors" "fmt" "strings" @@ -10,21 +11,21 @@ import ( "github.com/urfave/cli" ) -func deleteHandler(context *cli.Context) error { - if len(context.Args()) != 1 { +func deleteHandler(c *cli.Context) error { + if len(c.Args()) != 1 { return errors.New("Usage: delete imageReference") } - ref, err := alltransports.ParseImageName(context.Args()[0]) + ref, err := alltransports.ParseImageName(c.Args()[0]) if err != nil { - return fmt.Errorf("Invalid source name %s: %v", context.Args()[0], err) + return fmt.Errorf("Invalid source name %s: %v", c.Args()[0], err) } - ctx, err := contextFromGlobalOptions(context, "") + sys, err := contextFromGlobalOptions(c, "") if err != nil { return err } - return ref.DeleteImage(ctx) + return ref.DeleteImage(context.Background(), sys) } var deleteCmd = cli.Command{ diff --git a/cmd/skopeo/inspect.go b/cmd/skopeo/inspect.go index 380b5352e8..ec39429952 100644 --- a/cmd/skopeo/inspect.go +++ b/cmd/skopeo/inspect.go @@ -1,6 +1,7 @@ package main import ( + "context" "encoding/json" "fmt" "strings" @@ -66,7 +67,9 @@ var inspectCmd = cli.Command{ }, }, Action: func(c *cli.Context) (retErr error) { - img, err := parseImage(c) + ctx := context.Background() + + img, err := parseImage(ctx, c) if err != nil { return err } @@ -77,7 +80,7 @@ var inspectCmd = cli.Command{ } }() - rawManifest, _, err := img.Manifest() + rawManifest, _, err := img.Manifest(ctx) if err != nil { return err } @@ -88,7 +91,7 @@ var inspectCmd = cli.Command{ } return nil } - imgInspect, err := img.Inspect() + imgInspect, err := img.Inspect(ctx) if err != nil { return err } @@ -110,7 +113,7 @@ var inspectCmd = cli.Command{ } if dockerImg, ok := img.(*docker.Image); ok { outputData.Name = dockerImg.SourceRefFullName() - outputData.RepoTags, err = dockerImg.GetRepositoryTags() + outputData.RepoTags, err = dockerImg.GetRepositoryTags(ctx) if err != nil { // some registries may decide to block the "list all tags" endpoint // gracefully allow the inspect to continue in this case. Currently diff --git a/cmd/skopeo/layers.go b/cmd/skopeo/layers.go index 18bfd273c4..8461958012 100644 --- a/cmd/skopeo/layers.go +++ b/cmd/skopeo/layers.go @@ -1,6 +1,7 @@ package main import ( + "context" "fmt" "io/ioutil" "os" @@ -24,15 +25,18 @@ var layersCmd = cli.Command{ if c.NArg() == 0 { return errors.New("Usage: layers imageReference [layer...]") } - ctx, err := contextFromGlobalOptions(c, "") + + ctx := context.Background() + + sys, err := contextFromGlobalOptions(c, "") if err != nil { return err } - rawSource, err := parseImageSource(c, c.Args()[0]) + rawSource, err := parseImageSource(ctx, c, c.Args()[0]) if err != nil { return err } - src, err := image.FromSource(ctx, rawSource) + src, err := image.FromSource(ctx, sys, rawSource) if err != nil { if closeErr := rawSource.Close(); closeErr != nil { return errors.Wrapf(err, " (close error: %v)", closeErr) @@ -85,7 +89,7 @@ var layersCmd = cli.Command{ if err != nil { return err } - dest, err := tmpDirRef.NewImageDestination(nil) + dest, err := tmpDirRef.NewImageDestination(ctx, nil) if err != nil { return err } @@ -97,11 +101,11 @@ var layersCmd = cli.Command{ }() for _, bd := range blobDigests { - r, blobSize, err := rawSource.GetBlob(types.BlobInfo{Digest: bd.digest, Size: -1}) + r, blobSize, err := rawSource.GetBlob(ctx, types.BlobInfo{Digest: bd.digest, Size: -1}) if err != nil { return err } - if _, err := dest.PutBlob(r, types.BlobInfo{Digest: bd.digest, Size: blobSize}, bd.isConfig); err != nil { + if _, err := dest.PutBlob(ctx, r, types.BlobInfo{Digest: bd.digest, Size: blobSize}, bd.isConfig); err != nil { if closeErr := r.Close(); closeErr != nil { return errors.Wrapf(err, " (close error: %v)", closeErr) } @@ -109,14 +113,14 @@ var layersCmd = cli.Command{ } } - manifest, _, err := src.Manifest() + manifest, _, err := src.Manifest(ctx) if err != nil { return err } - if err := dest.PutManifest(manifest); err != nil { + if err := dest.PutManifest(ctx, manifest); err != nil { return err } - return dest.Commit() + return dest.Commit(ctx) }, } diff --git a/cmd/skopeo/signing.go b/cmd/skopeo/signing.go index ff04ebeaa7..500fedd5b3 100644 --- a/cmd/skopeo/signing.go +++ b/cmd/skopeo/signing.go @@ -10,14 +10,14 @@ import ( "github.com/urfave/cli" ) -func standaloneSign(context *cli.Context) error { - outputFile := context.String("output") - if len(context.Args()) != 3 || outputFile == "" { +func standaloneSign(c *cli.Context) error { + outputFile := c.String("output") + if len(c.Args()) != 3 || outputFile == "" { return errors.New("Usage: skopeo standalone-sign manifest docker-reference key-fingerprint -o signature") } - manifestPath := context.Args()[0] - dockerReference := context.Args()[1] - fingerprint := context.Args()[2] + manifestPath := c.Args()[0] + dockerReference := c.Args()[1] + fingerprint := c.Args()[2] manifest, err := ioutil.ReadFile(manifestPath) if err != nil { @@ -53,14 +53,14 @@ var standaloneSignCmd = cli.Command{ }, } -func standaloneVerify(context *cli.Context) error { - if len(context.Args()) != 4 { +func standaloneVerify(c *cli.Context) error { + if len(c.Args()) != 4 { return errors.New("Usage: skopeo standalone-verify manifest docker-reference key-fingerprint signature") } - manifestPath := context.Args()[0] - expectedDockerReference := context.Args()[1] - expectedFingerprint := context.Args()[2] - signaturePath := context.Args()[3] + manifestPath := c.Args()[0] + expectedDockerReference := c.Args()[1] + expectedFingerprint := c.Args()[2] + signaturePath := c.Args()[3] unverifiedManifest, err := ioutil.ReadFile(manifestPath) if err != nil { @@ -81,7 +81,7 @@ func standaloneVerify(context *cli.Context) error { return fmt.Errorf("Error verifying signature: %v", err) } - fmt.Fprintf(context.App.Writer, "Signature verified, digest %s\n", sig.DockerManifestDigest) + fmt.Fprintf(c.App.Writer, "Signature verified, digest %s\n", sig.DockerManifestDigest) return nil } @@ -92,11 +92,11 @@ var standaloneVerifyCmd = cli.Command{ Action: standaloneVerify, } -func untrustedSignatureDump(context *cli.Context) error { - if len(context.Args()) != 1 { +func untrustedSignatureDump(c *cli.Context) error { + if len(c.Args()) != 1 { return errors.New("Usage: skopeo untrusted-signature-dump-without-verification signature") } - untrustedSignaturePath := context.Args()[0] + untrustedSignaturePath := c.Args()[0] untrustedSignature, err := ioutil.ReadFile(untrustedSignaturePath) if err != nil { @@ -111,7 +111,7 @@ func untrustedSignatureDump(context *cli.Context) error { if err != nil { return err } - fmt.Fprintln(context.App.Writer, string(untrustedOut)) + fmt.Fprintln(c.App.Writer, string(untrustedOut)) return nil } diff --git a/cmd/skopeo/utils.go b/cmd/skopeo/utils.go index 50ec0cd476..f07b24b654 100644 --- a/cmd/skopeo/utils.go +++ b/cmd/skopeo/utils.go @@ -1,6 +1,7 @@ package main import ( + "context" "errors" "strings" @@ -66,29 +67,29 @@ func getDockerAuth(creds string) (*types.DockerAuthConfig, error) { // parseImage converts image URL-like string to an initialized handler for that image. // The caller must call .Close() on the returned ImageCloser. -func parseImage(c *cli.Context) (types.ImageCloser, error) { +func parseImage(ctx context.Context, c *cli.Context) (types.ImageCloser, error) { imgName := c.Args().First() ref, err := alltransports.ParseImageName(imgName) if err != nil { return nil, err } - ctx, err := contextFromGlobalOptions(c, "") + sys, err := contextFromGlobalOptions(c, "") if err != nil { return nil, err } - return ref.NewImage(ctx) + return ref.NewImage(ctx, sys) } // parseImageSource converts image URL-like string to an ImageSource. // The caller must call .Close() on the returned ImageSource. -func parseImageSource(c *cli.Context, name string) (types.ImageSource, error) { +func parseImageSource(ctx context.Context, c *cli.Context, name string) (types.ImageSource, error) { ref, err := alltransports.ParseImageName(name) if err != nil { return nil, err } - ctx, err := contextFromGlobalOptions(c, "") + sys, err := contextFromGlobalOptions(c, "") if err != nil { return nil, err } - return ref.NewImageSource(ctx) + return ref.NewImageSource(ctx, sys) }