Skip to content

Commit

Permalink
Improve remote speed: First iteration 😎
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanilves committed Oct 19, 2017
1 parent 482adcd commit c24ae50
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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())
}
Expand Down
12 changes: 10 additions & 2 deletions tag/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c24ae50

Please sign in to comment.