Generate website diagrams during deployment
This commit is contained in:
parent
32471aff2c
commit
e1f2edca83
|
|
@ -26,8 +26,8 @@ jobs:
|
|||
- name: Validate repository
|
||||
run: |
|
||||
set -e
|
||||
python3 scripts/render-website-architecture.py --check
|
||||
python3 scripts/render-website-tree.py --check
|
||||
python3 scripts/render-website-architecture.py --output /tmp/homelab-architecture.svg
|
||||
python3 scripts/render-website-tree.py --output /tmp/homelab-tree.json
|
||||
./jeannie validate
|
||||
|
||||
running-update:
|
||||
|
|
|
|||
|
|
@ -40,37 +40,25 @@ the blog page cacheable while preserving the write path through `save_idea.php`.
|
|||
|
||||
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
|
||||
Jeannie regenerates it automatically in a temporary website build directory
|
||||
before calculating the image tag. 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
|
||||
profile or changing its runtime requires a model review. CI also validates
|
||||
that generation succeeds. 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.
|
||||
|
||||
The Christmas tree retains its festive artwork and uses the curated
|
||||
`architecture/tree-model.json` for its technology ornaments and explanations.
|
||||
The `Learning` category marks experiments rather than production claims.
|
||||
Edit the model when technologies or descriptions change, then run:
|
||||
|
||||
```sh
|
||||
python3 scripts/render-website-tree.py
|
||||
python3 scripts/render-website-tree.py --check
|
||||
python3 -m unittest discover -s tests/jeannie -p test_website_tree.py
|
||||
```
|
||||
|
||||
Commit `tree-model.json` and the generated `tree-data.json` together. The
|
||||
Edit the model when technologies or descriptions change; `jeannie apps website`
|
||||
automatically generates the tree data in the temporary build directory. The
|
||||
generator checks the shared profile model and any explicit inventory
|
||||
references; technologies without inventory references are editorial and need
|
||||
manual review. CI and `jeannie apps website` refuse stale generated data.
|
||||
The tree illustrates configured technologies, not current service health.
|
||||
manual review. Generated files in the checkout are reference snapshots and do
|
||||
not need to be updated for a Jeannie website deployment. The tree illustrates
|
||||
configured technologies, not current service health.
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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 the diagram model, then run
|
||||
`python3 scripts/render-website-architecture.py`; CI checks for stale output.
|
||||
instructions in the generated documentation. Review the public diagram model
|
||||
when architecture relationships change. CI checks that it can be generated,
|
||||
and Jeannie generates the diagram in a temporary website build context.
|
||||
Website source changes take effect after the normal image build and
|
||||
Argo delivery path; editing PHP does not publish the live site.
|
||||
|
||||
|
|
|
|||
|
|
@ -4722,7 +4722,7 @@ demos_registry_endpoint() {
|
|||
|
||||
website_source_hash() {
|
||||
(
|
||||
cd "${REPO_ROOT}"
|
||||
cd "${1:-${REPO_ROOT}}"
|
||||
find apps/website -type f -print0 | sort -z | xargs -0 sha256sum | sha256sum | awk '{print $1}'
|
||||
)
|
||||
}
|
||||
|
|
@ -7904,7 +7904,7 @@ PIMOX_NODE_STORAGE_EOF
|
|||
done
|
||||
}
|
||||
|
||||
apps() {
|
||||
apps() (
|
||||
local app_selector="${1:-all}"
|
||||
local app_ready_wait_seconds="${LAB_APPS_READY_WAIT_SECONDS:-600}"
|
||||
local app_resource_wait_seconds="${LAB_APPS_RESOURCE_WAIT_SECONDS:-120}"
|
||||
|
|
@ -7921,6 +7921,7 @@ apps() {
|
|||
local website_image_state_file
|
||||
local website_platforms
|
||||
local website_source_hash
|
||||
local website_build_root=""
|
||||
local -a app_targets=()
|
||||
local deploy_demos=false
|
||||
local deploy_registry=false
|
||||
|
|
@ -7966,8 +7967,12 @@ apps() {
|
|||
require_debian_server "apps"
|
||||
|
||||
if [[ "${deploy_website}" == "true" ]]; then
|
||||
python3 "${REPO_ROOT}/scripts/render-website-architecture.py" --check || return 1
|
||||
python3 "${REPO_ROOT}/scripts/render-website-tree.py" --check || return 1
|
||||
website_build_root="$(mktemp -d "${TMPDIR:-/tmp}/jeannie-website.XXXXXXXX")" || return 1
|
||||
trap 'rm -rf -- "${website_build_root}"' EXIT
|
||||
mkdir -p "${website_build_root}/apps" || return 1
|
||||
cp -a "${REPO_ROOT}/apps/website" "${website_build_root}/apps/website" || return 1
|
||||
python3 "${REPO_ROOT}/scripts/render-website-architecture.py" --output "${website_build_root}/apps/website/architecture/homelab.svg" || return 1
|
||||
python3 "${REPO_ROOT}/scripts/render-website-tree.py" --output "${website_build_root}/apps/website/architecture/tree-data.json" || return 1
|
||||
fi
|
||||
|
||||
registry_endpoint="$(apps_registry_endpoint)"
|
||||
|
|
@ -7978,7 +7983,7 @@ apps() {
|
|||
demos_image_ref="${registry_endpoint}/demos-static:${DEMOS_IMAGE_TAG:-$(demos_image_tag "${demos_source_hash}")}"
|
||||
website_image_state_file="${REPO_ROOT}/.lab/php-website-image.state"
|
||||
website_platforms="${WEBSITE_IMAGE_PLATFORMS:-linux/amd64,linux/arm64}"
|
||||
website_source_hash="$(website_source_hash)"
|
||||
website_source_hash="$(website_source_hash "${website_build_root:-${REPO_ROOT}}")"
|
||||
website_image_ref="${registry_endpoint}/php-website:${WEBSITE_IMAGE_TAG:-$(website_image_tag "${website_source_hash}")}"
|
||||
export TF_VAR_registry_endpoint="${TF_VAR_registry_endpoint:-${registry_endpoint}}"
|
||||
export TF_VAR_website_image_ref="${TF_VAR_website_image_ref:-${website_image_ref}}"
|
||||
|
|
@ -8080,8 +8085,8 @@ apps() {
|
|||
--sbom=true \
|
||||
--label "dev.homelab.website.source-hash=${website_source_hash}" \
|
||||
-t "${website_image_ref}" \
|
||||
-f "${REPO_ROOT}/apps/website/Dockerfile" \
|
||||
"${REPO_ROOT}/apps/website/" \
|
||||
-f "${website_build_root}/apps/website/Dockerfile" \
|
||||
"${website_build_root}/apps/website/" \
|
||||
--push; then
|
||||
echo "Website image build failed for ${website_image_ref}; not publishing supply-chain metadata." >&2
|
||||
return 1
|
||||
|
|
@ -8176,7 +8181,7 @@ apps() {
|
|||
|
||||
echo "Application deployment successfully completed."
|
||||
remember_cluster_profile || return 1
|
||||
}
|
||||
)
|
||||
|
||||
platform_apply() {
|
||||
require_debian_server "platform"
|
||||
|
|
|
|||
|
|
@ -94,16 +94,17 @@ def render(model, data):
|
|||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--check', action='store_true', help='fail if the committed SVG is stale')
|
||||
parser.add_argument('--output', type=Path, default=OUTPUT, help='write the generated SVG to this path')
|
||||
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:
|
||||
if not args.output.exists() or args.output.read_text(encoding='utf-8') != 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)}')
|
||||
args.output.write_text(content, encoding='utf-8')
|
||||
print(f'Wrote {args.output}')
|
||||
except (ValueError, KeyError, TypeError, OSError, json.JSONDecodeError) as exc:
|
||||
print(f'Architecture diagram: {exc}', file=sys.stderr)
|
||||
return 1
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@ ARCH_SCRIPT = ROOT / 'scripts/render-website-architecture.py'
|
|||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--check', action='store_true', help='check the generated data without writing')
|
||||
parser.add_argument('--output', type=Path, help='write generated data to this path')
|
||||
args = parser.parse_args()
|
||||
output = args.output or TREE_DATA
|
||||
try:
|
||||
spec = importlib.util.spec_from_file_location('architecture_renderer', ARCH_SCRIPT)
|
||||
architecture = importlib.util.module_from_spec(spec)
|
||||
|
|
@ -46,12 +48,12 @@ def main():
|
|||
if ornament.get('inventory'):
|
||||
architecture.lookup(data, ornament['inventory'])
|
||||
if args.check:
|
||||
if not TREE_DATA.exists() or TREE_DATA.read_text(encoding='utf-8') != source:
|
||||
if not output.exists() or output.read_text(encoding='utf-8') != source:
|
||||
raise ValueError('Tree data is stale; run python3 scripts/render-website-tree.py')
|
||||
print('Website Christmas tree is current.')
|
||||
else:
|
||||
TREE_DATA.write_text(source, encoding='utf-8')
|
||||
print(f'Wrote {TREE_DATA.relative_to(ROOT)}')
|
||||
output.write_text(source, encoding='utf-8')
|
||||
print(f'Wrote {output}')
|
||||
except (OSError, ValueError, KeyError, TypeError, AttributeError, json.JSONDecodeError) as exc:
|
||||
print(f'Website Christmas tree: {exc}', file=sys.stderr)
|
||||
return 1
|
||||
|
|
|
|||
|
|
@ -42,6 +42,15 @@ class WebsiteTreeTests(unittest.TestCase):
|
|||
self.assertEqual(self.run_tree(), 1)
|
||||
self.assertFalse(self.output.exists())
|
||||
|
||||
def test_custom_build_output_does_not_modify_snapshot(self):
|
||||
snapshot = self.output
|
||||
snapshot.write_text('snapshot\n', encoding='utf-8')
|
||||
build_output = Path(self.temp.name) / 'build.json'
|
||||
self.assertEqual(self.run_tree('--output', str(build_output)), 0)
|
||||
self.assertEqual(snapshot.read_text(encoding='utf-8'), 'snapshot\n')
|
||||
self.assertEqual(json.loads(build_output.read_text(encoding='utf-8')),
|
||||
json.loads(self.model.read_text(encoding='utf-8')))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Reference in New Issue