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
309 310 311 312 313 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 | |
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:
-
ManifestContentException–If service name in args not found in manifest.
Source code in src/mender_docker_lifecycle_helper/artifact.py
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 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | |
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
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 | |
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 | |
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
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 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 196 197 198 199 200 201 202 203 204 205 | |
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
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 232 233 234 235 236 237 238 239 240 241 242 | |
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
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 | |
mender_docker_lifecycle_helper.artifact_metadata
Classes:
ArtifactMetadata
Construct an ArtifactMetadata object.
Parameters:
-
(versionstr) –The version identifier for the artifact.
-
(servicesdict[str, dict[str, dict[str, str]]] | None) –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
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
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
27 28 29 30 31 32 33 34 35 | |
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
37 38 39 40 41 42 43 44 45 46 47 | |
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
49 50 51 52 53 54 55 56 57 58 59 60 61 | |
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
63 64 65 66 67 68 69 70 71 72 | |
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.
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 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 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
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:
-
clean_cache–Clean the image cache based on size or disk percent limits.
-
clear_cache–Remove the entire cache directory.
-
clear_image_cache–Remove the image cache contents (save, extract, delta).
-
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
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 | |
_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
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 | |
_compose_content_from_file
_compose_content_from_file(compose_file: Path) -> dict
Read the contents of a Compose YAML file using all expansions per the spec.
Parameters:
-
(compose_filePath) –The path to the Compose YAML file to read.
Returns:
-
dict–The normalized compose content as a dict with all directives resolved.
Raises:
-
RuntimeError–If docker compose config fails.
-
yaml.YAMLError–If the output cannot be parsed as YAML.
Source code in src/mender_docker_lifecycle_helper/context.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
_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
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
_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
209 210 211 212 213 214 215 216 217 218 219 220 221 | |
_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
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
_prep_previous_artifact_metadata
_prep_previous_artifact_metadata(previous_version: str | None) -> 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_versionstr | None) –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
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 390 391 392 393 394 395 396 397 | |
_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
182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
_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
197 198 199 200 201 202 203 204 205 206 207 | |
_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
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 285 286 287 288 | |
clean_cache
clean_cache(limit_size_bytes: int | None, disk_percent: float | None) -> int
Clean the image cache based on size or disk percent limits.
Parameters:
-
(limit_size_bytesint | None) –Maximum cache size in bytes.
-
(disk_percentfloat | None) –Minimum percent of total disk that should remain free.
Returns:
-
int–Number of bytes freed.
Source code in src/mender_docker_lifecycle_helper/context.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
clear_cache
clear_cache() -> None
Remove the entire cache directory.
Raises:
-
FileNotFoundError–If the cache directory does not exist.
Source code in src/mender_docker_lifecycle_helper/context.py
246 247 248 249 250 251 252 253 254 255 | |
clear_image_cache
clear_image_cache() -> None
Remove the image cache contents (save, extract, delta).
Raises:
-
FileNotFoundError–If the image cache does not exist.
Source code in src/mender_docker_lifecycle_helper/context.py
238 239 240 241 242 243 244 | |
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
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
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.
-
update_cache_artifact_metadata–Write the specified artifact metadata to the cache previous metadata location, if applicable.
Source code in src/mender_docker_lifecycle_helper/helper.py
29 30 31 32 33 34 35 | |
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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
deploy_artifact
deploy_artifact(artifact: LifecycleHelperArtifact) -> str
Issue a deployment of a pre-uploaded artifact.
Parameters:
-
(artifactLifecycleHelperArtifact) –The object of the artifact to deploy to the Mender server.
Returns:
-
str–The deployment ID.
Source code in src/mender_docker_lifecycle_helper/helper.py
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 | |
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
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 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 | |
update_cache_artifact_metadata
update_cache_artifact_metadata(artifact_metadata: ArtifactMetadata) -> None
Write the specified artifact metadata to the cache previous metadata location, if applicable.
Parameters:
-
(artifact_metadataArtifactMetadata) –The artifact metadata object to write to the cache.
Source code in src/mender_docker_lifecycle_helper/helper.py
102 103 104 105 106 107 108 109 110 111 112 113 114 | |
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
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
_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
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 | |
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
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 | |
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.
-
(platformstr, default:None) –The platform for which to save the image, as os/arch[/variant].
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
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 | |
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
200 201 202 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 232 233 234 235 236 237 238 239 240 | |
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.
-
(platformstr, default:None) –The platform for which to save the image, as os/arch[/variant].
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
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 196 197 | |
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: Logger | None = 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].
-
(loggerLogger | None, 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
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 | |
oci_deep_delta
oci_deep_delta(from_dir: Path, to_dir: Path, delta_dir: Path, delta_filename: str, target_platform: str, delta_cmd: list[str] | None = XDELTA_CMD, logger: Logger | None = 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_cmdlist[str] | None, 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].
-
(loggerLogger | None, 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
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 168 169 170 171 172 173 174 175 176 177 | |
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 for inclusion in the cache by image ref and hash, or by OCI image filename.
-
ImageDirFormatException–Raised when an OCI image directory is not in the expected format.
ImageCache
ImageCache(cache_dir: Path, platform: str | None = None, delta_cache_dirname: str | None = DELTA_CACHE_DIRNAME, extract_cache_dirname: str | None = EXTRACT_CACHE_DIRNAME, image_file_name: str | None = IMAGE_FILE_NAME, save_cache_dirname: str | None = SAVE_CACHE_DIRNAME, logger: Logger | None = 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 for 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.
-
(platformstr | None, default:None) –The platform for which to save images, as os/arch[/variant].
-
(delta_cache_dirnamestr | None, default:DELTA_CACHE_DIRNAME) –The name of the subdirectory for image deltas, defaults to DELTA_CACHE_DIRNAME.
-
(extract_cache_dirnamestr | None, default:EXTRACT_CACHE_DIRNAME) –The name of the subdirectory for image extracts, defaults to EXTRACT_CACHE_DIRNAME.
-
(image_file_namestr | None, default:IMAGE_FILE_NAME) –The filename to use for image save files, defaults to IMAGE_FILE_NAME.
-
(save_cache_dirnamestr | None, default:SAVE_CACHE_DIRNAME) –The name of the subdirectory for image saves, defaults to SAVE_CACHE_DIRNAME.
-
(loggerLogger | None, default:getLogger(__name__)) –A logger with which to log steps of cache processes, defaults to logging.getLogger(name).
Methods:
-
cleanup_by_mtime–Remove oldest cached items to bring cache size at or below limit.
-
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
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 | |
_calculate_space_to_free_for_percent
_calculate_space_to_free_for_percent(disk_percent: float, current_cache_size: int) -> int
Calculate how much space needs to be freed to meet the disk percent threshold.
Parameters:
-
(disk_percentfloat) –Minimum percent of total disk that should remain free.
-
(current_cache_sizeint) –Current cache size in bytes.
Returns:
-
int–Bytes to free, or 0 if no cleanup needed or cache is already within limits.
Source code in src/mender_docker_lifecycle_helper/utils/image_cache.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
_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
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
_get_cache_items_by_mtime
_get_cache_items_by_mtime() -> list[tuple[Path, float, int]]
Get all cache items ordered by modification time.
Returns:
-
list[tuple[Path, float, int]]–List of (path, mtime, size) tuples. Items are always directories: save/
, extract/ , delta/ / .
Source code in src/mender_docker_lifecycle_helper/utils/image_cache.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | |
_get_cache_size
_get_cache_size() -> int
Calculate total size of the images cache directory.
Returns:
-
int–Total size in bytes.
Source code in src/mender_docker_lifecycle_helper/utils/image_cache.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
_get_dir_size
_get_dir_size(path: Path) -> int
Recursively calculate total size of directory.
Parameters:
-
(pathPath) –The directory path to calculate size for.
Returns:
-
int–Total size in bytes.
Source code in src/mender_docker_lifecycle_helper/utils/image_cache.py
398 399 400 401 402 403 404 405 | |
_get_disk_stats
_get_disk_stats() -> dict
Get disk usage stats for the filesystem containing the cache.
Returns:
-
dict–Dictionary with 'total' and 'free' keys in bytes.
Source code in src/mender_docker_lifecycle_helper/utils/image_cache.py
335 336 337 338 339 340 341 342 343 344 345 | |
_sync_cache_dicts_on_cleanup
_sync_cache_dicts_on_cleanup() -> None
Remove entries from in-memory cache dicts after cleanup removes those dirs.
Returns:
-
None–None.
Source code in src/mender_docker_lifecycle_helper/utils/image_cache.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | |
cleanup_by_mtime
cleanup_by_mtime(limit_size_bytes: int | None = None, disk_percent: float | None = None) -> int
Remove oldest cached items to bring cache size at or below limit.
Only folder items (save/
Parameters:
-
(limit_size_bytesint | None, default:None) –Maximum cache size in bytes. If None with disk_percent, no cleanup occurs.
-
(disk_percentfloat | None, default:None) –If set, calculate free space needed as percent of total disk.
Returns:
-
int–Total bytes freed by cleanup.
Source code in src/mender_docker_lifecycle_helper/utils/image_cache.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 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 313 314 315 316 | |
delta
delta(from_image: dict[str, str], to_image: dict[str, 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.
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
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 | |
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
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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
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
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
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
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 | |
ImageDirFormatException
flowchart TD
mender_docker_lifecycle_helper.utils.image_cache.ImageDirFormatException[ImageDirFormatException]
click mender_docker_lifecycle_helper.utils.image_cache.ImageDirFormatException href "" "mender_docker_lifecycle_helper.utils.image_cache.ImageDirFormatException"
Raised when an OCI image directory is not in the expected format.
mender_docker_lifecycle_helper.utils.mender_server
Functions:
-
call_mender_host_api–Calls the Mender server API at the specified endpoint with provided args.
-
get_deployment_status–Get the status of a deployment from the Mender server.
-
upload_artifact–Upload the specified artifact file to the Mender server with retry logic.
-
wait_for_deployment–Watch a deployment until completion, success, or timeout.
call_mender_host_api
call_mender_host_api(context: LifecycleHelperContext, mender_endpoint: str, request_args: dict, max_retries: int = 0, base_delay: int = 5) -> 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.
-
(max_retriesint, default:0) –Maximum number of retries for server errors (5xx). Default 0 (no retries).
-
(base_delayint, default:5) –Base delay in seconds between retries. Default 5.
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
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
get_deployment_status
get_deployment_status(context: LifecycleHelperContext, deployment_id: str) -> dict
Get the status of a deployment from the Mender server.
Parameters:
-
(contextLifecycleHelperContext) –The context of the lifecycle helper execution.
-
(deployment_idstr) –The ID of the deployment to check.
Returns:
-
dict–The deployment statistics as a dict, or None if the request fails.
Source code in src/mender_docker_lifecycle_helper/utils/mender_server.py
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 | |
upload_artifact
upload_artifact(context: LifecycleHelperContext, artifact: LifecycleHelperArtifact, max_retries: int = 3, base_delay: int = 5) -> None
Upload the specified artifact file to the Mender server with retry logic.
Parameters:
-
(contextLifecycleHelperContext) –The context of the lifecycle helper execution.
-
(artifactLifecycleHelperArtifact) –The object of the artifact to upload to the Mender server.
-
(max_retriesint, default:3) –The maximum number of times to retry uploading the artifact in the case of failure.
-
(base_delayint, default:5) –The number of seconds to wait between upload retries.
Returns:
-
None–None
Source code in src/mender_docker_lifecycle_helper/utils/mender_server.py
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 | |
wait_for_deployment
wait_for_deployment(context: LifecycleHelperContext, deployment_id: str, poll_interval: int = 30, timeout: int = 3600) -> bool
Watch a deployment until completion, success, or timeout.
Returns True if the deployment succeeded (all devices reported success), False otherwise.
Parameters:
-
(contextLifecycleHelperContext) –The context of the lifecycle helper execution.
-
(deployment_idstr) –The ID of the deployment to watch.
-
(poll_intervalint, default:30) –Seconds between status checks (default: 30).
-
(timeoutint, default:3600) –Maximum seconds to wait (default: 3600).
Returns:
-
bool–True if deployment succeeded, False otherwise.
Source code in src/mender_docker_lifecycle_helper/utils/mender_server.py
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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |