Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crane: add digest --full #1524

Merged
merged 2 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion cmd/crane/cmd/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import (
"fmt"

"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/name"
"github.com/spf13/cobra"
)

// NewCmdDigest creates a new cobra.Command for the digest subcommand.
func NewCmdDigest(options *[]crane.Option) *cobra.Command {
var tarball string
var fullRef bool
cmd := &cobra.Command{
Use: "digest IMAGE",
Short: "Get the digest of an image",
Expand All @@ -36,17 +38,29 @@ func NewCmdDigest(options *[]crane.Option) *cobra.Command {
}
return errors.New("image reference required without --tarball")
}
if fullRef && tarball != "" {
return errors.New("cannot specify --full-ref with --tarball")
}

digest, err := getDigest(tarball, args, options)
if err != nil {
return err
}
fmt.Println(digest)
if fullRef {
ref, err := name.ParseReference(args[0])
if err != nil {
return err
}
fmt.Println(ref.Context().Digest(digest))
} else {
fmt.Println(digest)
}
return nil
},
}

cmd.Flags().StringVar(&tarball, "tarball", "", "(Optional) path to tarball containing the image")
cmd.Flags().BoolVar(&fullRef, "full-ref", false, "(Optional) if true, print the full image reference by digest")

return cmd
}
Expand Down
1 change: 1 addition & 0 deletions cmd/crane/doc/crane_digest.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.