MCPcopy Index your code
hub / github.com/astral-sh/python-build-standalone / ensure_docker_image

Function ensure_docker_image

pythonbuild/docker.py:40–68  ·  view source on GitHub ↗
(client, fh, image_path=None)

Source from the content-addressed store, hash-verified

38
39
40def ensure_docker_image(client, fh, image_path=None):
41 res = client.api.build(fileobj=fh, decode=True)
42
43 image = None
44
45 for s in res:
46 if "stream" in s:
47 for l in s["stream"].strip().splitlines():
48 log(l)
49
50 if "aux" in s and "ID" in s["aux"]:
51 image = s["aux"]["ID"]
52
53 if "error" in s:
54 log(s["error"])
55
56 if not image:
57 raise Exception("unable to determine built Docker image")
58
59 if image_path:
60 tar_path = pathlib.Path(str(image_path) + ".tar")
61 with tar_path.open("wb") as fh:
62 for chunk in client.images.get(image).save():
63 fh.write(chunk)
64
65 with image_path.open("w") as fh:
66 fh.write(image + "\n")
67
68 return image
69
70
71def get_image(

Callers 1

build_docker_imageFunction · 0.85

Calls 1

logFunction · 0.90

Tested by

no test coverage detected