From 80cac4cc4bc864aa5465a0109d9e1a783662c76d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Mon, 4 Jun 2018 15:48:56 +0200 Subject: [PATCH] Add option to fetch Docker-Content-Digest Code reused from manifest.go; this one is helpful to figure out if tags have changed --- README.md | 7 +++++++ digest.go | 39 +++++++++++++++++++++++++++++++++++++++ main.go | 1 + 3 files changed, 47 insertions(+) create mode 100644 digest.go diff --git a/README.md b/README.md index e978d809..f16eb538 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ AUTHOR: COMMANDS: delete, rm delete a specific reference of a repository + digest get the Docker-Content-Digest layer, download download a layer for the specific reference of a repository list, ls list all repositories manifest get the json manifest for the specific reference of a repository @@ -102,6 +103,12 @@ latest stable ``` +## Get the Docker-Content-Digest +```console +$ reg digest htop +"sha256:791158756cc0f5b27ef8c5c546284568fc9b7f4cf1429fb736aff3ee2d2e340f" +``` + ## Get a Manifest ```console diff --git a/digest.go b/digest.go new file mode 100644 index 00000000..524b2e06 --- /dev/null +++ b/digest.go @@ -0,0 +1,39 @@ +package main + +import ( + "encoding/json" + "fmt" + + "github.com/genuinetools/reg/repoutils" + "github.com/urfave/cli" +) + +var digestCommand = cli.Command{ + Name: "digest", + Usage: "get the Docker-Content-Digest", + Action: func(c *cli.Context) error { + if len(c.Args()) < 1 { + return fmt.Errorf("pass the name of the repository") + } + + repo, ref, err := repoutils.GetRepoAndRef(c.Args()[0]) + if err != nil { + return err + } + + var digest interface{} + digest, err = r.Digest(repo, ref) + if err != nil { + return err + } + + b, err := json.MarshalIndent(digest, " ", " ") + if err != nil { + return err + } + + fmt.Println(string(b)) + + return nil + }, +} diff --git a/main.go b/main.go index 6303dd86..18b8c726 100644 --- a/main.go +++ b/main.go @@ -57,6 +57,7 @@ func main() { app.Commands = []cli.Command{ deleteCommand, + digestCommand, layerCommand, listCommand, manifestCommand,