Skip to content

Commit

Permalink
add digests flag and detailed arch (#21)
Browse files Browse the repository at this point in the history
* add digests flag
* add variants and features to  arch
  • Loading branch information
tomoyamachi authored Apr 4, 2020
1 parent e5e312d commit f80aee1
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 72 deletions.
5 changes: 4 additions & 1 deletion cmd/dockertags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ OPTIONS:
app.Name = "dockertags"
app.Version = version
app.ArgsUsage = "image_name"

app.Usage = "fetch docker image tags"

app.Flags = []cli.Flag{
Expand Down Expand Up @@ -74,6 +73,10 @@ OPTIONS:
Name: "password, p",
Usage: "Using -password via CLI is insecure. Be careful.",
},
cli.BoolFlag{
Name: "digests",
Usage: "Show long digests",
},
cli.BoolFlag{
Name: "debug, d",
Usage: "Show debug logs",
Expand Down
9 changes: 7 additions & 2 deletions internal/report/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (

// TableWriter output table format
type TableWriter struct {
Output io.Writer
Output io.Writer
LongDigests bool
}

// Write is
Expand All @@ -31,7 +32,11 @@ func (w TableWriter) Write(tags types.ImageTags) (err error) {
var sizes, digests, osArchs []string
for _, datum := range tag.Data {
sizes = append(sizes, getBytesize(datum.Byte))
digests = append(digests, trimHash(datum.Digest))
digest := datum.Digest
if !w.LongDigests {
digest = trimHash(datum.Digest)
}
digests = append(digests, digest)
if datum.Os != "" {
osArchs = append(osArchs, fmt.Sprintf("%s/%s", datum.Os, datum.Arch))
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/provider/dockerhub/dockerhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,27 @@ func (p *DockerHub) summarizeByTagNames(keyDigestMap map[string]types.ImageTag)
func convertUploadImageTag(is tagSummary, img image) types.ImageTag {
uploadedAt, _ := time.Parse(time.RFC3339Nano, is.LastUpdated)
tagNames := []string{is.Name}
archName := concatWithSlash(img.Architecture, img.Features)
archName = concatWithSlash(archName, img.Variant)
return types.ImageTag{
Tags: tagNames,
Data: []types.TagAttr{{
Os: img.Os,
Arch: img.Architecture,
Arch: archName,
Digest: img.Digest,
Byte: img.Size,
}},
UploadedAt: uploadedAt,
}
}

func concatWithSlash(original, adding string) string {
if adding == "" {
return original
}
return original + "/" + adding
}

// getTagResponse returns the tags for a specific repository.
// curl 'https://registry.hub.docker.com/v2/repositories/library/debian/tags/'
func getTagResponse(ctx context.Context, auth dockertypes.AuthConfig, timeout time.Duration, repository string, page int) (tagsResponse, error) {
Expand Down
Loading

0 comments on commit f80aee1

Please sign in to comment.