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

Fix edge case of children for images that are FROM a SharedTag #32

Merged
merged 1 commit into from
Aug 16, 2021
Merged
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
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