Source code for gyoza.worker.execution_pipeline.steps.pull_latest_image

"""Pull latest image step - ensures the latest version of the image is available."""

import docker
from gyoza.worker.execution_pipeline.types import ExecutionContext


[docs] def pull_latest_image(ctx: ExecutionContext) -> ExecutionContext: """Pull the latest version of the Docker image before execution. Parameters ---------- ctx : ExecutionContext Execution context with image name configured. Returns ------- ExecutionContext Context with ``image_digest`` set to what was actually pulled. """ client = docker.from_env() image = client.images.pull(ctx.image) # The tag alone does not say which build ran; the digest does. Reporting # it is best-effort and never fails the run. try: ctx.image_digest = (image.attrs.get("RepoDigests") or [image.id])[0] except Exception: # noqa: BLE001 ctx.image_digest = None return ctx