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 negative match for repositories (regexp) #44

Open
wants to merge 1 commit 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: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ We run our own private registry on a server with limited storage and it was only
URL of registry (default "http://localhost:5000")
-repo string
matching repositories (allows regexp) (default ".*")
-nrepo string
matching everything but this repo (allows regexp) (default empty)
-repos int
number of repositories to garbage collect (default 5)
-tag string
Expand Down
18 changes: 16 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
// Base URL of registry
registryURL *string
// Regexps for filtering repositories and tags
repoRegexpStr, tagRegexpStr, negTagRegexpStr *string
repoRegexpStr, negRepoRegexpStr, tagRegexpStr, negTagRegexpStr *string
// Maximum age of image to consider for deletion
day, month, year *int
// Max number of repositories to be fetched from registry
Expand All @@ -47,7 +47,7 @@ var (
ver *bool

// Compiled regexps
repoRegexp, tagRegexp, negTagRegexp *regexp.Regexp
repoRegexp, negRepoRegexp, tagRegexp, negTagRegexp *regexp.Regexp
// Skip insecure TLS
insecure *bool
// Username and password
Expand All @@ -72,6 +72,8 @@ func init() {
year = flag.Int("year", 0, "max age in days")
// Regexp for images (default = .*)
repoRegexpStr = flag.String("repo", ".*", "matching repositories (allows regexp)")
// Negative regexp for images (default = empty)
negRepoRegexpStr = flag.String("nrepo", "", "matching repositories (allows regexp)")
// Regexp for tags (default = .*)
tagRegexpStr = flag.String("tag", ".*", "matching tags (allows regexp)")
// Negative regexp for tags (default = empty)
Expand Down Expand Up @@ -101,6 +103,9 @@ func main() {

// Compile regular expressions
repoRegexp = regexp.MustCompile(*repoRegexpStr)
if *negRepoRegexpStr != "" {
negRepoRegexp = regexp.MustCompile(*negRepoRegexpStr)
}
tagRegexp = regexp.MustCompile(*tagRegexpStr)
if *negTagRegexpStr != "" {
negTagRegexp = regexp.MustCompile(*negTagRegexpStr)
Expand Down Expand Up @@ -165,6 +170,15 @@ func main() {
continue
}

// Check for the negative regexp for repos as well.
if negRepoRegexp != nil {
negRepoMatch := negRepoRegexp.MatchString(entry)
if negRepoMatch {
logger.WithFields(log.Fields{"entry": entry}).Debug("Ignore excluded repository (-nrepo=", *negRepoRegexpStr, ")")
continue
}
}

// Establish repository object in registry
repoName, err := reference.WithName(entry)

Expand Down