Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and jajreidy committed Oct 29, 2024
1 parent bf61854 commit a065198
Show file tree
Hide file tree
Showing 18 changed files with 422 additions and 68 deletions.
19 changes: 19 additions & 0 deletions docs/schema/cloud.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.. _cloud_schema:

Schema: cloud
==============

This document shows the schema of cloud build YAML files
supported by this library, in `JSON schema`_ format.
These files may be used within the ``CLOUD_IMAGES`` directory within
a :ref:`staging_structure`.

The latest version of this schema is available in raw form at
https://release-engineering.github.io/pushsource/cloud-schema.yaml.


.. include:: ../../src/pushsource/_impl/schema/cloud-schema.yaml
:code: yaml


.. _JSON schema: https://json-schema.org/
9 changes: 6 additions & 3 deletions docs/sources/staged.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,17 @@ Files in this directory must have metadata included in ``staged.yaml``.
Will yield instances of :class:`~pushsource.AmiPushItem`.

root/destination/CLOUD_IMAGES/\*
..............................
................................

The ``CLOUD_IMAGES`` should contain the VMI(s) plus a ``resources.yaml``.
The ``CLOUD_IMAGES`` directory should contain the VMI(s) plus a ``resources.yaml``.

The ``resources.yaml`` contains all the information needed for the
images in that folder.

Files in this directory should not include the ``staged.yaml``.
:ref:`cloud_schema` provides a complete reference of the fields which can be set by this
file.

A blank ``staged.yaml`` must be included in the root directory.

Will yield instances of either :class:`~pushsource.AmiPushItem` or
:class:`~pushsource.VHDPushItem`.
Expand Down
75 changes: 46 additions & 29 deletions src/pushsource/_impl/backend/staged/staged_cloud.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import yaml
import os
import yaml

from .staged_base import StagedBaseMixin, handles_type
from ...model import VHDPushItem, AmiPushItem, AmiRelease, BootMode, KojiBuildInfo
Expand All @@ -11,10 +11,11 @@
class StagedCloudMixin(StagedBaseMixin):
def __build_ami_push_item(self, resources, src, origin, name):
build_resources = resources.get("build")
release_resources = resources.get("release", {})
build_info = KojiBuildInfo(
name=build_resources.get("name"),
version=build_resources.get("version"),
release=build_resources.get("respin")
release=build_resources.get("respin"),
)
image_kwargs = {
"name": name,
Expand All @@ -34,7 +35,7 @@ def __build_ami_push_item(self, resources, src, origin, name):
)

release_required = ["product", "date", "arch", "respin"]
if all(x in build_resources for x in release_required):
if all(x in release_resources.keys() for x in release_required):
release_attrs = [
"product",
"date",
Expand All @@ -48,7 +49,7 @@ def __build_ami_push_item(self, resources, src, origin, name):
]
release_kwargs = {}
for key in release_attrs:
release_kwargs[key] = build_resources.get(key)
release_kwargs[key] = release_resources.get(key)

image_kwargs["release"] = AmiRelease(**release_kwargs)

Expand Down Expand Up @@ -81,44 +82,60 @@ def __build_ami_push_item(self, resources, src, origin, name):
image_kwargs[key] = resources.get(key)

return AmiPushItem(**image_kwargs)

def __build_azure_push_item(self, resources, src, origin, name):
build_resources = resources.get("build")
build_info = KojiBuildInfo(
name=build_resources.get("name"),
version=build_resources.get("version"),
release=build_resources.get("respin")
release=build_resources.get("respin"),
)
image_kwargs = {
"name": name,
"src": src,
"description": resources.get("description"),
"build_info": build_info,
"origin": origin,
}
return VHDPushItem(**image_kwargs)

@handles_type("CLOUD_IMAGES")
def __cloud_push_item(self, leafdir, metadata, entry):
with open(entry.path, "rt") as fh:
raw = yaml.safe_load(fh)
if not raw:
return


def __process_builds(self, build_dirs):
out = []
image_type = raw.get("type")
images_info = raw.get("images")
for bd in build_dirs:
yaml_path = os.path.join(bd, "resources.yaml")
try:
with open(yaml_path, "rt") as fh:
raw = yaml.safe_load(fh)
except FileNotFoundError as e:
LOG.warning("No resources.yaml file found at %s (ignored)", yaml_path)
continue
if not raw:
continue
image_type = raw.get("type", "")
images_info = raw.get("images", [])

for image in images_info:
image_relative_path = os.path.join(leafdir.path, image.get("path"))
if image_type == "AMI":
out.append(self.__build_ami_push_item(raw,
image_relative_path,
leafdir.topdir,
image.get("path")))
elif image_type == "VHD":
out.append(self.__build_azure_push_item(raw,
image_relative_path,
leafdir.topdir,
image.get("path")))
for image in images_info:
if "/" in image.get("path"):
LOG.warning("Unexpected '/' in %s (ignored)", image_relative_path)
continue
image_relative_path = os.path.join(bd, image.get("path"))
if image_type == "AMI":
out.append(
self.__build_ami_push_item(
raw, image_relative_path, bd, image.get("path")
)
)
elif image_type == "VHD":
out.append(
self.__build_azure_push_item(
raw, image_relative_path, bd, image.get("path")
)
)
return out

@handles_type("CLOUD_IMAGES")
def __cloud_push_item(self, leafdir, _, entry):
builds = [ f.path for f in os.scandir(leafdir.path) if f.is_dir() ]
out = self.__process_builds(builds)

return out
return out
Loading

0 comments on commit a065198

Please sign in to comment.