From 8d6444a1af3d18fd8693c4330cf996ee603ea355 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Fri, 6 Sep 2019 17:42:50 -0700 Subject: [PATCH] Adjust "bashbrew" namespace sorting to account for more edge cases In particular, our namespace changes made `bashbrew list --build-order wordpress php` work properly but `bashbrew --namespace amd64 list --build-order wordpress php` does not -- these changes adjust our sorting to take into account both the namespaced and the non-namespaced version of each tag in our library when checking the `FROM` values for sorting purposes. --- go/src/bashbrew/sort.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/go/src/bashbrew/sort.go b/go/src/bashbrew/sort.go index 006ade7..75b2d14 100644 --- a/go/src/bashbrew/sort.go +++ b/go/src/bashbrew/sort.go @@ -79,7 +79,12 @@ func sortRepoObjects(rs []*Repo, applyConstraints bool) ([]*Repo, error) { for _, r := range rs { node := r.Identifier() for _, entry := range r.Entries() { - for _, tag := range r.Tags(namespace, false, entry) { + // add edges both with and without namespace so sorting still works properly for official images ("bashbrew --namespace amd64 list --build-order wordpress php") + // this should be reasonably harmless for other use cases of --namespace but catches things like "tianon/foo -> tianon/bar" and things like "php -> wordpress" equally even if we're building to target a different namespace + tags := []string{} + tags = append(tags, r.Tags("", false, entry)...) + tags = append(tags, r.Tags(namespace, false, entry)...) + for _, tag := range tags { if canonicalRepo, ok := canonicalRepos[tag]; ok && canonicalRepo.TagName != "" { // if we run into a duplicate, we want to prefer a specific tag over a full repo continue