Reduce connections in diagram

This commit is contained in:
Tobias Reisinger 2025-01-09 19:49:06 +01:00
parent 4608081fba
commit d6c2dd419a
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
2 changed files with 35 additions and 34 deletions

View file

@ -15,16 +15,25 @@ external: {
} }
} }
{% for host in hosts %} classes: {
{{ host.key }}: { zero_grid: {
} grid-columns: 3
grid-gap: 0
{{ host.key }}.backup -> external.restic { }
style: { monitored: {
stroke: "#0f0" style: {
stroke-dash: 3 fill: "#1E9025"
}
}
backup: {
style: {
fill: "#0f0"
}
} }
} }
{% for host in hosts %}
{{ host.key }}
{% endfor %}{# host #} {% endfor %}{# host #}
{% for svc in svcs %} {% for svc in svcs %}
@ -36,32 +45,25 @@ external: {
} }
{% for backup in svc.backup or [] %} {% for backup in svc.backup or [] %}
{{ svc.key }} -> {{ svc.host_key }}.backup: {{ backup.name }} { {{ svc.key }}.'{{ backup.name }}'.class: backup
style: { {% endfor %}
stroke: "#0f0"
stroke-dash: 3
}
}
{% endfor %}{# backup #}
{% if svc.monitoring %} {% if svc.monitoring %}
{{ monitoring_key }} -> {{ svc.key }}: { {{ svc.key }}.monitored.class: monitored
style.stroke: "#1E9025"
}
{% endif %} {% endif %}
{% if svc.database %} {% if svc.database %}
{{ svc.key }} -> {{ db_key }}: { {{ svc.key }} -> {{ db_key }}: {
style.stroke: "#336791" style.stroke: "#336791"
} }
{{ db_key }}.{{ svc.name }} {{ db_subkey }}.{{ svc.name }}
{% endif %} {% endif %}
{% if svc.auth %} {% if svc.auth %}
{{ svc.key }} -> {{ auth_key }}: { {{ svc.key }} -> {{ auth_key }}: {
style.stroke: "#FD4B2D" style.stroke: "#FD4B2D"
} }
{{ auth_key }}.{{ svc.name }} {{ auth_subkey }}.{{ svc.name }}
{% endif %} {% endif %}
{% if svc.s3 %} {% if svc.s3 %}
@ -78,14 +80,11 @@ external.scaleway.s3.{{ svc.name }}
{{ svc.key }} -> {{ mail_key }}: { {{ svc.key }} -> {{ mail_key }}: {
style.stroke: "#C9B81F" style.stroke: "#C9B81F"
} }
{{ mail_key }}.{{ svc.name }} {{ mail_subkey }}.{{ svc.name }}
{% endif %} {% endif %}
{% endfor %}{# svc #} {% endfor %}{# svc #}
{% for svc in grid_svcs %} {% for svc in grid_svcs %}
{{ svc }}: { {{ svc }}.class: zero_grid
grid-columns: 3
grid-gap: 0
}
{% endfor %} {% endfor %}

View file

@ -11,6 +11,7 @@ icon_overrides = {
"backup": "restic", "backup": "restic",
"dokku": None, "dokku": None,
"extra_services": None, "extra_services": None,
"factorio": None,
"forgejo_runner": "forgejo", "forgejo_runner": "forgejo",
"healthcheck": "healthchecks", "healthcheck": "healthchecks",
"lego": "lets-encrypt", "lego": "lets-encrypt",
@ -96,20 +97,21 @@ if __name__ == '__main__':
with open('./services.auto.tfvars', 'r') as file: with open('./services.auto.tfvars', 'r') as file:
services = hcl2.load(file)["services"][0] services = hcl2.load(file)["services"][0]
db_key = service_key_find("postgresql", services, hosts) keys = {}
auth_key = service_key_find("authentik", services, hosts) keys["db_key"] = service_key_find("postgresql", services, hosts)
monitoring_key = service_key_find("gatus", services, hosts) keys["db_subkey"] = f"{keys["db_key"]}.dbs"
mail_key = service_key_find("mailcowdockerized", services, hosts) 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_loader = jinja2.FileSystemLoader(searchpath="./templates")
jinja_env = jinja2.Environment(loader=jinja_loader) jinja_env = jinja2.Environment(loader=jinja_loader)
template = jinja_env.get_template("infrastructure.d2.j2") template = jinja_env.get_template("infrastructure.d2.j2")
print(template.render( 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), svcs=parse_services(services, hosts),
hosts=parse_hosts(hosts), hosts=parse_hosts(hosts),
db_key=db_key, **keys
auth_key=auth_key,
monitoring_key=monitoring_key,
mail_key=mail_key,
)) ))