mirror of
https://github.com/Quiq/docker-registry-ui.git
synced 2025-09-04 22:50:43 +00:00
@@ -2,6 +2,7 @@ package registry
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
@@ -32,7 +33,7 @@ func (p timeSlice) Swap(i, j int) {
|
||||
}
|
||||
|
||||
// PurgeOldTags purge old tags.
|
||||
func PurgeOldTags(client *Client, purgeDryRun bool, purgeTagsKeepDays, purgeTagsKeepCount int) {
|
||||
func PurgeOldTags(client *Client, purgeDryRun bool, purgeTagsKeepDays, purgeTagsKeepCount int, purgeTagsKeepRegexp string) {
|
||||
logger := SetupLogging("registry.tasks.PurgeOldTags")
|
||||
dryRunText := ""
|
||||
if purgeDryRun {
|
||||
@@ -83,10 +84,14 @@ func PurgeOldTags(client *Client, purgeDryRun bool, purgeTagsKeepDays, purgeTags
|
||||
sort.Sort(sortedTags)
|
||||
repos[repo] = sortedTags
|
||||
|
||||
// Filter out tags by retention days.
|
||||
// Filter out tags by retention days and regexp
|
||||
for _, tag := range repos[repo] {
|
||||
regexpKeep := false
|
||||
if purgeTagsKeepRegexp != "" {
|
||||
regexpKeep, _ = regexp.MatchString(purgeTagsKeepRegexp, tag.name)
|
||||
}
|
||||
delta := int(now.Sub(tag.created).Hours() / 24)
|
||||
if delta > purgeTagsKeepDays {
|
||||
if !regexpKeep && delta > purgeTagsKeepDays {
|
||||
purgeTags[repo] = append(purgeTags[repo], tag.name)
|
||||
} else {
|
||||
keepTags[repo] = append(keepTags[repo], tag.name)
|
||||
|
Reference in New Issue
Block a user