mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-10 04:36:40 +00:00
- Move iter_role_images + all helpers + ImageRef from cli/mirror/util.py and
cli/mirror/model.py into utils/docker/image_discovery.py; add source_file field
to ImageRef to distinguish config/main.yml vs vars/main.yml entries
- Delete cli/mirror/util.py; update all callers to import from utils.docker.image_discovery
- Move utils into subpackages: utils/docker/ (image_ref, paths_utils, hadolint) and
utils/roles/ (dependency_resolver, resource_validation); update all imports
- Reorganise tests into subpackages: tests/lint/docker/dockerfile/, tests/integration/docker/,
tests/unit/utils/docker/, tests/unit/utils/roles/; fix parents[N] offsets after relocation
- tests/lint/docker/test_image_versions.py now uses iter_role_images (same SPOT as mirror)
- Add vars/main.yml images.<name>.{image,version} support for non-application roles
(test-e2e-playwright, sys-ctl-hlth-csp); eliminate hardcoded duplicates in defaults/tasks
- Add web-app-matrix matrix-chatgpt-bot and web-app-mini-qr mini-qr entries in config/main.yml;
replace hardcoded image strings in vars/templates with lookup('config', ...) references
- Fix sync/__main__.py log line to use correct registry prefix for non-Docker-Hub images
- Update docs/contributing/code/role/dockerfile.md with image declaration rules and SPOT reference
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any, Dict, Optional
|
|
|
|
from ansible.errors import AnsibleError
|
|
from ansible.plugins.lookup import LookupBase
|
|
|
|
from utils.docker.paths_utils import get_docker_paths
|
|
|
|
|
|
def _as_str(v: Any) -> str:
|
|
return "" if v is None else str(v).strip()
|
|
|
|
|
|
def _deep_get(d: Dict[str, Any], path: str) -> Any:
|
|
cur: Any = d
|
|
for key in path.split("."):
|
|
if not isinstance(cur, dict) or key not in cur:
|
|
raise AnsibleError(f"lookup('container'): invalid path '{path}'")
|
|
cur = cur[key]
|
|
return cur
|
|
|
|
|
|
class LookupModule(LookupBase):
|
|
"""
|
|
lookup('container', application_id[, path])
|
|
|
|
path can be:
|
|
- 'directories' / 'files' (returns sub-dict)
|
|
- 'directories.instance' (returns leaf)
|
|
"""
|
|
|
|
def run(self, terms, variables: Optional[Dict[str, Any]] = None, **kwargs):
|
|
if not terms or len(terms) > 2:
|
|
raise AnsibleError("lookup('container', application_id[, path])")
|
|
|
|
application_id = _as_str(terms[0])
|
|
if not application_id:
|
|
raise AnsibleError("lookup('container'): application_id is empty")
|
|
|
|
base = _as_str((variables or {}).get("DIR_COMPOSITIONS"))
|
|
if not base:
|
|
raise AnsibleError("lookup('container'): DIR_COMPOSITIONS not set")
|
|
|
|
paths = get_docker_paths(application_id, base)
|
|
|
|
if len(terms) == 2:
|
|
path = _as_str(terms[1])
|
|
if not path:
|
|
raise AnsibleError("lookup('container'): path is empty")
|
|
return [_deep_get(paths, path)]
|
|
|
|
return [paths]
|