From d6c2dd419a9ca60e27986811603d8db15a89636b Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Thu, 9 Jan 2025 19:49:06 +0100 Subject: [PATCH] Reduce connections in diagram --- templates/infrastructure.d2.j2 | 49 +++++++++++++++++----------------- visualize.py | 20 +++++++------- 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/templates/infrastructure.d2.j2 b/templates/infrastructure.d2.j2 index 86d5670..0f47193 100644 --- a/templates/infrastructure.d2.j2 +++ b/templates/infrastructure.d2.j2 @@ -15,16 +15,25 @@ external: { } } -{% for host in hosts %} -{{ host.key }}: { -} - -{{ host.key }}.backup -> external.restic { - style: { - stroke: "#0f0" - stroke-dash: 3 +classes: { + zero_grid: { + grid-columns: 3 + grid-gap: 0 + } + monitored: { + style: { + fill: "#1E9025" + } + } + backup: { + style: { + fill: "#0f0" + } } } + +{% for host in hosts %} +{{ host.key }} {% endfor %}{# host #} {% for svc in svcs %} @@ -36,32 +45,25 @@ external: { } {% for backup in svc.backup or [] %} -{{ svc.key }} -> {{ svc.host_key }}.backup: {{ backup.name }} { - style: { - stroke: "#0f0" - stroke-dash: 3 - } -} -{% endfor %}{# backup #} +{{ svc.key }}.'{{ backup.name }}'.class: backup +{% endfor %} {% if svc.monitoring %} -{{ monitoring_key }} -> {{ svc.key }}: { - style.stroke: "#1E9025" -} +{{ svc.key }}.monitored.class: monitored {% endif %} {% if svc.database %} {{ svc.key }} -> {{ db_key }}: { style.stroke: "#336791" } -{{ db_key }}.{{ svc.name }} +{{ db_subkey }}.{{ svc.name }} {% endif %} {% if svc.auth %} {{ svc.key }} -> {{ auth_key }}: { style.stroke: "#FD4B2D" } -{{ auth_key }}.{{ svc.name }} +{{ auth_subkey }}.{{ svc.name }} {% endif %} {% if svc.s3 %} @@ -78,14 +80,11 @@ external.scaleway.s3.{{ svc.name }} {{ svc.key }} -> {{ mail_key }}: { style.stroke: "#C9B81F" } -{{ mail_key }}.{{ svc.name }} +{{ mail_subkey }}.{{ svc.name }} {% endif %} {% endfor %}{# svc #} {% for svc in grid_svcs %} -{{ svc }}: { - grid-columns: 3 - grid-gap: 0 -} +{{ svc }}.class: zero_grid {% endfor %} diff --git a/visualize.py b/visualize.py index 3dc3af7..62c8a43 100755 --- a/visualize.py +++ b/visualize.py @@ -11,6 +11,7 @@ icon_overrides = { "backup": "restic", "dokku": None, "extra_services": None, + "factorio": None, "forgejo_runner": "forgejo", "healthcheck": "healthchecks", "lego": "lets-encrypt", @@ -96,20 +97,21 @@ if __name__ == '__main__': with open('./services.auto.tfvars', 'r') as file: services = hcl2.load(file)["services"][0] - db_key = service_key_find("postgresql", services, hosts) - auth_key = service_key_find("authentik", services, hosts) - monitoring_key = service_key_find("gatus", services, hosts) - mail_key = service_key_find("mailcowdockerized", services, hosts) + keys = {} + keys["db_key"] = service_key_find("postgresql", services, hosts) + keys["db_subkey"] = f"{keys["db_key"]}.dbs" + keys["auth_key"] = service_key_find("authentik", services, hosts) + keys["auth_subkey"] = f"{keys["auth_key"]}.apps" + keys["mail_key"] = service_key_find("mailcowdockerized", services, hosts) + keys["mail_subkey"] = f"{keys["mail_key"]}.mailboxes" + keys["monitoring_key"] = service_key_find("gatus", services, hosts) jinja_loader = jinja2.FileSystemLoader(searchpath="./templates") jinja_env = jinja2.Environment(loader=jinja_loader) template = jinja_env.get_template("infrastructure.d2.j2") print(template.render( - grid_svcs=[db_key, auth_key, mail_key], + grid_svcs=[keys["db_subkey"], keys["auth_subkey"], keys["mail_subkey"]], svcs=parse_services(services, hosts), hosts=parse_hosts(hosts), - db_key=db_key, - auth_key=auth_key, - monitoring_key=monitoring_key, - mail_key=mail_key, + **keys ))