bd125b0b57
Add DOCKER_REGISTRY and DOCKER_REGISTRY_PREFIX environment variables to ci/build_matrix.py for pulling base images from a private registry (Artifactory, Harbor, etc.) instead of Docker Hub. Document CI usage and registry configuration in README.
67 lines
2.1 KiB
Python
67 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Parse meta/main.yml platforms and output a Docker test matrix as JSON."""
|
|
|
|
import json
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
try:
|
|
import yaml
|
|
except ImportError:
|
|
print("ERROR: PyYAML is required. Install with: pip install pyyaml", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
# Mapping Galaxy platform name -> Docker image prefix
|
|
PLATFORM_IMAGE_MAP = {
|
|
"EL": "rockylinux",
|
|
"Debian": "debian",
|
|
"Ubuntu": "ubuntu",
|
|
}
|
|
|
|
def _resolve_image(image: str) -> str:
|
|
"""Prefix image with registry and namespace if configured via env vars."""
|
|
registry = os.environ.get("DOCKER_REGISTRY", "").strip().rstrip("/")
|
|
prefix = os.environ.get("DOCKER_REGISTRY_PREFIX", "").strip()
|
|
if registry:
|
|
return f"{registry}/{prefix}{image}"
|
|
return image
|
|
|
|
def build_matrix(meta_path: str = "roles/remote_users_fact/meta/main.yml") -> list[dict]:
|
|
meta_file = Path(meta_path)
|
|
if not meta_file.exists():
|
|
print(f"ERROR: {meta_file} not found", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
with open(meta_file) as f:
|
|
meta = yaml.safe_load(f)
|
|
|
|
platforms = meta.get("galaxy_info", {}).get("platforms", [])
|
|
if not platforms:
|
|
print("ERROR: No platforms found in meta/main.yml", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
matrix = []
|
|
for platform in platforms:
|
|
name = platform["name"]
|
|
if name not in PLATFORM_IMAGE_MAP:
|
|
print(f"ERROR: Unknown platform '{name}'. Known: {list(PLATFORM_IMAGE_MAP.keys())}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
image_prefix = PLATFORM_IMAGE_MAP[name]
|
|
for version in platform.get("versions", []):
|
|
version_str = str(version)
|
|
slug = f"{name.lower()}{version_str}" if name == "EL" else f"{name.lower()}-{version_str}"
|
|
base_image = f"{image_prefix}:{version_str}"
|
|
matrix.append({
|
|
"slug": slug,
|
|
"image": _resolve_image(base_image),
|
|
"platform": name,
|
|
"version": version_str,
|
|
})
|
|
|
|
return matrix
|
|
|
|
if __name__ == "__main__":
|
|
print(json.dumps(build_matrix(), indent=2))
|