Created
May 29, 2019 05:51
-
-
Save fujiwara/e0d891c0c1020c9769deeb259738486d to your computer and use it in GitHub Desktop.
Visualize container dependencies from ECS task definition JSON.
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 perl | |
use 5.12.1; | |
use warnings; | |
use JSON::PP; | |
my $file = shift; | |
open my $in, "<", $file or die $!; | |
my $taskdef = JSON::PP::decode_json(do { local $/ = undef; <$in> }); | |
my $g = $file; | |
$g =~ s/[^\w]/_/g; | |
say "digraph $g {"; | |
for my $c (@{$taskdef->{taskDefinition}->{containerDefinitions}}) { | |
my $name = $c->{name}; | |
for my $dep (@{$c->{dependsOn}}) { | |
printf qq{ %s -> %s [label = "%s"];\n}, | |
$name, $dep->{containerName}, $dep->{condition}; | |
} | |
} | |
say "}"; |
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' | |
file = ARGV[0] | |
taskdef = open(file) do |f| | |
JSON.load(f) | |
end | |
gname = file.gsub(/[^\w]/, '_') | |
puts "digraph #{gname} {" | |
taskdef['taskDefinition']['containerDefinitions'].each do |c| | |
name = c['name'] | |
c['dependsOn']&.each do |dep| | |
puts " #{name} -> #{dep['containerName']} [label = \"#{dep['condition']}\"];" | |
end | |
end | |
puts '}' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment