Is there a way to easily propagate the output path...
# general
r
Is there a way to easily propagate the output path of a
pex_binary
target to the
extra_build_args
field of a
docker_image
target?
b
To avoid an x-y problem: Why do you want it in
extra_build_args
? To answer your question, unless you customise
output_directory
, we have a macro that does something like:
Copy code
target = pex_binary(name="...", ...)

output_directory = ".".join(build_file_dir().parts)
pex_path = f"{output_diretory}/{target.name}.pex"
and I imagine
pex_path
could be fed into
extra_build_args
.
r
I have a base docker image and I want to generate an image for each pex, but the instructions in the dockerfile are the same, only the pex is different
b
Ah okay. We do something similar via a macro'd
docker_image
with inline `instructions`: https://pantsbuild.slack.com/archives/C046T6T9U/p1668559231617069?thread_ts=1668559186.539269&cid=C046T6T9U That is, rather than have a fixed
Dockerfile
and pass args in, we just format the instructions appropriately. If that's not appropriate, I'm guessing adapting the
docker_image
to have something like
extra_build_args=[f"PACKAGED_PEX={pex_path}"], dependencies=[":{target.name}"]
would work (I think you'll need the explicit dependency on the PEX in that case, because I assume pants won't infer from
extra_build_args
, but it will infer if the appropriate string appears in the instructions)