fix created date

Signed-off-by: Jess Frazelle <acidburn@google.com>
This commit is contained in:
Jess Frazelle 2016-12-19 21:33:29 -08:00
parent e33d3e5526
commit d1014eed19
No known key found for this signature in database
GPG key ID: 18F3685C0022BFF3
3 changed files with 44 additions and 10 deletions

View file

@ -1,6 +1,7 @@
package main
import (
"encoding/json"
"errors"
"fmt"
"html/template"
@ -12,6 +13,7 @@ import (
"time"
"github.com/Sirupsen/logrus"
"github.com/docker/distribution/manifest/schema1"
"github.com/docker/docker/cliconfig"
"github.com/docker/engine-api/types"
"github.com/jessfraz/reg/registry"
@ -224,9 +226,14 @@ type data struct {
type repository struct {
Name string
Tags string
Tag string
RegistryURL string
// TODO: add date last uploaded
CreatedDate string
}
type v1Compatibility struct {
ID string `json:"id"`
Created time.Time `json:"created"`
}
func createStaticIndex(r *registry.Registry, staticDir string) error {
@ -240,15 +247,38 @@ func createStaticIndex(r *registry.Registry, staticDir string) error {
logrus.Info("fetching tags")
var repos []repository
for _, repo := range repoList {
// get the tags
tags, err := r.Tags(repo)
if err != nil {
return fmt.Errorf("getting tags for %s failed: %v", repo, err)
}
repos = append(repos, repository{
Name: repo,
Tags: strings.Join(tags, " | "),
RegistryURL: r.Domain,
})
for _, tag := range tags {
// get the manifest
manifest, err := r.Manifest(repo, tag)
if err != nil {
return fmt.Errorf("getting tags for %s:%s failed: %v", repo, tag, err)
}
var createdDate string
if m1, ok := manifest.(schema1.SignedManifest); ok {
history := m1.History
for _, h := range history {
var comp v1Compatibility
if err := json.Unmarshal([]byte(h.V1Compatibility), &comp); err != nil {
return fmt.Errorf("unmarshal v1compatibility failed: %v", err)
}
createdDate = comp.Created.Format(time.RFC1123)
}
}
repos = append(repos, repository{
Name: repo,
Tag: tag,
RegistryURL: r.Domain,
CreatedDate: createdDate,
})
}
}
// create temporoary file to save template to

View file

@ -23,7 +23,7 @@ function prettyDate(time){
function search(search_val){
var suche = search_val.toLowerCase();
var table = document.getElementById("directory");
var cellNr = 1;
var cellNr = 0;
var ele;
for (var r = 1; r < table.rows.length; r++){
ele = table.rows[r].cells[cellNr].innerHTML.replace(/<[^>]+>/g,"");
@ -88,4 +88,4 @@ search_input.addEventListener('keypress', function(e){
clear_button.addEventListener('click', function(e){
search_input.value = '';
search('');
});
});

View file

@ -23,6 +23,7 @@
<tr>
<th>Name</th>
<th>Tags</th>
<th>Created</th>
<th>Pull Command</th>
</tr>
{{ range $key, $value := .Repos }}
@ -31,7 +32,10 @@
{{ $value.Name }}
</td>
<td>
{{ $value.Tags }}
{{ $value.Tag }}
</td>
<td>
{{ $value.CreatedDate }}
</td>
<td align="right" nowrap>
<code>docker pull {{ $value.RegistryURL }}/{{ $value.Name }}</code>