Generate public homelab architecture diagram
Homelab Main / validate (push) Waiting to run Details
Homelab Main / running-update (push) Blocked by required conditions Details
Homelab Main / debian-ops (push) Blocked by required conditions Details

This commit is contained in:
juvenal.diaz 2026-11-06 19:21:39 -06:00
parent e312d8915e
commit b91218d20e
10 changed files with 330 additions and 199 deletions

View File

@ -26,6 +26,7 @@ jobs:
- name: Validate repository
run: |
set -e
python3 scripts/render-website-architecture.py --check
./jeannie validate
running-update:

View File

@ -38,10 +38,28 @@ the blog page cacheable while preserving the write path through `save_idea.php`.
## Blog content and architecture
The detailed blog diagram is generated from the public model in
`architecture/model.json` and the profile and host inventory in `homelab.yml`.
After changing the architecture, review the model and run:
```sh
python3 scripts/render-website-architecture.py
python3 scripts/render-website-architecture.py --check
```
Commit the model and `architecture/homelab.svg` together. The generator reads
only explicitly referenced inventory values, maps host identifiers to public
labels, and does not include addresses, credentials, or live health. Adding a
profile or changing its runtime requires a model review. CI and `jeannie apps
website` check the generated SVG before deployment. PyYAML is required on
Debian; Ruby's YAML parser is used as a fallback where PyYAML is unavailable.
Graphify remains a code-navigation aid, not an architecture source of truth.
Keep `blog.php`, `homelab-tree.php` and `lang/en.php` aligned with
`homelab.yml` and [the code map](../../docs/code-map.md). The blog distinguishes
the three exclusive cluster profiles and the confirmed native-node readiness
milestone from still-unverified platform/app rollout completion.
milestone from still-unverified platform/app rollout completion. The generated
diagram itself does not report whether any service is currently running.
`lang_helper.php` merges localized strings over the English dictionary. Revised
operational entries currently use that fallback where old Nahuatl translations

View File

@ -0,0 +1,46 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 720" role="img" aria-labelledby="title desc">
<title id="title">Homelab architecture</title>
<desc id="desc">A public overview of delivery, cluster profiles, hosting and operations. Cluster profiles are alternatives, not simultaneous clusters. This diagram describes configuration, not current health.</desc>
<rect width="1200" height="720" rx="18" fill="#f8fafc"/>
<rect x="24" y="24" width="368" height="500" rx="14" fill="#fff" stroke="#cbd5e1"/>
<text x="42" y="58" fill="#102a43" font-size="20" font-weight="700" font-family="sans-serif">Develop and deliver</text>
<rect x="40" y="100" width="336" height="80" rx="9" fill="#f1f5f9" stroke="#cbd5e1"/>
<text x="54" y="130" fill="#102a43" font-size="16" font-weight="700" font-family="sans-serif">Source control</text>
<text x="54" y="155" fill="#334155" font-size="13" font-family="sans-serif">Gitea and GitOps · Debian host</text>
<rect x="40" y="198" width="336" height="80" rx="9" fill="#f1f5f9" stroke="#cbd5e1"/>
<text x="54" y="228" fill="#102a43" font-size="16" font-weight="700" font-family="sans-serif">Operations</text>
<text x="54" y="253" fill="#334155" font-size="13" font-family="sans-serif">Jeannie and OpenTofu</text>
<rect x="40" y="296" width="336" height="80" rx="9" fill="#f1f5f9" stroke="#cbd5e1"/>
<text x="54" y="326" fill="#102a43" font-size="16" font-weight="700" font-family="sans-serif">Build and registry</text>
<text x="54" y="351" fill="#334155" font-size="13" font-family="sans-serif">Container images and policies · Debian host</text>
<rect x="416" y="24" width="368" height="500" rx="14" fill="#fff" stroke="#cbd5e1"/>
<text x="434" y="58" fill="#102a43" font-size="20" font-weight="700" font-family="sans-serif">Cluster profiles</text>
<text x="434" y="82" fill="#52606d" font-size="13" font-family="sans-serif">One profile active at a time</text>
<rect x="432" y="100" width="336" height="80" rx="9" fill="#f1f5f9" stroke="#cbd5e1"/>
<text x="446" y="130" fill="#102a43" font-size="16" font-weight="700" font-family="sans-serif">Hybrid kubeadm</text>
<text x="446" y="155" fill="#334155" font-size="13" font-family="sans-serif">Debian control plane and VM workers</text>
<rect x="432" y="198" width="336" height="80" rx="9" fill="#f1f5f9" stroke="#cbd5e1"/>
<text x="446" y="228" fill="#102a43" font-size="16" font-weight="700" font-family="sans-serif">Pimox kubeadm</text>
<text x="446" y="253" fill="#334155" font-size="13" font-family="sans-serif">Control plane and workers in VMs</text>
<rect x="432" y="296" width="336" height="80" rx="9" fill="#f1f5f9" stroke="#cbd5e1"/>
<text x="446" y="326" fill="#102a43" font-size="16" font-weight="700" font-family="sans-serif">Native K3s</text>
<text x="446" y="351" fill="#334155" font-size="13" font-family="sans-serif">Orange Pi single-node cluster</text>
<rect x="808" y="24" width="368" height="500" rx="14" fill="#fff" stroke="#cbd5e1"/>
<text x="826" y="58" fill="#102a43" font-size="20" font-weight="700" font-family="sans-serif">Services and access</text>
<rect x="824" y="100" width="336" height="80" rx="9" fill="#f1f5f9" stroke="#cbd5e1"/>
<text x="838" y="130" fill="#102a43" font-size="16" font-weight="700" font-family="sans-serif">Public edge</text>
<text x="838" y="155" fill="#334155" font-size="13" font-family="sans-serif">OCI edge and Tailscale</text>
<rect x="824" y="198" width="336" height="80" rx="9" fill="#f1f5f9" stroke="#cbd5e1"/>
<text x="838" y="228" fill="#102a43" font-size="16" font-weight="700" font-family="sans-serif">Cluster workloads</text>
<text x="838" y="253" fill="#334155" font-size="13" font-family="sans-serif">Apps, GitOps and monitoring · Kubernetes</text>
<rect x="824" y="296" width="336" height="80" rx="9" fill="#f1f5f9" stroke="#cbd5e1"/>
<text x="838" y="326" fill="#102a43" font-size="16" font-weight="700" font-family="sans-serif">External services</text>
<text x="838" y="351" fill="#334155" font-size="13" font-family="sans-serif">Dex, Gitea, Matrix and AI · Debian host</text>
<rect x="824" y="394" width="336" height="80" rx="9" fill="#f1f5f9" stroke="#cbd5e1"/>
<text x="838" y="424" fill="#102a43" font-size="16" font-weight="700" font-family="sans-serif">Network services</text>
<text x="838" y="449" fill="#334155" font-size="13" font-family="sans-serif">DNS and monitoring · Raspberry Pi</text>
<text x="42" y="562" fill="#102a43" font-size="18" font-weight="700" font-family="sans-serif">How the pieces connect</text>
<text x="42" y="594" fill="#334155" font-size="15" font-family="sans-serif">Git → build and registry → Argo CD → applications</text>
<text x="42" y="624" fill="#334155" font-size="15" font-family="sans-serif">Visitors → OCI edge → cluster and external services</text>
<text x="42" y="654" fill="#334155" font-size="15" font-family="sans-serif">Jeannie → selected cluster profile → platform and apps</text>
</svg>

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@ -0,0 +1,84 @@
{
"title": "Homelab architecture",
"description": "A public overview of delivery, cluster profiles, hosting and operations. Cluster profiles are alternatives, not simultaneous clusters. This diagram describes configuration, not current health.",
"groups": [
{
"title": "Develop and deliver",
"items": [
{
"title": "Source control",
"detail": "Gitea and GitOps",
"inventory": "services.gitea.host"
},
{
"title": "Operations",
"detail": "Jeannie and OpenTofu"
},
{
"title": "Build and registry",
"detail": "Container images and policies",
"inventory": "services.local_registry.host"
}
]
},
{
"title": "Cluster profiles",
"profile_group": true,
"items": [
{
"title": "Hybrid kubeadm",
"detail": "Debian control plane and VM workers",
"profile": "debian",
"runtime": "kubeadm"
},
{
"title": "Pimox kubeadm",
"detail": "Control plane and workers in VMs",
"profile": "pimox",
"runtime": "kubeadm"
},
{
"title": "Native K3s",
"detail": "Orange Pi single-node cluster",
"profile": "k3s",
"runtime": "k3s"
}
]
},
{
"title": "Services and access",
"items": [
{
"title": "Public edge",
"detail": "OCI edge and Tailscale",
"inventory": "hosts.oci_edge.role"
},
{
"title": "Cluster workloads",
"detail": "Apps, GitOps and monitoring",
"inventory": "services.traefik.host"
},
{
"title": "External services",
"detail": "Dex, Gitea, Matrix and AI",
"inventory": "services.dex.host",
"also_on_same_host": [
"services.gitea.host",
"services.matrix.host",
"services.ollama.host"
]
},
{
"title": "Network services",
"detail": "DNS and monitoring",
"inventory": "services.rpi_dns.host"
}
]
}
],
"flows": [
"Git \u2192 build and registry \u2192 Argo CD \u2192 applications",
"Visitors \u2192 OCI edge \u2192 cluster and external services",
"Jeannie \u2192 selected cluster profile \u2192 platform and apps"
]
}

View File

@ -319,9 +319,9 @@ function renderStackSourceLinks(string $stackKey, array $sourceLinks, string $so
data-en="<?php echo htmlspecialchars($en['blog_arch_title']); ?>">
<?php echo $text['blog_arch_title']; ?>
</h2>
<p data-translate data-key="blog_arch_intro"
data-en="<?php echo htmlspecialchars($en['blog_arch_intro']); ?>">
<?php echo $text['blog_arch_intro']; ?>
<p data-translate data-key="blog_arch_intro_generated"
data-en="<?php echo htmlspecialchars($en['blog_arch_intro_generated']); ?>">
<?php echo $text['blog_arch_intro_generated']; ?>
</p>
</div>
@ -329,198 +329,7 @@ function renderStackSourceLinks(string $stackKey, array $sourceLinks, string $so
<details class="architecture-details">
<summary>Explore the detailed architecture</summary>
<div class="diagram-shell" aria-label="Professional homelab architecture diagram">
<svg class="homelab-map" viewBox="0 0 1120 960" role="img" aria-labelledby="homelab-map-title homelab-map-desc">
<title id="homelab-map-title">Homelab architecture map</title>
<desc id="homelab-map-desc">Debian hosts Gitea, build and recovery tools, and Ollama. Jeannie selects one exclusive Kubernetes profile: laptop kubeadm with Pimox workers, an all-Pimox kubeadm cluster, or native K3s on the Orange Pi. The native Orange Pi node has reported Ready; platform and app rollout completion are separate milestones. Identity, scheduling and retained-storage checks guard deployment. The OCI edge connects through Tailscale, and OpenWrt is available only in VM mode.</desc>
<defs>
<marker id="map-arrow" markerWidth="12" markerHeight="12" refX="10" refY="6" orient="auto">
<path d="M2,2 L10,6 L2,10 Z" fill="#2b6cb0"></path>
</marker>
</defs>
<rect class="diagram-zone diagram-zone-source" x="24" y="40" width="310" height="880" rx="12"></rect>
<text class="diagram-zone-title" x="46" y="74">Source, validation, and images</text>
<rect class="diagram-zone diagram-zone-platform" x="382" y="40" width="340" height="880" rx="12"></rect>
<text class="diagram-zone-title" x="404" y="74">Profiles and deployment guards</text>
<rect class="diagram-zone diagram-zone-runtime" x="770" y="40" width="326" height="880" rx="12"></rect>
<text class="diagram-zone-title" x="792" y="74">Hosts, edge, and workloads</text>
<g class="diagram-node node-accent-blue" transform="translate(54 100)">
<rect width="240" height="74" rx="8"></rect>
<text x="18" y="28">Developer laptop</text>
<text class="diagram-small" x="18" y="52">edit, test, push main</text>
</g>
<g class="diagram-node node-accent-blue" transform="translate(54 208)">
<rect width="240" height="82" rx="8"></rect>
<text x="18" y="27">Gitea repository</text>
<text class="diagram-small" x="18" y="50">https://lab2025.duckdns.org/git/</text>
<text class="diagram-small" x="18" y="68">main is the release branch</text>
</g>
<g class="diagram-node node-accent-teal" transform="translate(54 318)">
<rect width="240" height="82" rx="8"></rect>
<text x="18" y="27">Gitea Actions runner</text>
<text class="diagram-small" x="18" y="50">Debian hosted runner</text>
<text class="diagram-small" x="18" y="68">runs validated deploys</text>
</g>
<g class="diagram-node node-accent-red" transform="translate(54 430)">
<rect width="240" height="82" rx="8"></rect>
<text x="18" y="27">Validation gates</text>
<text class="diagram-small" x="18" y="50">Gitleaks secret scan</text>
<text class="diagram-small" x="18" y="68">Trivy IaC and image posture</text>
</g>
<g class="diagram-node node-accent-green" transform="translate(54 542)">
<rect width="240" height="70" rx="8"></rect>
<text x="18" y="27">Buildx image build</text>
<text class="diagram-small" x="18" y="50">amd64 + arm64 website and demos</text>
</g>
<g class="diagram-node node-accent-purple" transform="translate(412 92)">
<rect width="280" height="82" rx="8"></rect>
<text x="18" y="27">OpenTofu + jeannie</text>
<text class="diagram-small" x="18" y="50">pinned identity and scoped state</text>
<text class="diagram-small" x="18" y="68">runtime and scheduling checks</text>
</g>
<g class="diagram-node node-accent-orange" transform="translate(412 202)">
<rect width="280" height="96" rx="8"></rect>
<text x="18" y="28">VM profile provisioning</text>
<text class="diagram-small" x="18" y="52">dnsmasq TFTP, nginx HTTP</text>
<text class="diagram-small" x="18" y="70">Debian 13 arm64 netboot</text>
<text class="diagram-small" x="18" y="88">skipped for native K3s</text>
</g>
<g class="diagram-node node-accent-blue" transform="translate(412 326)">
<rect width="280" height="82" rx="8"></rect>
<text x="18" y="27">One active cluster profile</text>
<text class="diagram-small" x="18" y="50">debian / pimox / k3s</text>
<text class="diagram-small" x="18" y="68">native K3s or kubeadm topology</text>
</g>
<g class="diagram-node node-accent-teal" transform="translate(412 438)">
<rect width="280" height="82" rx="8"></rect>
<text x="18" y="27">Validated Git revision</text>
<text class="diagram-small" x="18" y="50">validated commit copied locally</text>
<text class="diagram-small" x="18" y="68">Argo reads configured Git repo</text>
</g>
<g class="diagram-node node-accent-green" transform="translate(412 550)">
<rect width="280" height="82" rx="8"></rect>
<text x="18" y="27">GitOps + policy controllers</text>
<text class="diagram-small" x="18" y="50">Argo CD and Kyverno</text>
<text class="diagram-small" x="18" y="68">placement follows live topology</text>
</g>
<g class="diagram-node node-accent-purple" transform="translate(412 662)">
<rect width="280" height="82" rx="8"></rect>
<text x="18" y="27">Monitoring stack</text>
<text class="diagram-small" x="18" y="50">Prometheus, Grafana, Loki</text>
<text class="diagram-small" x="18" y="68">Promtail, node-exporter, KSM</text>
</g>
<g class="diagram-node node-accent-orange" transform="translate(412 774)">
<rect width="280" height="82" rx="8"></rect>
<text x="18" y="27">Storage and backups</text>
<text class="diagram-small" x="18" y="50">OpenEBS retained PVs, n8n data</text>
<text class="diagram-small" x="18" y="68">Gitea dumps, logs, Redis cache</text>
</g>
<g class="diagram-node node-accent-blue" transform="translate(800 92)">
<rect width="258" height="96" rx="8"></rect>
<text x="18" y="28">OCI edge host</text>
<text class="diagram-small" x="18" y="52">nginx, HAProxy, Varnish, Squid</text>
<text class="diagram-small" x="18" y="70">TLS, routing, caching</text>
<text class="diagram-small" x="18" y="88">public DNS entry point</text>
</g>
<g class="diagram-node node-accent-purple" transform="translate(800 218)">
<rect width="258" height="82" rx="8"></rect>
<text x="18" y="27">Tailscale + edge routes</text>
<text class="diagram-small" x="18" y="50">Traefik LAN LoadBalancer</text>
<text class="diagram-small" x="18" y="68">Gitea and API stay on Debian</text>
</g>
<g class="diagram-node node-accent-green" transform="translate(800 330)">
<rect width="258" height="96" rx="8"></rect>
<text x="18" y="28">Debian laptop .73</text>
<text class="diagram-small" x="18" y="52">external Gitea Docker service</text>
<text class="diagram-small" x="18" y="70">Jeannie, builds, AI and backups</text>
<text class="diagram-small" x="18" y="88">Raspberry Pi: DNS and uptime</text>
</g>
<g class="diagram-node node-accent-red" transform="translate(800 466)">
<rect width="258" height="112" rx="8"></rect>
<text x="18" y="28">Orange Pi 5 Plus .80</text>
<text class="diagram-small" x="18" y="52">native K3s: opi5plus Ready</text>
<text class="diagram-small" x="18" y="70">or retained Pimox VMs</text>
<text class="diagram-small" x="18" y="88">never native K3s plus VMs</text>
<text class="diagram-small" x="18" y="106">platform then app readiness</text>
</g>
<g class="diagram-node node-accent-orange" transform="translate(800 616)">
<rect width="258" height="112" rx="8"></rect>
<text x="18" y="28">OpenWrt firewall VM</text>
<text class="diagram-small" x="18" y="52">VM mode only; opt-in</text>
<text class="diagram-small" x="18" y="70">vmbr0 WAN, vmbr1 LAN</text>
<text class="diagram-small" x="18" y="88">simple firewall path</text>
<text class="diagram-small" x="18" y="106">DHCP optional, VLANs later</text>
</g>
<g class="diagram-node node-accent-teal" transform="translate(800 766)">
<rect width="258" height="82" rx="8"></rect>
<text x="18" y="27">Local registry :30500</text>
<text class="diagram-small" x="18" y="50">php-website and demos-static</text>
<text class="diagram-small" x="18" y="68">forward to selected registry node</text>
</g>
<g class="diagram-node node-accent-purple" transform="translate(800 866)">
<rect width="258" height="54" rx="8"></rect>
<text x="18" y="24">Ollama translation API</text>
<text class="diagram-small" x="18" y="44">website-translator on Debian</text>
</g>
<path class="diagram-link" d="M174 174 L174 208"></path>
<path class="diagram-link" d="M174 290 L174 318"></path>
<path class="diagram-link" d="M174 400 L174 430"></path>
<path class="diagram-link" d="M174 512 L174 542"></path>
<path class="diagram-link" d="M294 577 C346 577 352 133 412 133"></path>
<path class="diagram-link" d="M294 577 C372 577 722 807 800 807"></path>
<path class="diagram-link" d="M294 359 C340 359 360 133 412 133"></path>
<path class="diagram-link" d="M294 249 C348 249 360 479 412 479"></path>
<path class="diagram-link" d="M552 174 L552 202"></path>
<path class="diagram-link" d="M552 298 L552 326"></path>
<path class="diagram-link" d="M552 520 L552 550"></path>
<path class="diagram-link" d="M552 632 L552 662"></path>
<path class="diagram-link" d="M552 744 L552 774"></path>
<path class="diagram-link" d="M692 250 C746 250 746 522 800 522"></path>
<path class="diagram-link" d="M692 133 C748 133 748 672 800 672"></path>
<path class="diagram-link" d="M692 591 C748 591 744 378 800 378"></path>
<path class="diagram-link" d="M929 188 L929 218"></path>
<path class="diagram-link" d="M929 300 L929 330"></path>
<path class="diagram-link" d="M929 766 L929 426"></path>
<path class="diagram-link" d="M800 893 C724 893 720 367 692 367"></path>
<text class="diagram-link-label" x="184" y="198">push</text>
<text class="diagram-link-label" x="196" y="312">workflow</text>
<text class="diagram-link-label" x="200" y="424">scan</text>
<text class="diagram-link-label" x="205" y="536">build</text>
<text class="diagram-link-label" x="320" y="124">manual infra</text>
<text class="diagram-link-label" x="344" y="386">validated Git</text>
<text class="diagram-link-label" x="562" y="195">serve boot</text>
<text class="diagram-link-label" x="566" y="320">VM profiles</text>
<text class="diagram-link-label" x="710" y="494">Pimox template</text>
<text class="diagram-link-label" x="710" y="626">firewall VM</text>
<text class="diagram-link-label" x="710" y="420">policy + GitOps</text>
<text class="diagram-link-label" x="934" y="212">secure tunnel</text>
<text class="diagram-link-label" x="934" y="322">service traffic</text>
<text class="diagram-link-label" x="946" y="754">image pulls</text>
<text class="diagram-link-label" x="710" y="860">translation calls</text>
</svg>
<img class="homelab-map" src="<?php echo asset_url('architecture/homelab.svg'); ?>" alt="Homelab architecture: delivery, alternative cluster profiles, public edge, and services. The diagram describes configuration, not live health.">
</div>
</details>

View File

@ -180,6 +180,7 @@ return [
'blog_stack_22' => 'The Pimox profiles preserve the learning path: golden-image preparation, VM lifecycle, big-core pinning, guest readiness, containerd registry trust and recovery. Native K3s offers a simpler runtime on the same Orange Pi without discarding those VM environments.',
'blog_arch_kicker' => 'Architecture map',
'blog_arch_title' => 'The homelab, end to end',
'blog_arch_intro_generated' => 'This diagram shows how source control, deployment, cluster profiles, and services fit together. It describes the intended architecture rather than live availability.',
'blog_arch_intro' => 'Git, builds, AI and recovery stay on Debian. Jeannie selects one of three Kubernetes layouts and checks identity, runtime exclusivity, scheduling and retained storage before changing it. The native Orange Pi K3s node has reported Ready; its platform and application rollout is tracked separately. The OCI edge still reaches services over Tailscale.',
'blog_arch_caption' => 'The three profiles are alternatives, not simultaneous clusters. VM provisioning and OpenWrt belong to VM mode; native K3s uses the Orange Pi host directly. Retained disks and data survive mode changes, but storage moves require an explicit verified copy or restore.',
'blog_arch_fun_link' => 'Open the Christmas-tree version',

View File

@ -22,7 +22,7 @@ names were derived from hubs rather than refreshed with an LLM.
| Native transition | [cluster-transition.py](../scripts/cluster-transition.py), [k3s-stop.sh](../scripts/k3s-stop.sh) | A private phase journal sequences retirement, offline storage copy, bootstrap, independent identity enrollment, platform and apps. |
| Layer orchestration | [pipeline.sh](../lib/jeannie/pipeline.sh) | Applies guards, discovery/adoption, bounded transport retries and readiness checks around OpenTofu and Argo operations. |
| Documentation | [render-docs](../scripts/render-docs), [templates](templates/) | README and modular guides are generated from templates; the service catalog comes from inventory. |
| Blog | [blog.php](../apps/website/blog.php), [English copy](../apps/website/lang/en.php), [Nahuatl copy](../apps/website/lang/nah.php) | The PHP page supplies the diagram and source links; language dictionaries supply narrative copy. |
| Blog | [blog.php](../apps/website/blog.php), [diagram model](../apps/website/architecture/model.json), [generator](../scripts/render-website-architecture.py), [English copy](../apps/website/lang/en.php) | A curated model and inventory generate the public SVG; language dictionaries supply narrative copy. |
## Native transition flow
@ -48,8 +48,9 @@ not completion of every platform or application rollout.
Edit `README.md.tmpl` and `docs/templates/*.md.tmpl`, then run
`scripts/render-docs`. Keep architecture, deployment, app operations and AI
operations in their own guides; duplicated copies previously left contradictory
instructions in the generated documentation. Update blog text and diagram labels
together. Website source changes take effect after the normal image build and
instructions in the generated documentation. Update the diagram model, then run
`python3 scripts/render-website-architecture.py`; CI checks for stale output.
Website source changes take effect after the normal image build and
Argo delivery path; editing PHP does not publish the live site.
Useful local navigation commands:

View File

@ -7965,6 +7965,10 @@ apps() {
require_debian_server "apps"
if [[ "${deploy_website}" == "true" ]]; then
python3 "${REPO_ROOT}/scripts/render-website-architecture.py" --check || return 1
fi
registry_endpoint="$(apps_registry_endpoint)"
demos_registry_endpoint="$(demos_registry_endpoint)"
demos_image_state_file="${REPO_ROOT}/.lab/demos-static-image.state"

View File

@ -0,0 +1,114 @@
#!/usr/bin/env python3
"""Generate the public blog diagram from a curated model and inventory."""
import argparse
import html
import json
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
MODEL = ROOT / 'apps/website/architecture/model.json'
OUTPUT = ROOT / 'apps/website/architecture/homelab.svg'
def inventory():
path = ROOT / 'homelab.yml'
try:
import yaml
except ImportError:
try:
result = subprocess.run(['ruby', '-ryaml', '-rjson', '-e',
'puts JSON.generate(YAML.safe_load_file(ARGV[0]))', str(path)],
capture_output=True, text=True, check=True)
return json.loads(result.stdout)
except (OSError, subprocess.CalledProcessError, json.JSONDecodeError) as exc:
raise ValueError('Install PyYAML to read homelab.yml') from exc
return yaml.safe_load(path.read_text())
def lookup(data, path):
for part in path.split('.'):
if not isinstance(data, dict) or part not in data:
raise ValueError(f'Inventory reference does not exist: {path}')
data = data[part]
return data
def render(model, data):
groups = model['groups']
if len(groups) != 3:
raise ValueError('Diagram requires exactly three groups')
declared_profiles = []
host_labels = {'debian': 'Debian host', 'rpi4': 'Raspberry Pi',
'opi5_pimox': 'Orange Pi host', 'kubernetes': 'Kubernetes'}
for group in groups:
if len(group['items']) > 4:
raise ValueError('Each group can contain at most four items')
for item in group['items']:
if item.get('inventory'):
value = lookup(data, item['inventory'])
if item['inventory'].endswith('.host') and value not in host_labels:
raise ValueError(f'Unknown public host label for {item["inventory"]}; review diagram')
for ref in item.get('also_on_same_host', []):
if lookup(data, ref) != value:
raise ValueError(f'{ref} moved to a different host; review diagram')
if item.get('profile'):
profile = item['profile']
runtime = lookup(data, f'cluster.profiles.{profile}.runtime')
if runtime != item['runtime']:
raise ValueError(f'Profile {profile} runtime changed; review diagram')
declared_profiles.append(profile)
profiles = lookup(data, 'cluster.profiles')
if not isinstance(profiles, dict) or sorted(declared_profiles) != sorted(profiles):
raise ValueError('Cluster profiles changed; review the public architecture model')
esc = lambda value: html.escape(str(value), quote=True)
out = [f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 720" role="img" aria-labelledby="title desc">',
f'<title id="title">{esc(model["title"])}</title>',
f'<desc id="desc">{esc(model["description"])}</desc>',
'<rect width="1200" height="720" rx="18" fill="#f8fafc"/>']
for col, group in enumerate(groups):
x = 24 + col * 392
out += [f'<rect x="{x}" y="24" width="368" height="500" rx="14" fill="#fff" stroke="#cbd5e1"/>',
f'<text x="{x+18}" y="58" fill="#102a43" font-size="20" font-weight="700" font-family="sans-serif">{esc(group["title"])}</text>']
if group.get('profile_group'):
out.append(f'<text x="{x+18}" y="82" fill="#52606d" font-size="13" font-family="sans-serif">One profile active at a time</text>')
for row, item in enumerate(group['items']):
y = 100 + row * 98
ref = item.get('inventory', '')
detail = item['detail']
if ref.endswith('.host'):
detail += ' · ' + host_labels[lookup(data, ref)]
if len(detail) > 45:
raise ValueError(f'Diagram detail is too long: {item["title"]}')
out += [f'<rect x="{x+16}" y="{y}" width="336" height="80" rx="9" fill="#f1f5f9" stroke="#cbd5e1"/>',
f'<text x="{x+30}" y="{y+30}" fill="#102a43" font-size="16" font-weight="700" font-family="sans-serif">{esc(item["title"])}</text>',
f'<text x="{x+30}" y="{y+55}" fill="#334155" font-size="13" font-family="sans-serif">{esc(detail)}</text>']
out.append('<text x="42" y="562" fill="#102a43" font-size="18" font-weight="700" font-family="sans-serif">How the pieces connect</text>')
for i, flow in enumerate(model['flows']):
out.append(f'<text x="42" y="{594+i*30}" fill="#334155" font-size="15" font-family="sans-serif">{esc(flow)}</text>')
out.append('</svg>')
return '\n'.join(out) + '\n'
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--check', action='store_true', help='fail if the committed SVG is stale')
args = parser.parse_args()
try:
content = render(json.loads(MODEL.read_text()), inventory())
if args.check:
if not OUTPUT.exists() or OUTPUT.read_text() != content:
raise ValueError('Architecture SVG is stale; run python3 scripts/render-website-architecture.py')
print('Website architecture diagram is current.')
else:
OUTPUT.write_text(content)
print(f'Wrote {OUTPUT.relative_to(ROOT)}')
except (ValueError, KeyError, TypeError, OSError, json.JSONDecodeError) as exc:
print(f'Architecture diagram: {exc}', file=sys.stderr)
return 1
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@ -0,0 +1,53 @@
"""Checks for the public architecture renderer."""
import copy
import importlib.util
import json
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
SPEC = importlib.util.spec_from_file_location('website_architecture', ROOT / 'scripts/render-website-architecture.py')
renderer = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(renderer)
class WebsiteArchitectureTests(unittest.TestCase):
def setUp(self):
self.model = json.loads(renderer.MODEL.read_text())
self.data = {
'cluster': {'profiles': {'debian': {'runtime': 'kubeadm'},
'pimox': {'runtime': 'kubeadm'},
'k3s': {'runtime': 'k3s'}}},
'hosts': {'oci_edge': {'role': 'public-edge'}},
'services': {'gitea': {'host': 'debian'}, 'local_registry': {'host': 'debian'},
'traefik': {'host': 'kubernetes'}, 'dex': {'host': 'debian'},
'matrix': {'host': 'debian'}, 'ollama': {'host': 'debian'},
'rpi_dns': {'host': 'rpi4'}},
'private_ip': '192.0.2.123',
}
def test_only_public_labels_are_rendered(self):
svg = renderer.render(self.model, self.data)
self.assertNotIn('192.0.2.123', svg)
self.assertIn('Debian host', svg)
updated = copy.deepcopy(self.data)
updated['services']['local_registry']['host'] = 'rpi4'
self.assertNotEqual(svg, renderer.render(self.model, updated))
def test_unmodelled_profile_requires_review(self):
self.data['cluster']['profiles']['new'] = {'runtime': 'k3s'}
with self.assertRaisesRegex(ValueError, 'profiles changed'):
renderer.render(self.model, self.data)
def test_changed_runtime_requires_review(self):
self.data['cluster']['profiles']['k3s']['runtime'] = 'kubeadm'
with self.assertRaisesRegex(ValueError, 'runtime changed'):
renderer.render(self.model, self.data)
def test_model_text_is_xml_escaped(self):
self.model['title'] = '<test & diagram>'
self.assertIn('&lt;test &amp; diagram&gt;', renderer.render(self.model, self.data))
if __name__ == '__main__':
unittest.main()