Code Monkey home page Code Monkey logo

dgr's Introduction

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 me โ†’ no 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/

dgr's People

Contributors

skyzyx avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.