Skip to content

Instantly share code, notes, and snippets.

@jcarley
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcarley/fe6a68e8f0e56b002d37 to your computer and use it in GitHub Desktop.
Save jcarley/fe6a68e8f0e56b002d37 to your computer and use it in GitHub Desktop.
Tsorting docker json files
#!/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