From c24ae500b4aada3f98b6529399994b3f1a30edfb Mon Sep 17 00:00:00 2001 From: Ivan Ilves Date: Thu, 19 Oct 2017 23:10:02 +0200 Subject: [PATCH] Improve remote speed: First iteration :sunglasses: --- main.go | 4 ++-- main_test.go | 4 ++-- tag/remote/remote.go | 12 ++++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index b47e31e..b502840 100644 --- a/main.go +++ b/main.go @@ -127,7 +127,7 @@ func main() { suicide(err, true) } - remoteTags, err := remote.FetchTags(registry, repoPath, tr.AuthHeader(), o.ConcurrentRequests) + remoteTags, err := remote.FetchTags(registry, repoPath, tr.AuthHeader(), o.ConcurrentRequests, filter) if err != nil { suicide(err, true) } @@ -179,7 +179,7 @@ func main() { suicide(err, true) } - alreadyPushedTags, err := remote.FetchTags(o.PushRegistry, pushRepoPath, tr.AuthHeader(), o.ConcurrentRequests) + alreadyPushedTags, err := remote.FetchTags(o.PushRegistry, pushRepoPath, tr.AuthHeader(), o.ConcurrentRequests, filter) if err != nil { if !strings.Contains(err.Error(), "404 Not Found") { suicide(err, true) diff --git a/main_test.go b/main_test.go index a885508..3a014a5 100644 --- a/main_test.go +++ b/main_test.go @@ -29,7 +29,7 @@ func TestDockerHubWithPublicRepo(t *testing.T) { t.Fatalf("Failed to get DockerHub public repo token: %s", err.Error()) } - tags, err := remote.FetchTags(dockerHub, repo, tr.AuthHeader(), 128) + tags, err := remote.FetchTags(dockerHub, repo, tr.AuthHeader(), 128, ".*") if err != nil { t.Fatalf("Failed to list DockerHub public repo (%s) tags: %s", repo, err.Error()) } @@ -60,7 +60,7 @@ func TestDockerHubWithPrivateRepo(t *testing.T) { t.Fatalf("Failed to get DockerHub private repo token: %s", err.Error()) } - tags, err := remote.FetchTags(dockerHub, repo, tr.AuthHeader(), 128) + tags, err := remote.FetchTags(dockerHub, repo, tr.AuthHeader(), 128, ".*") if err != nil { t.Fatalf("Failed to list DockerHub private repo (%s) tags: %s", repo, err.Error()) } diff --git a/tag/remote/remote.go b/tag/remote/remote.go index 4db7818..2901e5d 100644 --- a/tag/remote/remote.go +++ b/tag/remote/remote.go @@ -15,6 +15,7 @@ import ( "time" "github.com/ivanilves/lstags/tag" + "github.com/ivanilves/lstags/util" ) // WebSchema defines how do we connect to remote web servers @@ -270,17 +271,24 @@ func calculateBatchStepSize(stepNumber, stepsTotal, remain, limit int) int { } // FetchTags looks up Docker repo tags present on remote Docker registry -func FetchTags(registry, repo, authorization string, concurrentRequests int) (map[string]*tag.Tag, error) { +func FetchTags(registry, repo, authorization string, concurrentRequests int, filter string) (map[string]*tag.Tag, error) { batchLimit, err := validateConcurrentRequests(concurrentRequests) if err != nil { return nil, err } - tagNames, err := fetchTagNames(registry, repo, authorization) + allTagNames, err := fetchTagNames(registry, repo, authorization) if err != nil { return nil, err } + tagNames := make([]string, 0) + for _, tagName := range allTagNames { + if util.DoesMatch(tagName, filter) { + tagNames = append(tagNames, tagName) + } + } + tags := make(map[string]*tag.Tag) batchSteps, batchRemain := calculateBatchSteps(len(tagNames), batchLimit)