dgr

command module
v0.0.0-...-167e3e1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2021 License: MIT Imports: 9 Imported by: 0

README

dgr

Short for directed graph.

Takes a DOT-formatted digraph where dependencies are expressed as dependent -> dependency, determines the order in which they need to occur, and sorts the dependencies by earlier-to-later resolution.

With the -node parameter, you can specify one of the nodes in the graph, and this will display the list of dependencies beginning with the node you specified. The intended use-case is to assume that node's dependencies are met, so just perform the work for that node and everything which depends on it.

Install

Assuming you have the Go toolchain set up, run:

go get github.com/skyzyx/dgr

Usage

terragrunt graph-dependencies | dgr

Use-case

My specific use-case is using Terragrunt to break apart monolithic Terraform into smaller, discrete units. (There's no need for an update to a Lambda function to execute the same monolithic Terraform as what powers my database.) These units can depend on each other, and Terragrunt knows how to track that.

By running terragrunt graph-dependencies, you can get Graphviz (DOT) data which looks something like this:

digraph {
	"ecs-cluster" ;
	"resource-tags" ;
	"public-dns" ;
	"certificate" ;
	"database" ;

	"ecs-cluster" -> "resource-tags";
	"ecs-cluster" -> "database";
	"database" -> "resource-tags";
	"public-dns" -> "ecs-cluster";
	"certificate" -> "public-dns";
}

By piping that data into dgr, it will read the directed acyclic graph (DAG) and sort the nodes in dependency order from lots of things depend on meno things depend on me.

If you pass the name of one of the nodes to the -node flag, it will give you a shorter version of the list starting with that node.

What this means is that if there is an update to one of my discrete units of Terraform (managed by Terragrunt), and I have other units which depend on that unit downstream, this will give me a list of the units which need to be re-applied in order for the changes to apply cleanly all the way through the stack.

Generic use

I've tried to follow the Unix philosophy of doing one thing well, and supporting the ability to pipe things from one process to the next. I haven't broadly tested this (nor will I), but it should be able to sort nodes by their edges for any Graphviz-formatted digraph.

Note that I have little idea how this graph stuff works. I've picked up a little here and there, but I don't understand it well enough to know how to implement it myself (sorry technical recruiters). I have an interest in learning, but I'd need someone to walk me though the algorithm(s) first.

https://xkcd.wtf/1988/

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL