broad-processor-92400
11/16/2022, 12:39 AMabc/def/ghi:target-name
then dep inference will know that COPY abc.def.ghi/target-name.pex ...
in the docker instructions refers to it... but how can a macro automatically compute the output path? (particularly the abc.def.ghi
part) One option would be to set output_path
to have it fixed, but that risks collisions when the macro is used multiple times.
(Sketch of the macro in the ๐งต )broad-processor-92400
11/16/2022, 12:40 AMdef docker_image_from_pex(*, name, pex_entry_point):
deps = pex_binary(
name=f"_{name}-deps",
entry_point=pex_entry_point,
complete_platforms=COMPLETE_PLATFORMS,
include_sources=False,
include_requirements=True,
include_tools=True,
layout="packed",
)
srcs = pex_binary(
name=f"_{name}-srcs",
entry_point=pex_entry_point,
complete_platforms=COMPLETE_PLATFORMS,
include_sources=True,
include_requirements=False,
include_tools=True,
layout="packed",
)
# QUESTION: what's the generic form of this?
output_directory = "abc.def.ghi" # when used in abc/def/ghi... but what if it's used in other/directory too!?
docker_image(
name=name,
instructions=[
# unpack the external dependencies
f"FROM {BASE_IMAGE} AS deps",
f"COPY {output_directory}/{deps.name}.pex /deps.pex",
"RUN PEX_TOOLS=1 PEX_VERBOSE=2 python /deps.pex venv --scope=deps --compile /opt/venv",
# unpack our code
f"FROM {BASE_IMAGE} AS srcs",
f"COPY {output_directory}/{srcs.name}.pex /srcs.pex",
"RUN PEX_TOOLS=1 PEX_VERBOSE=2 python /srcs.pex venv --scope=srcs --compile /opt/venv",
# set up the actual app
f"FROM {BASE_IMAGE} AS app",
# ...
"COPY --from=deps /opt/venv /opt/venv",
"COPY --from=srcs /opt/venv /opt/venv",
# ...
],
)
broad-processor-92400
11/16/2022, 12:49 AMf"COPY {deps.get_me_the_resolved_output_path()} /deps.pex
and thus be totally agnostic to where the pex_binary
target decides to put its output, but I cannot find if that's possiblebitter-ability-32190
11/16/2022, 1:38 AMbuild_file_dir()
.
It's a pathlib.PurePath
to the directory containing the BUILD
filebitter-ability-32190
11/16/2022, 1:38 AMf"COPY {'.'.join(build_file_dir().parts) + '/' + name + '-deps-PEX.pex'} /bin/app.pex",
is what ours looks likebroad-processor-92400
11/16/2022, 1:42 AMoutput_directory = '.'.join(build_file_dir().parts)
makes the macro work well. How deep into unstable territory am I going by using that?bitter-ability-32190
11/16/2022, 1:44 AMobjects
(what this is)bitter-ability-32190
11/16/2022, 1:44 AMbroad-processor-92400
11/16/2022, 1:44 AMrefined-addition-53644
11/16/2022, 7:43 AMnutritious-hair-72580
10/25/2024, 3:33 AM