Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport master] Add some additional configuration to be able to tweak the package ins… #1264

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions c2cciutils/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class Codespell(TypedDict, total=False):
"publish": "Publish",
"version": "Version",
"k8s": "K8SConfiguration",
"dpkg": "Dpkg",
},
total=False,
)
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 15 additions & 7 deletions c2cciutils/lib/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand Down Expand Up @@ -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":
Expand Down
24 changes: 24 additions & 0 deletions c2cciutils/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
}
}
5 changes: 5 additions & 0 deletions config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading