Skip to content

Instantly share code, notes, and snippets.

@bdehamer
Last active August 29, 2015 14:05
Show Gist options
  • Save bdehamer/6af93687716ff9f4fc38 to your computer and use it in GitHub Desktop.
Save bdehamer/6af93687716ff9f4fc38 to your computer and use it in GitHub Desktop.
Format Docker Image Tree for D3.js Library
images = Docker::Image.all(all: 1)
nodes = images.each_with_object({}) do |image, memo|
memo[image.id] = {
id: image.id,
name: image.id[0..11],
parent_id: image.info['ParentId'],
children: []
}
end
nodes.each do |_, node|
next if node[:parent_id] == ''
nodes[node[:parent_id]][:children] << node
end
root = nodes.find do |_, node|
node[:parent_id] == ''
end
respond_with root[1]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment