From 9c73934382a13ec065321c5f15488e246e4f56b6 Mon Sep 17 00:00:00 2001 From: Roman Vynar Date: Tue, 6 Mar 2018 22:23:52 +0200 Subject: [PATCH] Natural sorting of tags, add last 5 event to tags page. --- main.go | 4 ++-- registry/event_listener.go | 8 ++++++-- registry/tasks.go | 2 +- templates/event_log.html | 2 +- templates/tag_info.html | 2 +- templates/tags.html | 37 ++++++++++++++++++++++++++++++++++++- 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 5699246..bba617a 100644 --- a/main.go +++ b/main.go @@ -185,6 +185,7 @@ func (a *apiClient) viewTags(c echo.Context) error { data.Set("repo", repo) data.Set("tags", tags) data.Set("deleteAllowed", deleteAllowed) + data.Set("events", registry.GetEvents(repo)) return c.Render(http.StatusOK, "tags.html", data) } @@ -279,9 +280,8 @@ func (a *apiClient) checkDeletePermission(user string) bool { // viewLog view events from sqlite. func (a *apiClient) viewLog(c echo.Context) error { - events := registry.GetEvents() data := jet.VarMap{} - data.Set("events", events) + data.Set("events", registry.GetEvents("")) return c.Render(http.StatusOK, "event_log.html", data) } diff --git a/registry/event_listener.go b/registry/event_listener.go index 7627039..20c59ba 100644 --- a/registry/event_listener.go +++ b/registry/event_listener.go @@ -103,7 +103,7 @@ func ProcessEvents(request *http.Request, retention int) { } // GetEvents retrieve events from sqlite db -func GetEvents() []EventRow { +func GetEvents(repository string) []EventRow { var events []EventRow db, err := sql.Open("sqlite3", dbFile) if err != nil { @@ -112,7 +112,11 @@ func GetEvents() []EventRow { } defer db.Close() - rows, err := db.Query("SELECT * FROM events ORDER BY id DESC LIMIT 1000") + query := "SELECT * FROM events ORDER BY id DESC LIMIT 1000" + if repository != "" { + query = fmt.Sprintf("SELECT * FROM events WHERE repository='%s' ORDER BY id DESC LIMIT 5", repository) + } + rows, err := db.Query(query) if err != nil { logger.Error("Error selecting from table: ", err) return events diff --git a/registry/tasks.go b/registry/tasks.go index 0656e02..378f278 100644 --- a/registry/tasks.go +++ b/registry/tasks.go @@ -64,7 +64,7 @@ func PurgeOldTags(client *Client, purgeDryRun bool, purgeTagsKeepDays, purgeTags for _, tag := range tags { _, infoV1, _ := client.TagInfo(repo, tag, true) if infoV1 == "" { - logger.Errorf("[%s] manifest missed for tag %s", repo, tag) + logger.Errorf("[%s] missing manifest v1 for tag %s", repo, tag) continue } created := gjson.Get(gjson.Get(infoV1, "history.0.v1Compatibility").String(), "created").Time() diff --git a/templates/event_log.html b/templates/event_log.html index c01d9bd..82da955 100644 --- a/templates/event_log.html +++ b/templates/event_log.html @@ -33,7 +33,7 @@ {{ e.Action }} {{if hasPrefix(e.Tag,"sha256") }} - {{ e.Repository }}@{{ e.Tag[:12] }}.....{{ e.Tag[66:] }} + {{ e.Repository }}@{{ e.Tag[:19] }}... {{else}} {{ e.Repository }}:{{ e.Tag }} {{end}} diff --git a/templates/tag_info.html b/templates/tag_info.html index 299c111..e9b7cfa 100644 --- a/templates/tag_info.html +++ b/templates/tag_info.html @@ -11,7 +11,7 @@
  • {{ repo }}
  • {{ tag }}
  • - +
    diff --git a/templates/tags.html b/templates/tags.html index 6cc628f..dbeb8a7 100644 --- a/templates/tags.html +++ b/templates/tags.html @@ -2,12 +2,16 @@ {{block head()}} + {{end}} @@ -49,4 +55,33 @@ {{end}}
    Image Details
    + +

    Latest events on this repo

    + + + + + + + + + + + + {{range e := events}} + + + {{if hasPrefix(e.Tag,"sha256") }} + + {{else}} + + {{end}} + + + + + {{end}} + +
    ActionImageIP AddressUserTime
    {{ e.Action }}{{ e.Repository }}@{{ e.Tag[:19] }}...{{ e.Repository }}:{{ e.Tag }}{{ e.IP }}{{ e.User }}{{ e.Created }}
    + {{end}}