Skip to content

Commit

Permalink
Merge pull request #32 from infosiftr/shared-tags-children
Browse files Browse the repository at this point in the history
Fix edge case of children for images that are FROM a SharedTag
  • Loading branch information
tianon authored Aug 16, 2021
2 parents 7d4279f + 16fb204 commit 4c95a9e
Showing 1 changed file with 62 additions and 50 deletions.
112 changes: 62 additions & 50 deletions cmd/bashbrew/cmd-deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,63 +100,75 @@ func cmdFamily(parents bool, c *cli.Context) error {
// now the real work
seen := map[string]bool{}
for _, repo := range depsRepos {
r, err := fetch(repo)
if err != nil {
return cli.NewMultiError(fmt.Errorf(`failed fetching repo %q`, repo), err)
}
tagsToConsider := []string{}

for _, entry := range r.Entries() {
if applyConstraints && r.SkipConstraints(entry) {
continue
if r, err := fetch(repo); err == nil {
// fetch succeeded, must be an object we know about so let's do a proper listing/search
for _, entry := range r.Entries() {
if applyConstraints && r.SkipConstraints(entry) {
continue
}
if archFilter && !entry.HasArchitecture(arch) {
continue
}

if len(r.TagEntries) == 1 {
// we can't include SharedTags here or else they'll make "bashbrew parents something:simple" show the parents of the shared tags too ("nats:scratch" leading to both "nats:alpine" *and* "nats:windowsservercore" instead of just "nats:alpine" like it should), so we have to reimplement bits of "r.Tags" to exclude them
tagRepo := path.Join(namespace, r.RepoName)
for _, rawTag := range entry.Tags {
tag := tagRepo + ":" + rawTag
tagsToConsider = append(tagsToConsider, tag)
}
} else {
// if we're doing something like "bashbrew children full-repo" (or "bashbrew children full-repo:shared-tag"), we *need* to include the SharedTags or else things that are "FROM full-repo:shared-tag" won't show up 😅 ("bashbrew children adoptopenjdk" was just "cassandra" instead of the full list)
tagsToConsider = append(tagsToConsider, r.Tags(namespace, false, entry)...)
}
}
if archFilter && !entry.HasArchitecture(arch) {
continue
} else {
if err != nil {
return cli.NewMultiError(fmt.Errorf(`failed fetching repo %q`, repo), err)
}
}

// we can't include SharedTags here or else they'll make "bashbrew parents something:simple" show the parents of the shared tags too ("nats:scratch" leading to both "nats:alpine" *and* "nats:windowsservercore" instead of just "nats:alpine" like it should), so we have to reimplement bits of "r.Tags" to exclude them
tagRepo := path.Join(namespace, r.RepoName)
for _, rawTag := range entry.Tags {
tag := tagRepo + ":" + rawTag

nodes := []topsortDepthNodes{}
if parents {
nodes = append(nodes, topsortDepthNodes{
depth: 1,
nodes: network.Get(tag).InboundEdges,
})
} else {
nodes = append(nodes, topsortDepthNodes{
depth: 1,
nodes: network.Get(tag).OutboundEdges,
})
for _, tag := range tagsToConsider {
nodes := []topsortDepthNodes{}
if parents {
nodes = append(nodes, topsortDepthNodes{
depth: 1,
nodes: network.Get(tag).InboundEdges,
})
} else {
nodes = append(nodes, topsortDepthNodes{
depth: 1,
nodes: network.Get(tag).OutboundEdges,
})
}
for len(nodes) > 0 {
depthNodes := nodes[0]
nodes = nodes[1:]
if depth > 0 && depthNodes.depth > depth {
continue
}
for len(nodes) > 0 {
depthNodes := nodes[0]
nodes = nodes[1:]
if depth > 0 && depthNodes.depth > depth {
for _, node := range depthNodes.nodes {
seenKey := node.Name
if uniq {
seenKey = seenKey[:strings.Index(seenKey, ":")+1] + node.Value.(*manifest.Manifest2822Entry).Tags[0]
}
if seen[seenKey] {
continue
}
for _, node := range depthNodes.nodes {
seenKey := node.Name
if uniq {
seenKey = seenKey[:strings.Index(seenKey, ":")+1] + node.Value.(*manifest.Manifest2822Entry).Tags[0]
}
if seen[seenKey] {
continue
}
seen[seenKey] = true
fmt.Printf("%s\n", seenKey)
if parents {
nodes = append(nodes, topsortDepthNodes{
depth: depthNodes.depth + 1,
nodes: node.InboundEdges,
})
} else {
nodes = append(nodes, topsortDepthNodes{
depth: depthNodes.depth + 1,
nodes: node.OutboundEdges,
})
}
seen[seenKey] = true
fmt.Printf("%s\n", seenKey)
if parents {
nodes = append(nodes, topsortDepthNodes{
depth: depthNodes.depth + 1,
nodes: node.InboundEdges,
})
} else {
nodes = append(nodes, topsortDepthNodes{
depth: depthNodes.depth + 1,
nodes: node.OutboundEdges,
})
}
}
}
Expand Down

0 comments on commit 4c95a9e

Please sign in to comment.