mirror of
https://github.com/Quiq/docker-registry-ui.git
synced 2025-09-29 22:38:00 +00:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
c7c3a815fb | ||
|
929daf733f | ||
|
86ee1d56bd | ||
|
d29c24a78f |
10
CHANGELOG.md
10
CHANGELOG.md
@@ -1,12 +1,18 @@
|
||||
## Changelog
|
||||
|
||||
## 0.10.1 (2024-04-19)
|
||||
|
||||
* Rename cmd flag `-purge-from-repos` to `-purge-include-repos` to purge tags only for the specified repositories.
|
||||
* Add a new cmd flag `-purge-exclude-repos` to skip the specified repositories from the tag purging.
|
||||
* Make image column clickable in Event Log.
|
||||
|
||||
### 0.10.0 (2024-04-16)
|
||||
|
||||
**JUST BREAKING CHANGES**
|
||||
|
||||
* We have made a full rewrite. Over 6 years many things have been changed.
|
||||
* Renamed github/dockerhub repo from docker-registry-ui -> registry-ui
|
||||
* Switched from doing raw http calls to github.com/google/go-containerregistry
|
||||
* Switched from doing raw http calls to `github.com/google/go-containerregistry`
|
||||
* URLs and links are now matching the image references, no more "library" or other weird URL parts.
|
||||
* No namespace or only 2-level deep concept
|
||||
* An arbitrary repository levels are supported
|
||||
@@ -18,7 +24,7 @@
|
||||
* Changed format of config.yml but the same concept is preserved
|
||||
* Event listener path has been changed from /api/events to /event-receiver and you may need to update your registry config
|
||||
* Removed built-in cron scheduler for purging tags, please use the normal cron :)
|
||||
* Now you can now tune the refresh of catalog and separately refresh of tag counting, disable them etc.
|
||||
* Now you can tune the refresh of catalog and separately refresh of tag counting, disable them etc.
|
||||
* Everything has been made better! :)
|
||||
|
||||
### 0.9.7 (2024-02-21)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
FROM golang:1.22.1-alpine3.19 as builder
|
||||
FROM golang:1.22.2-alpine3.19 as builder
|
||||
|
||||
RUN apk update && \
|
||||
apk add ca-certificates git bash gcc musl-dev
|
||||
|
2
go.mod
2
go.mod
@@ -21,7 +21,7 @@ require (
|
||||
github.com/containerd/stargz-snapshotter/estargz v0.15.1 // indirect
|
||||
github.com/docker/cli v26.0.0+incompatible // indirect
|
||||
github.com/docker/distribution v2.8.3+incompatible // indirect
|
||||
github.com/docker/docker v26.0.0+incompatible // indirect
|
||||
github.com/docker/docker v26.0.2+incompatible // indirect
|
||||
github.com/docker/docker-credential-helpers v0.8.1 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
|
||||
|
4
go.sum
4
go.sum
@@ -14,8 +14,8 @@ github.com/docker/cli v26.0.0+incompatible h1:90BKrx1a1HKYpSnnBFR6AgDq/FqkHxwlUy
|
||||
github.com/docker/cli v26.0.0+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
|
||||
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
|
||||
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
||||
github.com/docker/docker v26.0.0+incompatible h1:Ng2qi+gdKADUa/VM+6b6YaY2nlZhk/lVJiKR/2bMudU=
|
||||
github.com/docker/docker v26.0.0+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
||||
github.com/docker/docker v26.0.2+incompatible h1:yGVmKUFGgcxA6PXWAokO0sQL22BrQ67cgVjko8tGdXE=
|
||||
github.com/docker/docker v26.0.2+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
||||
github.com/docker/docker-credential-helpers v0.8.1 h1:j/eKUktUltBtMzKqmfLB0PAgqYyMHOp5vfsD1807oKo=
|
||||
github.com/docker/docker-credential-helpers v0.8.1/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
|
7
main.go
7
main.go
@@ -24,15 +24,16 @@ func main() {
|
||||
a apiClient
|
||||
|
||||
configFile, loggingLevel string
|
||||
purgeFromRepos string
|
||||
purgeTags, purgeDryRun bool
|
||||
purgeIncludeRepos, purgeExcludeRepos string
|
||||
)
|
||||
flag.StringVar(&configFile, "config-file", "config.yml", "path to the config file")
|
||||
flag.StringVar(&loggingLevel, "log-level", "info", "logging level")
|
||||
|
||||
flag.BoolVar(&purgeTags, "purge-tags", false, "purge old tags instead of running a web server")
|
||||
flag.BoolVar(&purgeDryRun, "dry-run", false, "dry-run for purging task, does not delete anything")
|
||||
flag.StringVar(&purgeFromRepos, "purge-from-repos", "", "comma-separated list of repos to purge instead of all")
|
||||
flag.StringVar(&purgeIncludeRepos, "purge-include-repos", "", "comma-separated list of repos to purge tags from, otherwise all")
|
||||
flag.StringVar(&purgeExcludeRepos, "purge-exclude-repos", "", "comma-separated list of repos to skip from purging tags, otherwise none")
|
||||
flag.Parse()
|
||||
|
||||
// Setup logging
|
||||
@@ -56,7 +57,7 @@ func main() {
|
||||
|
||||
// Execute CLI task and exit.
|
||||
if purgeTags {
|
||||
registry.PurgeOldTags(a.client, purgeDryRun, purgeFromRepos)
|
||||
registry.PurgeOldTags(a.client, purgeDryRun, purgeIncludeRepos, purgeExcludeRepos)
|
||||
return
|
||||
}
|
||||
|
||||
|
@@ -42,11 +42,20 @@ func (p timeSlice) Swap(i, j int) {
|
||||
}
|
||||
|
||||
// PurgeOldTags purge old tags.
|
||||
func PurgeOldTags(client *Client, purgeDryRun bool, purgeFromRepos string) {
|
||||
func PurgeOldTags(client *Client, purgeDryRun bool, purgeIncludeRepos, purgeExcludeRepos string) {
|
||||
logger := SetupLogging("registry.tasks.PurgeOldTags")
|
||||
keepDays := viper.GetInt("purge_tags.keep_days")
|
||||
keepCount := viper.GetInt("purge_tags.keep_count")
|
||||
keepRegexp := viper.GetString("purge_tags.keep_regexp")
|
||||
keepFromFile := viper.GetString("purge_tags.keep_from_file")
|
||||
|
||||
dryRunText := ""
|
||||
if purgeDryRun {
|
||||
logger.Warn("Dry-run mode enabled.")
|
||||
dryRunText = "skipped"
|
||||
}
|
||||
|
||||
var dataFromFile gjson.Result
|
||||
keepFromFile := viper.GetString("purge_tags.keep_from_file")
|
||||
if keepFromFile != "" {
|
||||
if _, err := os.Stat(keepFromFile); os.IsNotExist(err) {
|
||||
logger.Warnf("Cannot open %s: %s", keepFromFile, err)
|
||||
@@ -62,21 +71,25 @@ func PurgeOldTags(client *Client, purgeDryRun bool, purgeFromRepos string) {
|
||||
dataFromFile = gjson.ParseBytes(data)
|
||||
}
|
||||
|
||||
dryRunText := ""
|
||||
if purgeDryRun {
|
||||
logger.Warn("Dry-run mode enabled.")
|
||||
dryRunText = "skipped"
|
||||
}
|
||||
|
||||
catalog := []string{}
|
||||
if purgeFromRepos != "" {
|
||||
logger.Infof("Working on repositories [%s] to scan their tags and creation dates...", purgeFromRepos)
|
||||
catalog = append(catalog, strings.Split(purgeFromRepos, ",")...)
|
||||
if purgeIncludeRepos != "" {
|
||||
logger.Infof("Including repositories: %s", purgeIncludeRepos)
|
||||
catalog = append(catalog, strings.Split(purgeIncludeRepos, ",")...)
|
||||
} else {
|
||||
logger.Info("Scanning registry for repositories, tags and their creation dates...")
|
||||
client.RefreshCatalog()
|
||||
catalog = client.GetRepos()
|
||||
}
|
||||
if purgeExcludeRepos != "" {
|
||||
logger.Infof("Excluding repositories: %s", purgeExcludeRepos)
|
||||
tmpCatalog := []string{}
|
||||
for _, repo := range catalog {
|
||||
if !ItemInSlice(repo, strings.Split(purgeExcludeRepos, ",")) {
|
||||
tmpCatalog = append(tmpCatalog, repo)
|
||||
}
|
||||
}
|
||||
catalog = tmpCatalog
|
||||
}
|
||||
logger.Infof("Working on repositories: %s", catalog)
|
||||
|
||||
now := time.Now().UTC()
|
||||
repos := map[string]timeSlice{}
|
||||
@@ -91,7 +104,7 @@ func PurgeOldTags(client *Client, purgeDryRun bool, purgeFromRepos string) {
|
||||
imageRef := repo + ":" + tag
|
||||
created := client.GetImageCreated(imageRef)
|
||||
if created.IsZero() {
|
||||
// Image manifest with zero creation time, e.g. cosign one
|
||||
// Image manifest with zero creation time, e.g. cosign w/o --record-creation-timestamp
|
||||
logger.Debugf("[%s] tag with zero creation time: %s", repo, tag)
|
||||
continue
|
||||
}
|
||||
@@ -100,16 +113,12 @@ func PurgeOldTags(client *Client, purgeDryRun bool, purgeFromRepos string) {
|
||||
}
|
||||
|
||||
logger.Infof("Scanned %d repositories.", len(catalog))
|
||||
|
||||
keepDays := viper.GetInt("purge_tags.keep_days")
|
||||
keepCount := viper.GetInt("purge_tags.keep_count")
|
||||
logger.Infof("Filtering out tags for purging: keep %d days, keep count %d", keepDays, keepCount)
|
||||
keepRegexp := viper.GetString("purge_tags.keep_regexp")
|
||||
if keepRegexp != "" {
|
||||
logger.Infof("Keeping tags matching regexp: %s", keepRegexp)
|
||||
}
|
||||
if keepFromFile != "" {
|
||||
logger.Infof("Keeping tags for repos from the file: %+v", dataFromFile)
|
||||
logger.Infof("Keeping tags from file: %+v", dataFromFile)
|
||||
}
|
||||
purgeTags := map[string][]string{}
|
||||
keepTags := map[string][]string{}
|
||||
|
@@ -26,7 +26,7 @@
|
||||
|
||||
<div style="padding: 10px 0; margin-bottom: 20px">
|
||||
<div style="text-align: center; color:darkgrey">
|
||||
Registry UI v{{version}} | <a href="https://quiq.com" target="_blank">Quiq Inc.</a>
|
||||
Registry UI v{{version}} | <a href="https://quiq.com" target="_blank">Quiq Inc.</a> | <a href="https://github.com/Quiq/registry-ui" target="_blank">Github</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -89,7 +89,7 @@
|
||||
{{end}} {* end tags *}
|
||||
|
||||
{{if eventsAllowed and isset(events) }}
|
||||
<h4>Latest activity</h4>
|
||||
<h4>Recent Activity</h4>
|
||||
<table id="datatable_events" class="table table-striped table-bordered">
|
||||
<thead bgcolor="#ddd">
|
||||
<tr>
|
||||
@@ -104,7 +104,7 @@
|
||||
{{range _, e := events}}
|
||||
<tr>
|
||||
<td>{{ e.Action }}</td>
|
||||
{{if hasPrefix(e.Tag,"sha256") }}
|
||||
{{if hasPrefix(e.Tag,"sha256:") }}
|
||||
<td title="{{ e.Tag }}">{{ e.Repository }}@{{ e.Tag[:19] }}...</td>
|
||||
{{else}}
|
||||
<td>{{ e.Repository }}:{{ e.Tag }}</td>
|
||||
|
@@ -72,10 +72,10 @@
|
||||
{{range _, e := events}}
|
||||
<tr>
|
||||
<td>{{ e.Action }}</td>
|
||||
{{if hasPrefix(e.Tag,"sha256") }}
|
||||
<td title="{{ e.Tag }}">{{ e.Repository }}@{{ e.Tag[:19] }}...</td>
|
||||
{{if hasPrefix(e.Tag,"sha256:") }}
|
||||
<td title="{{ e.Tag }}"><a href="{{ basePath }}/{{ e.Repository }}@{{ e.Tag }}">{{ e.Repository }}@{{ e.Tag[:19] }}...</a></td>
|
||||
{{else}}
|
||||
<td>{{ e.Repository }}:{{ e.Tag }}</td>
|
||||
<td><a href="{{ basePath }}/{{ e.Repository }}:{{ e.Tag }}">{{ e.Repository }}:{{ e.Tag }}</a></td>
|
||||
{{end}}
|
||||
<td>{{ e.IP }}</td>
|
||||
<td>{{ e.User }}</td>
|
||||
|
@@ -1,3 +1,3 @@
|
||||
package main
|
||||
|
||||
const version = "0.10.0"
|
||||
const version = "0.10.1"
|
||||
|
Reference in New Issue
Block a user