MCPcopy
hub / github.com/freedomofpress/dangerzone / load_image_tarball

Function load_image_tarball

dangerzone/container_utils.py:319–338  ·  view source on GitHub ↗

Load the image tarball, and return its digest.

(tarball_path: Path | None = None)

Source from the content-addressed store, hash-verified

317
318
319def load_image_tarball(tarball_path: Path | None = None) -> str:
320 """Load the image tarball, and return its digest."""
321 log.info("Installing Dangerzone container image...")
322 podman = init_podman_command()
323 if not tarball_path:
324 tarball_path = get_resource_path("container.tar")
325 try:
326 res = podman.run(["load", "-i", str(tarball_path)], capture_output=True)
327 assert isinstance(res, str)
328 # The stdout of the above command is usually 'Loaded image: sha256:<digest>'
329 # we can get the image digest by grabbing the last part of stdout.
330 return res.split()[-1]
331 except subprocess.CalledProcessError as e:
332 if e.stderr:
333 error = e.stderr.decode()
334 else:
335 error = "No output"
336 raise errors.ImageInstallationException(
337 f"Could not install container image: {error}"
338 )
339
340
341def tag_image_by_digest(digest: str, tag: str) -> None:

Callers

nothing calls this directly

Calls 3

init_podman_commandFunction · 0.85
get_resource_pathFunction · 0.85
runMethod · 0.45

Tested by

no test coverage detected