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

Add size column to tags page #215

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/docker/docker v1.4.2-0.20190916154449-92cc603036dd
github.com/docker/docker-credential-helpers v0.6.3 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/docker/go-units v0.4.0
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
github.com/fernet/fernet-go v0.0.0-20180830025343-9eac43b88a5e // indirect
github.com/genuinetools/pkg v0.0.0-20181022210355-2fcf164d37cb
Expand Down
65 changes: 48 additions & 17 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"sync"
"time"

"github.com/docker/go-units"
"github.com/genuinetools/reg/clair"
"github.com/genuinetools/reg/registry"
"github.com/gorilla/mux"
Expand Down Expand Up @@ -42,6 +43,7 @@ type Repository struct {
Created time.Time `json:"created"`
URI string `json:"uri"`
VulnerabilityReport clair.VulnerabilityReport `json:"vulnerability"`
Size string `json:"size"`
}

// An AnalysisResult holds all vulnerabilities of a scan
Expand Down Expand Up @@ -196,33 +198,62 @@ func (rc *registryController) generateTagsTemplate(ctx context.Context, repo str
}

for _, tag := range tags {
// get the manifest
m1, err := rc.reg.ManifestV1(ctx, repo, tag)
if err != nil {
return nil, fmt.Errorf("getting v1 manifest for %s:%s failed: %v", repo, tag, err)
rp := Repository{
Name: repo,
Tag: tag,
}

var createdDate time.Time
for _, h := range m1.History {
var comp v1Compatibility
ch := make(chan error)
go func() {
// get the manifest
m1, err := rc.reg.ManifestV1(ctx, repo, tag)
if err != nil {
ch <- fmt.Errorf("getting v1 manifest for %s:%s failed: %v", repo, tag, err)
return
}

var createdDate time.Time
for _, h := range m1.History {
var comp v1Compatibility

if err := json.Unmarshal([]byte(h.V1Compatibility), &comp); err != nil {
return nil, fmt.Errorf("unmarshal v1 manifest for %s:%s failed: %v", repo, tag, err)
if err := json.Unmarshal([]byte(h.V1Compatibility), &comp); err != nil {
ch <- fmt.Errorf("unmarshal v1 manifest for %s:%s failed: %v", repo, tag, err)
return
}

createdDate = comp.Created
break
}
rp.Created = createdDate
ch <- nil
}()

createdDate = comp.Created
break
}
go func() {
m2, err := rc.reg.ManifestV2(ctx, repo, tag)
if err != nil {
ch <- fmt.Errorf("getting v2 manifest for %s:%s failed: %v", repo, tag, err)
return
}
var size float64
for _, layer := range m2.Layers {
size += float64(layer.Size)
}

rp.Size = units.BytesSize(size)
ch <- nil
}()

repoURI := fmt.Sprintf("%s/%s", rc.reg.Domain, repo)
if tag != "latest" {
repoURI += ":" + tag
}
rp := Repository{
Name: repo,
Tag: tag,
URI: repoURI,
Created: createdDate,
rp.URI = repoURI

for i := 0; i < 2; i++ {
err := <-ch
if err != nil {
return nil, err
}
}

result.Repositories = append(result.Repositories, rp)
Expand Down
64 changes: 32 additions & 32 deletions internal/binutils/static/static.go

Large diffs are not rendered by default.

Loading