Image Recipe Tools¶
Module for miscellaneous modules to work with sregistry.
-
singularity_autobuild.image_recipe_tools.
dependency_drill_down
(dependency_dict, recipe_path, recipe_base_path)[source]¶ Recursively drills down a dependency chain.
The dependency dict is passed as reference through all recursive functions calls. It functions as a cache for already known results and as the expected result. It is however not returned.
Sets a dependency as 0, if it does not depend on container from the private sregistry. If a child of a recipe is found, this number is incremented by one.
Example:
{ '/path/to/Parent.recipe': 0, '/path/to/child.recipe': 1, '/path/to/child_of_child.recipe': 2 }
Parameters: - dependency_dict (
dict
) – Contains already known dependencies. The dictionary is directly modified and only passed as reference not as copy. It functions both as a cache and as the final result of the function. - child_key – Path to the recipe whose dependency is calculated.
Return type: None
- dependency_dict (
-
singularity_autobuild.image_recipe_tools.
dependency_resolver
(recipe_file_paths, recipe_base_path)[source]¶ Sorts a list of recipe file paths based on their base image dependency.
Sorts the list in a way, that all recipes with dependencies linking outside the local storage are sorted to the beginning. All other recipes that follow those recipes are sorted, that recipe with a child dependency, is always sorted behind its parent in the list.
Since a recipe can only depend on one base image, it is sufficient, that this base image is in front of the child image during the building process.
Parameters: - recipe_file_paths (
list
) – List of paths to recipe files. - recipe_base_path (
str
) – Path to the base folder containing all recipe files.
Return type: list
Returns: List of recipe paths sorted by their dependency. With Parents sorted before their children.
- recipe_file_paths (
-
singularity_autobuild.image_recipe_tools.
get_collection_from_recipe_path
(recipe_file_full_path)[source]¶ Returns the collection of the image to be produced by a recipe file .
Return type: str
-
singularity_autobuild.image_recipe_tools.
get_dependency_from_recipe
(recipe_file_full_path)[source]¶ Reads a recipe file and returns its Bootstrap and From values.
Return type: dict
Returns: A dict with a key equal to the recipes Bootstrap method and the value of this key being the value of its From value. Raises: UserWarning
-
singularity_autobuild.image_recipe_tools.
get_image_name_from_recipe
(recipe_file_name)[source]¶ Returns the image name contained in a recipe file name.
Return type: str
-
singularity_autobuild.image_recipe_tools.
get_path_from_dependency
(recipe_dependency_value, recipe_base_folder_path)[source]¶ Searches the base folder for a file, that corresponse to the dependency passed.
Parameters: - recipe_dependency_value (
str
) – Value of the “From:” section from a recipe file, used by singularity to find the base image. - recipe_base_folder_path (
str
) – Full path of the base folder, containing all recipes.
Return type: str
Returns: Full path to the parent recipe or an empty string ‘’ if it is not a local dependency.
- recipe_dependency_value (
-
singularity_autobuild.image_recipe_tools.
get_version_from_recipe
(recipe_file_name)[source]¶ Returns the image version contained in a recipe file name.
Return type: str
-
singularity_autobuild.image_recipe_tools.
image_in_sregistry
(collection, version, image)[source]¶ Returns true if image of version exists in collection.
Calls sregistry search and parses its output to determin if a specific container is already stored in the sregistry. :type collection:
str
:param collection: The name of the images/containers collection. :type version:str
:param version: The version of the container. :type image:str
:param image: The name of the container.Return type: bool
-
singularity_autobuild.image_recipe_tools.
image_pusher
(image_path, collection, version, image, retry_threshold=20)[source]¶ Upload image to an sregistry.
Calls sregistry push with subprocess.Popen to upload an existing image to an sregistry.
Parameters: - image_path (
str
) – Path to the image file - collection (
str
) – Name of the collection to upload to. - version (
str
) – Version of the image. - image (
str
) – Name of the image to be used by the sregistry. - retry_threshold (
int
) – How often should the upload retried if it fails. Note: Sregistry showed problems with accepting post requests. This parameter might become obsolete when this is no longer an issue.
Return type: bool
Returns: The success status of the upload.
- image_path (
-
singularity_autobuild.image_recipe_tools.
is_own_dependency
(recipe_dependency_value)[source]¶ Returns True if the dependency links to the sregistry used to push images to.
Needs the env variable SREGISTRY_HOSTNAME to be set. This variable is also needed for the .sregistry file setup.
Parameters: recipe_dependency_value ( str
) – Value from a recipes “From:” section declaring the base Image.Return type: bool
-
singularity_autobuild.image_recipe_tools.
recipe_finder
(path='./')[source]¶ Find recipe files given a root search directory.
Recipes need to have the suffix .recipe
Parameters: path ( str
) – Path of the search root. The path will be made into an absolute path if it is relative.Return type: Generator
[+T_co, -T_contra, +V_co]Returns: The absolute paths to found recipes.
-
singularity_autobuild.image_recipe_tools.
recipe_list_sanity_check
(recipe_file_paths)[source]¶ Checks a list of recipe file paths for recipes creating duplicates.
Raises an exception if at least two recipes are found in the passed list, that would be uploaded to the same collection, with the same name, and the same version.
Parameters: recipe_file_paths ( list
) – A list of full paths to recipe files.Raises: RuntimeError Return type: None