{"id":17962114,"url":"https://github.com/skyzyx/dgr","last_synced_at":"2025-04-03T18:44:19.026Z","repository":{"id":57571357,"uuid":"347844862","full_name":"skyzyx/dgr","owner":"skyzyx","description":"Sort Graphviz digraph nodes in the order specified by their edges.","archived":false,"fork":false,"pushed_at":"2021-03-15T06:10:13.000Z","size":16,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-01T18:15:20.758Z","etag":null,"topics":["dag","directed-acyclic-graph","directed-graph","directed-graphs","directedgraph","dot","edges","go","golang","graph","graphviz","graphviz-dot","graphviz-dot-language","nodes","terraform","terragrunt","xkcd"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skyzyx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-15T05:13:07.000Z","updated_at":"2021-04-07T08:46:46.000Z","dependencies_parsed_at":"2022-09-26T16:40:31.747Z","dependency_job_id":null,"html_url":"https://github.com/skyzyx/dgr","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyzyx%2Fdgr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyzyx%2Fdgr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyzyx%2Fdgr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyzyx%2Fdgr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skyzyx","download_url":"https://codeload.github.com/skyzyx/dgr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247061147,"owners_count":20877165,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dag","directed-acyclic-graph","directed-graph","directed-graphs","directedgraph","dot","edges","go","golang","graph","graphviz","graphviz-dot","graphviz-dot-language","nodes","terraform","terragrunt","xkcd"],"created_at":"2024-10-29T11:14:01.479Z","updated_at":"2025-04-03T18:44:19.003Z","avatar_url":"https://github.com/skyzyx.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dgr\n\nShort for _directed graph_.\n\nTakes a DOT-formatted `digraph` where dependencies are expressed as `dependent -\u003e dependency`, determines the order in which they need to occur, and sorts the dependencies by earlier-to-later resolution.\n\nWith 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.\n\n## Install\n\nAssuming you have the [Go toolchain](https://golang.org/doc/install) set up, run:\n\n```bash\ngo get github.com/skyzyx/dgr\n```\n\n## Usage\n\n```bash\nterragrunt graph-dependencies | dgr\n```\n\n## Use-case\n\nMy 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](https://terragrunt.gruntwork.io/docs/features/keep-your-terraform-code-dry/), and Terragrunt knows how to track that.\n\nBy running `terragrunt graph-dependencies`, you can get Graphviz (DOT) data which looks something like this:\n\n```dot\ndigraph {\n\t\"ecs-cluster\" ;\n\t\"resource-tags\" ;\n\t\"public-dns\" ;\n\t\"certificate\" ;\n\t\"database\" ;\n\n\t\"ecs-cluster\" -\u003e \"resource-tags\";\n\t\"ecs-cluster\" -\u003e \"database\";\n\t\"database\" -\u003e \"resource-tags\";\n\t\"public-dns\" -\u003e \"ecs-cluster\";\n\t\"certificate\" -\u003e \"public-dns\";\n}\n```\n\nBy 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_.\n\nIf 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.\n\nWhat 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.\n\n## Generic use\n\nI'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`.\n\nNote 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](https://tylercipriani.com/blog/2017/09/13/topographical-sorting-in-golang/) to [walk me though](https://github.com/philopon/go-toposort/blob/master/toposort.go) the [algorithm(s) first](https://github.com/stevenle/topsort/blob/master/topsort.go).\n\n\u003chttps://xkcd.wtf/1988/\u003e\n\n  [Terragrunt]: https://terragrunt.gruntwork.io\n  [Terraform]: https://terraform.io\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskyzyx%2Fdgr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskyzyx%2Fdgr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskyzyx%2Fdgr/lists"}