| |
@@ -186,11 +186,6 @@
|
| |
self['multi_arch_rpm_manifest'][image_arch] = image_rpm_manifest
|
| |
|
| |
@property
|
| |
- def is_base_image(self):
|
| |
- return (self['parent'] is None and
|
| |
- len(self['parsed_data']['layers']) == 2)
|
| |
-
|
| |
- @property
|
| |
def dockerfile(self):
|
| |
dockerfile = [file for file in self['parsed_data']['files']
|
| |
if file['filename'] == 'Dockerfile']
|
| |
@@ -1151,146 +1146,6 @@
|
| |
return None
|
| |
return images[0]
|
| |
|
| |
- # TODO: this should be removed in the future. There's a field in lightblue and koji
|
| |
- # that allows us to get the parent directly, without checking the layers.
|
| |
- @region.cache_on_arguments()
|
| |
- def get_image_by_layer(self, top_layer, build_layers_count,
|
| |
- srpm_name):
|
| |
- """
|
| |
- Find parent image by layer from either published repository or not
|
| |
-
|
| |
- :param str top_layer: the hash string representing an built image,
|
| |
- which is usually the top layer in ``parsed_data.layers`` list.
|
| |
- :param int build_layers_count: the number of build layers an image has.
|
| |
- :param str srpm_name: name of the package. it is optional. if
|
| |
- specified, will find image that also contains this package.
|
| |
-
|
| |
- :return: parent ContainerImage object. None is returned if no image is
|
| |
- found.
|
| |
- :rtype: ContainerImage
|
| |
- """
|
| |
- query = {
|
| |
- "objectType": "containerImage",
|
| |
- "query": {
|
| |
- "$and": [
|
| |
- {
|
| |
- "field": "parsed_data.layers#",
|
| |
- "op": "$eq",
|
| |
- "rvalue": build_layers_count
|
| |
- },
|
| |
- {
|
| |
- "field": "parsed_data.layers.*",
|
| |
- "op": "$eq",
|
| |
- "rvalue": top_layer
|
| |
- },
|
| |
- ],
|
| |
- },
|
| |
- "projection": self._get_default_projection(
|
| |
- srpm_names=[srpm_name] if srpm_name else None,
|
| |
- include_rpm_manifest=srpm_name is not None)
|
| |
- }
|
| |
-
|
| |
- images = self.find_container_images(query)
|
| |
- if not images:
|
| |
- return None
|
| |
-
|
| |
- # Filter out images which do not contain srpm_name locally, because
|
| |
- # filtering in lightblue takes long time and can even timeout
|
| |
- # server-side.
|
| |
- # We expect just at max 2 images here, published and unpublished, so
|
| |
- # it is not big deal doing so.
|
| |
- if srpm_name:
|
| |
- tmp = []
|
| |
- for image in images:
|
| |
- rpms = image.get_rpms()
|
| |
- for rpm in rpms or []:
|
| |
- if "srpm_name" in rpm and rpm["srpm_name"] == srpm_name:
|
| |
- tmp.append(image)
|
| |
- break
|
| |
- images = tmp
|
| |
- if not images:
|
| |
- return None
|
| |
-
|
| |
- for image in images:
|
| |
- # we should prefer published image
|
| |
- if 'repositories' in image:
|
| |
- for repository in image['repositories']:
|
| |
- if repository['published']:
|
| |
- return image
|
| |
-
|
| |
- return images[0]
|
| |
-
|
| |
- @region.cache_on_arguments()
|
| |
- def get_repository_from_name(self, repo_name):
|
| |
- """
|
| |
- Returns the ContainerRepository object based on the Repository name.
|
| |
- """
|
| |
- query = {
|
| |
- "objectType": "containerRepository",
|
| |
- "query": {
|
| |
- "$and": [
|
| |
- {
|
| |
- "field": "repository",
|
| |
- "op": "=",
|
| |
- "rvalue": repo_name
|
| |
- },
|
| |
-
|
| |
- ]
|
| |
- },
|
| |
- "projection": [
|
| |
- {"field": "*", "include": True, "recursive": True}
|
| |
- ]
|
| |
- }
|
| |
-
|
| |
- repos = self.find_container_repositories(query)
|
| |
- if not repos:
|
| |
- return None
|
| |
-
|
| |
- if len(repos) != 1:
|
| |
- raise ValueError("Multiple records found in Lightblue for repository %s." % repo_name)
|
| |
-
|
| |
- return repos[0]
|
| |
-
|
| |
- def find_latest_parent_image(self, parent_top_layer, parent_build_layers_count):
|
| |
- """
|
| |
- Finds the latest published parent image defined by the `parent_top_layer` and
|
| |
- `parent_build_layers_count`. For more info about these variables, refer to
|
| |
- `find_parent_images_with_package`.
|
| |
-
|
| |
- This method tries to find out the latest published parent image. If it fails
|
| |
- to find out, it simply returns the unpublished image defined by the input args.
|
| |
- """
|
| |
- latest_parent = self.get_image_by_layer(
|
| |
- parent_top_layer, parent_build_layers_count, None)
|
| |
- if not latest_parent or "repositories" not in latest_parent:
|
| |
- return latest_parent
|
| |
-
|
| |
- latest_parent_nvr = kobo.rpmlib.parse_nvr(latest_parent.nvr)
|
| |
-
|
| |
- for repo in latest_parent["repositories"]:
|
| |
- repo_data = self.get_repository_from_name(repo["repository"])
|
| |
- if not repo_data:
|
| |
- continue
|
| |
-
|
| |
- possible_latest_parents = self.find_images_with_included_srpms(
|
| |
- [], [], {repo["repository"]: repo_data}, include_rpm_manifest=False)
|
| |
- for possible_latest_parent in possible_latest_parents:
|
| |
- # Treat the `possible_latest_parent` as `latest_parent` in case its
|
| |
- # Name and Version are the same and Release is higher.
|
| |
- # compare_nvr return values:
|
| |
- # - nvr1 newer than nvr2: 1
|
| |
- # - same nvrs: 0
|
| |
- # - nvr1 older: -1
|
| |
- parsed_nvr = kobo.rpmlib.parse_nvr(possible_latest_parent.nvr)
|
| |
- if (parsed_nvr["name"] == latest_parent_nvr["name"] and
|
| |
- parsed_nvr["version"] == latest_parent_nvr["version"] and
|
| |
- kobo.rpmlib.compare_nvr(
|
| |
- latest_parent_nvr, parsed_nvr, ignore_epoch=True) == -1):
|
| |
- latest_parent = possible_latest_parent
|
| |
- latest_parent_nvr = kobo.rpmlib.parse_nvr(latest_parent.nvr)
|
| |
-
|
| |
- return latest_parent
|
| |
-
|
| |
def find_parent_brew_build_nvr_from_child(self, child_image):
|
| |
"""
|
| |
Returns the parent brew build NVR of the input image. If the parent is not found it returns None.
|
| |
This appears to be left over from changing how parent images are
identified.
Signed-off-by: Luiz Carvalho lucarval@redhat.com