mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-04 08:48:45 +00:00
get_entity_name('svc-runner') returned '' because the exact-match branch short-circuited on the category path 'svc-runner' before the shorter 'svc-' prefix could strip. The empty entity produced an empty swarm stack name (docker stack deploy "") and SERVICE_NAME '_' in the swarm convergence probe ('no such service: _' -> timeout). Record the exact match as a fallback and keep scanning so a shorter category prefix wins; simulated across all 254 roles, only svc-runner changes ('' -> 'runner').
Re-key roles/svc-runner/meta/services.yml from 'svc-runner' to the entity name 'runner' (services.yml is keyed by primary entity) and its 12 vars lookups, and add proxy.service_key: runner-1 so the swarm probe targets the real service (runner_runner-1) instead of the non-existent runner_runner.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
from pathlib import Path
|
|
|
|
from utils import PROJECT_ROOT
|
|
from utils.cache.yaml import load_yaml
|
|
|
|
|
|
def load_categories_tree(categories_file):
|
|
return load_yaml(categories_file)["roles"]
|
|
|
|
|
|
def flatten_categories(tree, prefix=""):
|
|
"""Flattens nested category tree to all possible category paths."""
|
|
result = []
|
|
for k, v in tree.items():
|
|
current = f"{prefix}-{k}" if prefix else k
|
|
result.append(current)
|
|
if isinstance(v, dict):
|
|
for sk, sv in v.items():
|
|
if isinstance(sv, dict):
|
|
result.extend(flatten_categories({sk: sv}, current))
|
|
return result
|
|
|
|
|
|
def get_entity_name(role_name):
|
|
"""
|
|
Get the entity name from a role name by removing the
|
|
longest matching category path from categories.yml.
|
|
"""
|
|
possible_locations = [
|
|
str(Path(str(Path.cwd())) / "roles" / "categories.yml"),
|
|
str(PROJECT_ROOT / "roles" / "categories.yml"),
|
|
"roles/categories.yml",
|
|
]
|
|
categories_file = None
|
|
for loc in possible_locations:
|
|
if Path(loc).exists():
|
|
categories_file = loc
|
|
break
|
|
if not categories_file:
|
|
return role_name
|
|
|
|
categories_tree = load_categories_tree(categories_file)
|
|
all_category_paths = flatten_categories(categories_tree)
|
|
|
|
role_name_lc = role_name.lower()
|
|
all_category_paths = [cat.lower() for cat in all_category_paths]
|
|
empty_match = False
|
|
for cat in sorted(all_category_paths, key=len, reverse=True):
|
|
if role_name_lc.startswith(cat + "-"):
|
|
return role_name[len(cat) + 1 :]
|
|
if role_name_lc == cat:
|
|
empty_match = True
|
|
return "" if empty_match else role_name
|