(client, fh, image_path=None)
| 38 | |
| 39 | |
| 40 | def 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 | |
| 71 | def get_image( |
no test coverage detected