MCPcopy
hub / github.com/pex-tool/pex / build_cache_image

Function build_cache_image

scripts/build-cache-image.py:93–151  ·  view source on GitHub ↗
(
    test_cmds: Iterable[str],
    image_id: str | None,
    image_tag: str,
    pex_repo: str,
    git_ref: str,
    new: bool,
    seed_image: str | None,
)

Source from the content-addressed store, hash-verified

91
92
93def build_cache_image(
94 test_cmds: Iterable[str],
95 image_id: str | None,
96 image_tag: str,
97 pex_repo: str,
98 git_ref: str,
99 new: bool,
100 seed_image: str | None,
101) -> None:
102
103 pythons = "new" if new else "old"
104
105 seed_args: list[str] = []
106 if seed_image:
107 seed_args.append("--build-arg")
108 seed_args.append(f"SEED_IMAGE={seed_image}")
109 seed_args.append("--build-arg")
110 seed_args.append(f"SEED_PATH={_CACHE_PATH}")
111
112 context = Path(safe_mkdtemp()) / f"pex-duvrc-{pythons}-cache-context"
113 shutil.copytree(os.path.join("docker", "cache"), context)
114 shutil.copy(os.path.join("docker", "user", "create_docker_image_user.sh"), context)
115 with (context / ".env").open(mode="w") as fp:
116 for name, value in os.environ.items():
117 if name.startswith(("_PEX_", "SCIENCE_")) or name == "CI":
118 print(f"export {name}={value}", file=fp)
119
120 subprocess.run(
121 args=[
122 "docker",
123 "buildx",
124 "build",
125 "--build-arg",
126 f"PYTHONS={pythons}",
127 *seed_args,
128 "--build-arg",
129 f"USER={getpass.getuser()}",
130 "--build-arg",
131 f"UID={os.getuid()}",
132 "--build-arg",
133 f"GROUP={grp.getgrgid(os.getgid()).gr_name}",
134 "--build-arg",
135 f"GID={os.getgid()}",
136 "--build-arg",
137 f"CACHE_PATH={_CACHE_PATH}",
138 "--build-arg",
139 f"FINGERPRINT={fingerprint_cache_inputs(image_id=image_id)}",
140 "--build-arg",
141 f"PEX_REPO={pex_repo}",
142 "--build-arg",
143 f"GIT_REF={git_ref}",
144 "--build-arg",
145 f"TEST_CMDS={','.join(test_cmds)}",
146 "--tag",
147 image_tag,
148 str(context),
149 ],
150 check=True,

Callers 1

mainFunction · 0.85

Calls 7

safe_mkdtempFunction · 0.90
fingerprint_cache_inputsFunction · 0.85
appendMethod · 0.80
openMethod · 0.80
joinMethod · 0.45
copyMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected