Last active
August 29, 2015 14:22
-
-
Save jcarley/fe6a68e8f0e56b002d37 to your computer and use it in GitHub Desktop.
Tsorting docker json files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'json' | |
require 'tsort' | |
class Hash | |
include TSort | |
alias tsort_each_node each_key | |
def tsort_each_child(node, &block) | |
fetch(node).each(&block) | |
end | |
end | |
@layers = {} | |
@images = {} | |
Dir.glob("./files/rmq/*/json") do |filename| | |
json = File.open(filename, "r") | |
hash = JSON.parse(json.read, :symbolize_names => true) | |
@layers[hash[:id]] = hash[:parent] ? [hash[:parent]] : [] | |
@images[hash[:id]] = hash | |
end | |
@sorted_list = @layers.tsort | |
@sorted_list.each do |id| | |
puts "" | |
command = @images[id][:container_config][:Cmd] | |
puts command.join(' ') unless command.nil? | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment