API reference
mender_docker_lifecycle_helper.artifact
Classes:
-
LifecycleHelperArtifact–Representation of the artifact on which the helper is operating. Provides the gen_artifact_file method to perform necessary processing and preparation for creating a Mender artifact file.
LifecycleHelperArtifact
LifecycleHelperArtifact(context: LifecycleHelperContext, name: str, artifact_metadata: ArtifactMetadata, filename: Path)
Representation of the artifact on which the helper is operating. Provides the gen_artifact_file method to perform necessary processing and preparation for creating a Mender artifact file.
Construct a LifecycleHelperArtifact object.
Parameters:
-
(contextLifecycleHelperContext) –The context of the lifecycle helper execution.
-
(namestr) –The name of the artifact as recognized by Mender.
-
(artifact_metadataArtifactMetadata) –The metadata of the artifact for caching.
-
(filenamePath) –The file at which to generate the artifact.
Methods:
-
call_mender_artifact–Execute the mender-artifact executable with the supplied arguments.
-
gen_artifact_file–Prepare the artifact by generating necessary files and processing via the mender-artifact tool.
-
gen_artifact_services–Determine the services metadata for the current artifact, including reading the image hashes from remote images when required. To establish this list, any provided service-file image archives are extracted and read.
-
prep_artifact_dir–Prepare artifact directory with necessary files for artifact generation, such as extracted service file images and any other necessary files.
-
prep_delta_image–Prepare a delta image file, which may be an empty delta file if the image ref and hash for the service match those in the previous artifact metadata, or a real delta.
-
prep_image–Prepare the required directory and files for the specified image in the specified artifact prep directory.
-
prep_images–Prepare the archive file for the specified images in the Mender artifact format, downloading and/or diffing images as necessary based on the image refs and hashes.
-
prep_manifests–Prepare the manifests archive file in the Mender artifact format.
Source code in src/mender_docker_lifecycle_helper/artifact.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
call_mender_artifact
staticmethod
call_mender_artifact(context: LifecycleHelperContext, arg_list: list[str]) -> str
Execute the mender-artifact executable with the supplied arguments.
Parameters:
-
(contextLifecycleHelperContext) –The context of the lifecycle helper execution.
-
(arg_listlist[str]) –The arguments to supply to the mender-artifact executable.
Returns:
-
str–The stdout output of the mender-artifact execution.
Raises:
-
RuntimeError–If the mender-artifact execution fails.
Source code in src/mender_docker_lifecycle_helper/artifact.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
gen_artifact_file
gen_artifact_file() -> None
Prepare the artifact by generating necessary files and processing via the mender-artifact tool.
Returns:
-
None–None
Source code in src/mender_docker_lifecycle_helper/artifact.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
gen_artifact_services
staticmethod
gen_artifact_services(context: LifecycleHelperContext) -> dict[str:(dict[str:(dict[str, str])])]
Determine the services metadata for the current artifact, including reading the image hashes from remote images when required. To establish this list, any provided service-file image archives are extracted and read.
Parameters:
-
(contextLifecycleHelperContext) –The context of the lifecycle helper execution.
Returns:
-
dict[str:(dict[str:(dict[str, str])])]–The services to be included in the current artifact, in the following dict structure: { serviceName: { image: { ref: str, hash: str } } }
Raises:
-
ManifestContentMismatchException–If service name in args not found in manifest.
Source code in src/mender_docker_lifecycle_helper/artifact.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
prep_artifact_dir
prep_artifact_dir(artifact_prep_dir: Path, images_archive_filename: str, manifests_archive_filename: str, metadata_filename: str) -> None
Prepare artifact directory with necessary files for artifact generation, such as extracted service file images and any other necessary files.
Parameters:
-
(artifact_prep_dirPath) –The directory into which to prepare the artifact files.
-
(images_archive_filenamestr) –The filename for the artifact images archive.
-
(manifests_archive_filenamestr) –The filename for the artifact manifests archive.
-
(metadata_filenamestr) –The filename for the artifact metadata file.
Returns:
-
None–None
Source code in src/mender_docker_lifecycle_helper/artifact.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
prep_delta_image
prep_delta_image(service_name: str, service_image: dict[str, str], artifact_image_prep_dir: Path) -> None
Prepare a delta image file, which may be an empty delta file if the image ref and hash for the service match those in the previous artifact metadata, or a real delta.
Parameters:
-
(service_namestr) –The name of the service in the manifest for which to generate an image delta.
-
(service_imagedict[str, str]) –The metadata of the image for which to generate a delta.
-
(artifact_image_prep_dirPath) –The directory into which the image delta file will be written.
Returns:
-
None–None
Raises:
-
ImageDeltaException–If the delta generation fails.
Source code in src/mender_docker_lifecycle_helper/artifact.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
prep_image
prep_image(service_name: str, service_image: dict[str, str], artifact_images_prep_dir: Path) -> None
Prepare the required directory and files for the specified image in the specified artifact prep directory.
Parameters:
-
(service_namestr) –The name of the service in the manifest for which to generate an image delta.
-
(service_imagedict[str, str]) –The metadata of the image for which to generate a delta.
-
(artifact_images_prep_dirPath) –The directory into which the image directory will be created.
Returns:
-
None–None
Raises:
-
ImageDeltaException–If delta generation fails.
Source code in src/mender_docker_lifecycle_helper/artifact.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
prep_images
prep_images(artifact_prep_dir: Path, images_archive_filename: str) -> None
Prepare the archive file for the specified images in the Mender artifact format, downloading and/or diffing images as necessary based on the image refs and hashes.
Parameters:
-
(artifact_prep_dirPath) –The directory into which the images archive will be generated.
-
(images_archive_filenamestr) –The name of the images archive file to generate.
Returns:
-
None–None
Source code in src/mender_docker_lifecycle_helper/artifact.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
prep_manifests
prep_manifests(artifact_prep_dir: Path, manifests_archive_filename: str) -> None
Prepare the manifests archive file in the Mender artifact format.
Parameters:
-
(artifact_prep_dirPath) –The directory into which the manifests archive will be generated.
-
(manifests_archive_filenamestr) –The name of the manifests archive file to generate.
Returns:
-
None–None
Source code in src/mender_docker_lifecycle_helper/artifact.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
mender_docker_lifecycle_helper.artifact_metadata
Classes:
ArtifactMetadata
Construct an ArtifactMetadata object.
Parameters:
-
(versionstr) –The version identifier for the artifact.
-
(servicesOptional[dict[str, dict[str, dict[str, str]]]]) –The metadata of the services included in the artifact. The structure of this metadata is: { serviceName: { image: { ref: str, hash: str } } }
Methods:
-
from_dict–Construct an ArtifactMetadata object directly from a dict.
-
from_file–Construct an ArtifactMetadata object directly from a file.
-
to_dict–Dump the contents of the artifact metadata as a dict.
-
to_file–Dump the contents of the artifact metadata to a file, as JSON structured as the to_dict return value.
Source code in src/mender_docker_lifecycle_helper/artifact_metadata.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
from_dict
classmethod
from_dict(data: dict[str, dict[str, dict[str, dict[str, str]]]])
Construct an ArtifactMetadata object directly from a dict.
Parameters:
-
(datadict[str, dict[str, dict[str, dict[str, str]]]]) –The metadata for the artifact, structured as the to_dict return value.
Returns:
-
–
An object constructed from the provided data.
Source code in src/mender_docker_lifecycle_helper/artifact_metadata.py
28 29 30 31 32 33 34 35 36 | |
from_file
classmethod
from_file(file_path: Path)
Construct an ArtifactMetadata object directly from a file.
Parameters:
-
(file_pathPath) –The path to a JSON file containing the artifact metadata, structured as the to_dict return value.
Returns:
-
–
An object constructed from the provided file.
Source code in src/mender_docker_lifecycle_helper/artifact_metadata.py
38 39 40 41 42 43 44 45 46 47 48 | |
to_dict
to_dict()
Dump the contents of the artifact metadata as a dict.
Returns:
-
–
The metadata of the artifact, structured as: { version: str, services: { ... (see services param in init) } }
Source code in src/mender_docker_lifecycle_helper/artifact_metadata.py
50 51 52 53 54 55 56 57 58 59 60 61 62 | |
to_file
to_file(file_path: Path)
Dump the contents of the artifact metadata to a file, as JSON structured as the to_dict return value.
Parameters:
-
(file_pathPath) –The path to which to dump the metadata of the artifact.
Returns:
-
–
None
Source code in src/mender_docker_lifecycle_helper/artifact_metadata.py
64 65 66 67 68 69 70 71 72 73 | |
mender_docker_lifecycle_helper.cli
Functions:
-
cli–Produce and deploy a Mender artifact for the MANIFEST_FILE (compose yaml) Docker application, as deltas against local cache when available or repo version context otherwise.
cli
cli(**args) -> None
Produce and deploy a Mender artifact for the MANIFEST_FILE (compose yaml) Docker application, as deltas against local cache when available or repo version context otherwise.
Parameters:
-
–argsAn object of CLI args for the execution as prepared by Click decorators.
Returns:
-
None–None
Source code in src/mender_docker_lifecycle_helper/cli.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
mender_docker_lifecycle_helper.context
Classes:
-
LifecycleHelperContext–Representation of the context in which the helper is operating, including the args, input file, and available container images.
LifecycleHelperContext
LifecycleHelperContext(args: SimpleNamespace)
Representation of the context in which the helper is operating, including the args, input file, and available container images.
Construct a LifecycleHelperContext object.
Parameters:
-
(argsSimpleNamespace) –An object of the args for the helper execution. See cli.py.
Methods:
-
match_or_find_hash–If the provided image ref matches that in the previous artifact metadata for the given service, return the corresponding hash from the previous artifact metadata. Otherwise, attempt to retrieve the image hash for the provided image ref.
Source code in src/mender_docker_lifecycle_helper/context.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
_artifact_services_metadata_from_compose
_artifact_services_metadata_from_compose(compose_file: Path) -> dict[str, dict[str, dict[str, str]]]
Extract the services metadata from an artifact compose manifest file.
Parameters:
-
(compose_filePath) –The path to the compose manifest file from which to extract metadata.
Returns:
-
dict[str, dict[str, dict[str, str]]]–The metadata of the services expressed in the compose manifest file, in the following format: { serviceName: { image: { ref: str, hash: str } } }
Source code in src/mender_docker_lifecycle_helper/context.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
_default_cache_dir
staticmethod
_default_cache_dir(cache_dir_env_key: str = 'MENDER_HELPER_CACHE_DIR', default_cache_dir_name: str = 'mender-docker-lifecycle-helper') -> Path
Determine the path use for the default helper cache dir based on the values of relevant env vars.
Parameters:
-
(cache_dir_env_keystr, default:'MENDER_HELPER_CACHE_DIR') –The env var from which to read the user-specified helper cache dir, if defined, defaults to "MENDER_HELPER_CACHE_DIR"
-
(default_cache_dir_namestr, default:'mender-docker-lifecycle-helper') –The dir name of the helper cache within general cache dir, defaults to "mender-docker-lifecycle-helper"
Returns:
-
Path–The path to the default helper cache dir.
Source code in src/mender_docker_lifecycle_helper/context.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
_prep_cache_dir
_prep_cache_dir(cache_dir: Path) -> Path
Prepare the cache directory for the helper execution, creating if necessary.
Parameters:
-
(cache_dirPath) –The directory of the cache dir to use or create.
Returns:
-
Path–The path to the created or already existing cache dir.
Source code in src/mender_docker_lifecycle_helper/context.py
156 157 158 159 160 161 162 163 164 165 166 167 168 | |
_prep_logger
staticmethod
_prep_logger(log_level: str) -> Logger
Prepare a logger object for the helper execution at the specified level.
Parameters:
-
(log_levelstr) –The log level for the logger; must be a string matching a logging level attribute, e.g. "INFO".
Returns:
-
Logger–A logger object.
Source code in src/mender_docker_lifecycle_helper/context.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
_prep_previous_artifact_metadata
_prep_previous_artifact_metadata(previous_version: Optional[str]) -> ArtifactMetadata
Determine the metadata of the previous artifact. If the cache is enabled and includes a metadata file from a previous helper execution, that data is used. If a previous version is specified, the metadata is extracted from the artifact compose manifest file at that version of the repository. If the execution is for a release, the metadata is extracted from the artifact compose manifest file at the previous (mainline) commit of the repo. Otherwise, the metadata is extracted from the artifact compose manifest file at the version of the repository as specified by the current repo version (as read from the version file).
Parameters:
-
(previous_versionOptional[str]) –If provided, the version of the helper execution repository from which to read the previous artifact metadata.
Returns:
-
ArtifactMetadata–The metadata of the previous artifact, in the format as returned by _artifact_services_metadata_from_compose.
Raises:
-
FileNotFoundError–If the manifest file does not exist.
Source code in src/mender_docker_lifecycle_helper/context.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
_repo_root_dir
staticmethod
_repo_root_dir(path: Path) -> Path
Find the root directory of the Git repo containing the specified path.
Parameters:
-
(pathPath) –The path for which to find the containing repo.
Returns:
-
Path–The path to the containing Git repo.
Raises:
-
FileNotFoundError–If the repository root directory cannot be found.
Source code in src/mender_docker_lifecycle_helper/context.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
_repo_version
staticmethod
_repo_version(repo_dir: Path) -> str
Find the version of the specified repo per its version file.
Parameters:
-
(repo_dirPath) –The path to the repository directory in which to find the version file.
Returns:
-
str–The version as specified in the version file.
Source code in src/mender_docker_lifecycle_helper/context.py
144 145 146 147 148 149 150 151 152 153 154 | |
_temp_repo_at_version
_temp_repo_at_version(version: str) -> Path
Prepare a temporary clone of the helper execution repo at the specified version.
Parameters:
-
(versionstr) –The version at which to clone the repo.
Returns:
-
Path–The path to the temporary clone of the repo.
Raises:
-
Exception–If the repository clone or checkout fails.
Source code in src/mender_docker_lifecycle_helper/context.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
match_or_find_hash
match_or_find_hash(service_name: str, image_ref: str) -> str
If the provided image ref matches that in the previous artifact metadata for the given service, return the corresponding hash from the previous artifact metadata. Otherwise, attempt to retrieve the image hash for the provided image ref.
Parameters:
-
(service_namestr) –The name of the service for which to look for a matching image ref.
-
(image_refstr) –The ref of the image for which to look for a match.
Returns:
-
str–The hash of the image with the provided ref.
Source code in src/mender_docker_lifecycle_helper/context.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
mender_docker_lifecycle_helper.helper
Classes:
-
LifecycleHelper–Representation of the lifecycle helper execution.
LifecycleHelper
LifecycleHelper(args: SimpleNamespace)
Representation of the lifecycle helper execution.
Construct a LifecycleHelper object.
Parameters:
-
(argsSimpleNamespace) –An object of the args for the helper execution. See cli.py.
Methods:
-
create_artifact–Generate the Mender artifact for the specified metadata.
-
deploy_artifact–Issue a deployment of a pre-uploaded artifact.
-
prep_artifact–Prepare the artifact, including creation, upload, and deployment as specified by provided args.
-
upload_artifact–Upload the specified artifact file to the Mender server.
Source code in src/mender_docker_lifecycle_helper/helper.py
18 19 20 21 22 23 24 | |
create_artifact
create_artifact(artifact_metadata: ArtifactMetadata) -> LifecycleHelperArtifact
Generate the Mender artifact for the specified metadata.
Parameters:
-
(artifact_metadataArtifactMetadata) –The metadata for the artifact to generate.
Returns:
-
LifecycleHelperArtifact–The object representing the generated artifact.
Source code in src/mender_docker_lifecycle_helper/helper.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
deploy_artifact
deploy_artifact(artifact: LifecycleHelperArtifact) -> None
Issue a deployment of a pre-uploaded artifact.
Parameters:
-
(artifactLifecycleHelperArtifact) –The object of the artifact to deploy to the Mender server.
Returns:
-
None–None
Source code in src/mender_docker_lifecycle_helper/helper.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
prep_artifact
prep_artifact() -> None
Prepare the artifact, including creation, upload, and deployment as specified by provided args.
Returns:
-
None–None
Source code in src/mender_docker_lifecycle_helper/helper.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
upload_artifact
upload_artifact(artifact: LifecycleHelperArtifact) -> None
Upload the specified artifact file to the Mender server.
Parameters:
-
(artifactLifecycleHelperArtifact) –The object of the artifact to upload to the Mender server.
Returns:
-
None–None
Source code in src/mender_docker_lifecycle_helper/helper.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
mender_docker_lifecycle_helper.utils.container_utils
Functions:
-
get_image_hash–Read the image hash for a given image reference from a remote registry, or, if unavailable, from the local image store.
-
save_image_to_file–Saves the specified container image to the specified file.
-
save_local_image_to_file–Saves the specified container image from the local image store to the specified file.
-
save_registry_image_to_file–Saves the specified container image from a registry to the specified file.
_image_ref_hash_or_tag
_image_ref_hash_or_tag(image_registry: str, image_tag: str, image_hash: str) -> str
Reconstructs an image ref using only the hash (no tag) if provided, or the tag ref otherwise.
Parameters:
-
(image_registrystr) –The registry portion of image ref.
-
(image_tagstr) –The tag portion of image ref.
-
(image_hashstr) –The hash portion of image ref.
Returns:
-
str–The reconstructed image ref.
Source code in src/mender_docker_lifecycle_helper/utils/container_utils.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
_split_image_ref
_split_image_ref(image_ref: str) -> tuple[str, str, str]
Split an image ref into its component parts, if present.
Parameters:
-
(image_refstr) –The image ref to split.
Returns:
-
tuple[str, str, str]–A tuple of the image registry, tag, and hash, or None if not specified.
Source code in src/mender_docker_lifecycle_helper/utils/container_utils.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
get_image_hash
Read the image hash for a given image reference from a remote registry, or, if unavailable, from the local image store.
Parameters:
-
(image_refstr) –The image ref for which to get the hash.
-
(loggerLogger) –The logger object to which to report.
Returns:
-
str–The hash of the image.
Raises:
-
ValueError–If the image hash cannot be retrieved.
Source code in src/mender_docker_lifecycle_helper/utils/container_utils.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
save_image_to_file
Saves the specified container image to the specified file.
Parameters:
-
(imagedict[str, str]) –The metadata (as {ref: , hash:
}) of the image to save. -
(filePath) –The path of the file to which to save the image.
Returns:
-
CompletedProcess–The completed process from the subprocess call.
Raises:
-
ImageRefHashMismatchException–If the metadata ref contains a hash that does not match the provided metadata hash.
-
ImageNotFoundException–If the image cannot be found.
Source code in src/mender_docker_lifecycle_helper/utils/container_utils.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
save_local_image_to_file
save_local_image_to_file(image_hash: str, file: Path) -> CompletedProcess
Saves the specified container image from the local image store to the specified file.
Parameters:
-
(image_hashstr) –The hash of the image to save.
-
(filePath) –The path of the file to which to save the image.
Returns:
-
CompletedProcess–The completed process from the subprocess call.
Raises:
-
ImageNotFoundException–If the save operation cannot find the image.
Source code in src/mender_docker_lifecycle_helper/utils/container_utils.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
save_registry_image_to_file
Saves the specified container image from a registry to the specified file.
Parameters:
-
(image_refstr) –The ref of the image to save.
-
(filePath) –The path of the file to which to save the image.
Returns:
-
CompletedProcess–The completed process from the subprocess call.
Raises:
-
ImageNotFoundException–If the save operation cannot find the image.
Source code in src/mender_docker_lifecycle_helper/utils/container_utils.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
mender_docker_lifecycle_helper.utils.deep_delta
Functions:
-
oci_deep_delta–Generate deep delta between OCI images.
_read_layers_from_manifest
_read_layers_from_manifest(image_dir: Path, target_platform: str, logger: Optional[Logger] = getLogger(__name__)) -> list[Path]
Reads the layers from an OCI image manifest file.
Parameters:
-
(image_dirPath) –The directory in which the image is extracted.
-
(target_platformstr) –The platform to target, if the image contains multiple, as os/[architecture]/[variant].
-
(loggerOptional[Logger], default:getLogger(__name__)) –A logger with which to log steps of function processes, defaults to logging.getLogger(name).
Returns:
-
list[Path]–The list of paths to the layers referenced by the image manifest.
Source code in src/mender_docker_lifecycle_helper/utils/deep_delta.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
oci_deep_delta
oci_deep_delta(from_dir: Path, to_dir: Path, delta_dir: Path, delta_filename: str, target_platform: str, delta_cmd: Optional[list[str]] = XDELTA_CMD, logger: Optional[Logger] = getLogger(__name__)) -> Path
Generate deep delta between OCI images.
Writes .vcdiff and .source files into delta_dir based on the layer files in to_dir and from_dir, bundled into a tar file.
Parameters:
-
(from_dirPath) –The path to the extracted current image.
-
(to_dirPath) –The path to the extracted new image.
-
(delta_dirPath) –The path under which to create the delta layers.
-
(delta_filenamestr) –The name of the delta image archive file to create.
-
(delta_cmdOptional[list[str]], default:XDELTA_CMD) –The command to use for layer delta generation, defaults to XDELTA_CMD.
-
(target_platformstr) –The platform to target, if the image contains multiple, as os/[architecture]/[variant].
-
(loggerOptional[Logger], default:getLogger(__name__)) –A logger with which to log steps of function processes, defaults to logging.getLogger(name).
Returns:
-
Path–The image delta file.
Raises:
-
ImageDeltaException–If images contain different numbers of layers.
Source code in src/mender_docker_lifecycle_helper/utils/deep_delta.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
mender_docker_lifecycle_helper.utils.image_cache
Classes:
-
ImageCache–Represents a cache of container images archive files, extractions of those archives, and files of the computed deltas between images. Images are referenced in the cache by manifest hash (and from/to hashes for deltas), and can be specified inclusion in the cache by image ref and hash, or by OCI image filename.
ImageCache
ImageCache(cache_dir: Path, delta_cache_dirname: Optional[str] = DELTA_CACHE_DIRNAME, extract_cache_dirname: Optional[str] = EXTRACT_CACHE_DIRNAME, image_file_name: Optional[str] = IMAGE_FILE_NAME, save_cache_dirname: Optional[str] = SAVE_CACHE_DIRNAME, logger: Optional[Logger] = getLogger(__name__))
Represents a cache of container images archive files, extractions of those archives, and files of the computed deltas between images. Images are referenced in the cache by manifest hash (and from/to hashes for deltas), and can be specified inclusion in the cache by image ref and hash, or by OCI image filename.
Construct an ImageCache object, reading cache dir contents into maps if present or creating them as empty dirs.
Parameters:
-
(cache_dirPath) –The top-level directory of the image cache.
-
(delta_cache_dirnameOptional[str], default:DELTA_CACHE_DIRNAME) –The name of the subdirectory for image deltas, defaults to DELTA_CACHE_DIRNAME.
-
(extract_cache_dirnameOptional[str], default:EXTRACT_CACHE_DIRNAME) –The name of the subdirectory for image extracts, defaults to EXTRACT_CACHE_DIRNAME.
-
(image_file_nameOptional[str], default:IMAGE_FILE_NAME) –The filename to use for image save files, defaults to IMAGE_FILE_NAME.
-
(save_cache_dirnameOptional[str], default:SAVE_CACHE_DIRNAME) –The name of the subdirectory for image saves, defaults to SAVE_CACHE_DIRNAME.
-
(loggerOptional[Logger], default:getLogger(__name__)) –A logger with which to log steps of cache processes, defaults to logging.getLogger(name).
Methods:
-
delta–Get the delta file path for a given from and to image hash, creating folders if required.
-
extract_cache_file–Extract image from a specified file to the cache and read and return the image metadata.
-
extract_cache_image–Extract an image with the given hash in the cache and return the path to the extracted image dir. If the image is not yet in the image save cache, it will be added there first.
-
save_cache_image–Save an image with the given ref and hash to the save cache, if not already present.
Source code in src/mender_docker_lifecycle_helper/utils/image_cache.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
_extract_oci_file
_extract_oci_file(extract_dir: Path, extract_file: Path) -> None
Extract specified OCI image file into specified directory, and ensure OCI-compliant layout.
Parameters:
-
(extract_dirPath) –The path into which to extract the OCI file.
-
(extract_filePath) –The OCI file to extract.
Returns:
-
None–None
Raises:
-
ImageDirFormatException–Indicates that the specified image file is not in the correct format.
Source code in src/mender_docker_lifecycle_helper/utils/image_cache.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
delta
delta(from_image: dict[str, str], to_image: dict[str, str], target_platform: str) -> Path
Get the delta file path for a given from and to image hash, creating folders if required.
Parameters:
-
(from_imagedict[str, str]) –The metadata (specifically {ref: , hash:
}) of the image from which the delta is defined. -
(to_imagedict[str, str]) –The metadata (specifically {ref: , hash:
}) of the image to which the delta is defined. -
(target_platformstr) –The platform to target, if the image contains multiple, as os/[architecture]/[variant].
Returns:
-
Path–The path to the delta file for the given from and to image hash.
Source code in src/mender_docker_lifecycle_helper/utils/image_cache.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
extract_cache_file
extract_cache_file(extract_file: Path) -> dict[str, str]
Extract image from a specified file to the cache and read and return the image metadata.
Parameters:
-
(extract_filePath) –The path to the OCI image archive file to extract into the cache space.
Returns:
-
dict[str, str]–The image specification (as {ref: , hash:
}) as read from the file.
Raises:
-
ImageDirFormatException–Indicates that the specified image file is not in the correct format.
Source code in src/mender_docker_lifecycle_helper/utils/image_cache.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
extract_cache_image
extract_cache_image(image: dict[str, str]) -> Path
Extract an image with the given hash in the cache and return the path to the extracted image dir. If the image is not yet in the image save cache, it will be added there first.
Parameters:
-
(imagedict[str, str]) –The metadata (specifically {ref: , hash:
}) of the image to extract.
Returns:
-
Path–The path to the extracted image directory.
Source code in src/mender_docker_lifecycle_helper/utils/image_cache.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
save_cache_image
save_cache_image(image: dict[str, str]) -> Path
Save an image with the given ref and hash to the save cache, if not already present.
Parameters:
-
(imagedict[str, str]) –The metadata (specifically {ref: , hash:
}) of the image to save.
Returns:
-
Path–The path to the image file in the save cache.
Source code in src/mender_docker_lifecycle_helper/utils/image_cache.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
mender_docker_lifecycle_helper.utils.mender_server
Functions:
-
call_mender_host_api–Calls the Mender server API at the specified endpoint with provided args.
call_mender_host_api
call_mender_host_api(context: LifecycleHelperContext, mender_endpoint: str, request_args: dict) -> Response
Calls the Mender server API at the specified endpoint with provided args.
Parameters:
-
(contextLifecycleHelperContext) –The context of the lifecycle helper execution.
-
(mender_endpointstr) –The endpoint of the Mender server to call.
-
(request_argsdict) –The args to provide to the API call.
Returns:
-
Response–The request response object or None.
Raises:
-
HTTPError–If the API call fails.
Source code in src/mender_docker_lifecycle_helper/utils/mender_server.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |