diff --git a/c2cciutils/configuration.py b/c2cciutils/configuration.py index 4e6e9e44a..8d2dbb8ac 100644 --- a/c2cciutils/configuration.py +++ b/c2cciutils/configuration.py @@ -222,6 +222,7 @@ class Codespell(TypedDict, total=False): "publish": "Publish", "version": "Version", "k8s": "K8SConfiguration", + "dpkg": "Dpkg", }, total=False, ) @@ -292,6 +293,28 @@ class Codespell(TypedDict, total=False): ) +class Dpkg(TypedDict, total=False): + """ + dpkg. + + The configuration use t manage the dpkg packages + """ + + packages_mapping: dict[str, str] + """ + dpkg packages mapping. + + The mapping of source package found in the image to package present in repology.org + """ + + ignored_packages: list[str] + """ + dpkg ignored packages. + + The list of packages that should be ignored + """ + + # K3d configuration. # # default: diff --git a/c2cciutils/lib/docker.py b/c2cciutils/lib/docker.py index f000ba452..cec19cdd0 100644 --- a/c2cciutils/lib/docker.py +++ b/c2cciutils/lib/docker.py @@ -8,9 +8,13 @@ import yaml from debian_inspector.version import Version +import c2cciutils.configuration + def get_dpkg_packages_versions( - image: str, default_distribution: Optional[str] = None, default_release: Optional[str] = None + image: str, + default_distribution: Optional[str] = None, + default_release: Optional[str] = None, ) -> tuple[bool, dict[str, Version]]: """ Get the versions of the dpkg packages installed in the image. @@ -22,6 +26,8 @@ def get_dpkg_packages_versions( from https://repology.org/repositories/statistics """ + dpkg_configuration = c2cciutils.get_config().get("dpkg", {}) + os_release = {} try: os_release_process = subprocess.run( @@ -79,12 +85,14 @@ def get_dpkg_packages_versions( if version is None: print(f"Error: Missing version for package {package}") else: - if package in package_version and version != package_version[package]: - print( - f"The package {package} has different version ({package_version[package]} != {version})" - ) - if package not in ("base-files",): - package_version[package] = version + if package not in dpkg_configuration.get("ignored_packages", []): + package = dpkg_configuration.get("packages_mapping", {}).get(package, package) + if package in package_version and version != package_version[package]: + print( + f"The package {package} has different version ({package_version[package]} != {version})" + ) + if package not in ("base-files",): + package_version[package] = version package = value version = None if name == "Source": diff --git a/c2cciutils/schema.json b/c2cciutils/schema.json index d3d46576c..1875a4f47 100644 --- a/c2cciutils/schema.json +++ b/c2cciutils/schema.json @@ -615,6 +615,30 @@ } } } + }, + "dpkg": { + "title": "dpkg", + "description": "The configuration use t manage the dpkg packages", + "type": "object", + "additionalProperties": false, + "properties": { + "packages_mapping": { + "title": "dpkg packages mapping", + "description": "The mapping of source package found in the image to package present in repology.org", + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "ignored_packages": { + "title": "dpkg ignored packages", + "description": "The list of packages that should be ignored", + "type": "array", + "items": { + "type": "string" + } + } + } } } } diff --git a/config.md b/config.md index e7d504ff8..50ac05043 100644 --- a/config.md +++ b/config.md @@ -31,6 +31,11 @@ _C2C CI utils configuration file_ - **`db`** _(object)_: Database configuration. Default: `{}`. - **`chart-options`** _(object)_: Can contain additional properties. Default: `{"persistence.enabled": "false", "tls.enabled": "true", "tls.autoGenerated": "true", "auth.postgresPassword": "mySuperTestingPassword", "volumePermissions.enabled": "true"}`. - **Additional Properties** _(string)_ +- **`dpkg`** _(object)_: The configuration use t manage the dpkg packages. Cannot contain additional properties. + - **`packages_mapping`** _(object)_: The mapping of source package found in the image to package present in repology.org. Can contain additional properties. + - **Additional Properties** _(string)_ + - **`ignored_packages`** _(array)_: The list of packages that should be ignored. + - **Items** _(string)_ ## Definitions