From b91218d20e929ee3c24ccf3914684f2470345945 Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Fri, 6 Nov 2026 19:21:39 -0600 Subject: [PATCH] Generate public homelab architecture diagram --- .gitea/workflows/homelab-main.yml | 1 + apps/website/README.md | 20 ++- apps/website/architecture/homelab.svg | 46 +++++ apps/website/architecture/model.json | 84 +++++++++ apps/website/blog.php | 199 +-------------------- apps/website/lang/en.php | 1 + docs/code-map.md | 7 +- lib/jeannie/pipeline.sh | 4 + scripts/render-website-architecture.py | 114 ++++++++++++ tests/jeannie/test_website_architecture.py | 53 ++++++ 10 files changed, 330 insertions(+), 199 deletions(-) create mode 100644 apps/website/architecture/homelab.svg create mode 100644 apps/website/architecture/model.json create mode 100644 scripts/render-website-architecture.py create mode 100644 tests/jeannie/test_website_architecture.py diff --git a/.gitea/workflows/homelab-main.yml b/.gitea/workflows/homelab-main.yml index 70f5e35..6ca2cc5 100644 --- a/.gitea/workflows/homelab-main.yml +++ b/.gitea/workflows/homelab-main.yml @@ -26,6 +26,7 @@ jobs: - name: Validate repository run: | set -e + python3 scripts/render-website-architecture.py --check ./jeannie validate running-update: diff --git a/apps/website/README.md b/apps/website/README.md index 57119a5..c911803 100644 --- a/apps/website/README.md +++ b/apps/website/README.md @@ -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 diff --git a/apps/website/architecture/homelab.svg b/apps/website/architecture/homelab.svg new file mode 100644 index 0000000..2533e53 --- /dev/null +++ b/apps/website/architecture/homelab.svg @@ -0,0 +1,46 @@ + +Homelab architecture +A public overview of delivery, cluster profiles, hosting and operations. Cluster profiles are alternatives, not simultaneous clusters. This diagram describes configuration, not current health. + + +Develop and deliver + +Source control +Gitea and GitOps · Debian host + +Operations +Jeannie and OpenTofu + +Build and registry +Container images and policies · Debian host + +Cluster profiles +One profile active at a time + +Hybrid kubeadm +Debian control plane and VM workers + +Pimox kubeadm +Control plane and workers in VMs + +Native K3s +Orange Pi single-node cluster + +Services and access + +Public edge +OCI edge and Tailscale + +Cluster workloads +Apps, GitOps and monitoring · Kubernetes + +External services +Dex, Gitea, Matrix and AI · Debian host + +Network services +DNS and monitoring · Raspberry Pi +How the pieces connect +Git → build and registry → Argo CD → applications +Visitors → OCI edge → cluster and external services +Jeannie → selected cluster profile → platform and apps + diff --git a/apps/website/architecture/model.json b/apps/website/architecture/model.json new file mode 100644 index 0000000..43cd5fc --- /dev/null +++ b/apps/website/architecture/model.json @@ -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" + ] +} diff --git a/apps/website/blog.php b/apps/website/blog.php index 78695b1..bd625c7 100644 --- a/apps/website/blog.php +++ b/apps/website/blog.php @@ -319,9 +319,9 @@ function renderStackSourceLinks(string $stackKey, array $sourceLinks, string $so data-en=""> -

- +

+

@@ -329,198 +329,7 @@ function renderStackSourceLinks(string $stackKey, array $sourceLinks, string $so
Explore the detailed architecture
- - Homelab architecture map - 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. - - - - - - - - Source, validation, and images - - - Profiles and deployment guards - - - Hosts, edge, and workloads - - - - Developer laptop - edit, test, push main - - - - - Gitea repository - https://lab2025.duckdns.org/git/ - main is the release branch - - - - - Gitea Actions runner - Debian hosted runner - runs validated deploys - - - - - Validation gates - Gitleaks secret scan - Trivy IaC and image posture - - - - - Buildx image build - amd64 + arm64 website and demos - - - - - OpenTofu + jeannie - pinned identity and scoped state - runtime and scheduling checks - - - - - VM profile provisioning - dnsmasq TFTP, nginx HTTP - Debian 13 arm64 netboot - skipped for native K3s - - - - - One active cluster profile - debian / pimox / k3s - native K3s or kubeadm topology - - - - - Validated Git revision - validated commit copied locally - Argo reads configured Git repo - - - - - GitOps + policy controllers - Argo CD and Kyverno - placement follows live topology - - - - - Monitoring stack - Prometheus, Grafana, Loki - Promtail, node-exporter, KSM - - - - - Storage and backups - OpenEBS retained PVs, n8n data - Gitea dumps, logs, Redis cache - - - - - OCI edge host - nginx, HAProxy, Varnish, Squid - TLS, routing, caching - public DNS entry point - - - - - Tailscale + edge routes - Traefik LAN LoadBalancer - Gitea and API stay on Debian - - - - - Debian laptop .73 - external Gitea Docker service - Jeannie, builds, AI and backups - Raspberry Pi: DNS and uptime - - - - - Orange Pi 5 Plus .80 - native K3s: opi5plus Ready - or retained Pimox VMs - never native K3s plus VMs - platform then app readiness - - - - - OpenWrt firewall VM - VM mode only; opt-in - vmbr0 WAN, vmbr1 LAN - simple firewall path - DHCP optional, VLANs later - - - - - Local registry :30500 - php-website and demos-static - forward to selected registry node - - - - - Ollama translation API - website-translator on Debian - - - - - - - - - - - - - - - - - - - - - - - - push - workflow - scan - build - manual infra - validated Git - serve boot - VM profiles - Pimox template - firewall VM - policy + GitOps - secure tunnel - service traffic - image pulls - translation calls - + Homelab architecture: delivery, alternative cluster profiles, public edge, and services. The diagram describes configuration, not live health.
diff --git a/apps/website/lang/en.php b/apps/website/lang/en.php index 6ab81d5..5d1b1e9 100644 --- a/apps/website/lang/en.php +++ b/apps/website/lang/en.php @@ -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', diff --git a/docs/code-map.md b/docs/code-map.md index 9e8b353..b8d51d2 100644 --- a/docs/code-map.md +++ b/docs/code-map.md @@ -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: diff --git a/lib/jeannie/pipeline.sh b/lib/jeannie/pipeline.sh index 8655c25..7e648d9 100644 --- a/lib/jeannie/pipeline.sh +++ b/lib/jeannie/pipeline.sh @@ -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" diff --git a/scripts/render-website-architecture.py b/scripts/render-website-architecture.py new file mode 100644 index 0000000..22c7544 --- /dev/null +++ b/scripts/render-website-architecture.py @@ -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'', + f'{esc(model["title"])}', + f'{esc(model["description"])}', + ''] + for col, group in enumerate(groups): + x = 24 + col * 392 + out += [f'', + f'{esc(group["title"])}'] + if group.get('profile_group'): + out.append(f'One profile active at a time') + 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'', + f'{esc(item["title"])}', + f'{esc(detail)}'] + out.append('How the pieces connect') + for i, flow in enumerate(model['flows']): + out.append(f'{esc(flow)}') + out.append('') + 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()) diff --git a/tests/jeannie/test_website_architecture.py b/tests/jeannie/test_website_architecture.py new file mode 100644 index 0000000..1c39dd5 --- /dev/null +++ b/tests/jeannie/test_website_architecture.py @@ -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'] = '' + self.assertIn('<test & diagram>', renderer.render(self.model, self.data)) + + +if __name__ == '__main__': + unittest.main()