https://pantsbuild.org/ logo
#general
Title
# general
p

proud-appointment-36730

07/11/2022, 10:38 PM
My last question for the day: Do
docker_image
targets only support dependency inference on paths that "look like" the outputs of
pex_binary
targets? Or, can you directly put target addresses anywhere in the Dockerfile and have the dependency inference work? So if, for example I had a Dockerfile with:
Copy code
FROM path/to/my/parent/docker/image:target

RUN pip install path/to/a/python_distribution:target
Would pants infer the dependency on both the parent docker image and the python package automatically, and inject the output paths for those targets into the build context automatically? I'm digging through the source code now but I honestly can't really figure out if it supports anything beyond
FROM target_address
and
COPY output_path_that_can_be_mapped_to_a_target
h

happy-kitchen-89482

07/11/2022, 11:09 PM
Let me check
Looks like it's just FROM and COPY, as you thought.
But it would be straightforward to add inference on other commands, if it made sense to do so
Note that it's not just
pex_binary
targets you can infer deps on, but any target that is "packageable" (i.e., that
./pants package
applies to)
But now that I think of it, you'd have to COPY anything useful into the image before you could RUN it, no?
1
t

thousands-plumber-33255

07/12/2022, 7:41 AM
I did not know it infers
FROM
. Is that really true as I cannot find this to be documented? What about
COPY --from=parent-image
?
c

curved-television-6568

07/12/2022, 9:05 AM
It hasn’t found it’s way into the Docker section of the docs, but it is in the reference section for the
docker_image
target: https://www.pantsbuild.org/docs/reference-docker_image
It’s for the
FROM
instruction only, not for the
COPY --from
..
That wouldn’t be too difficult to add, though. PRs welcome if so inclined 😉
Also, I notice the docs still refer to inference for
pex_binary
targets only, but it is now any packageable target not just pex ones.
👍 1
p

proud-appointment-36730

07/12/2022, 2:21 PM
Great point about the
COPY
! And in the
FROM
lines, will it only infer dependencies if you embed a target address there? Or will it detect an image URI that's in one of the image registries set up in your config, then search your repo for other
docker_image
targets that package and publish an image to the registry and image tag in the
FROM
line and infer a dependency on the matching
docker_image
target automatically?
Ah, doesn't seem to work like that from some quick local testing. I'm still trying to get my head wrapped around the plugin API and the docker backend implementation, but from reading through the pants source code this doesn't seem like it would be too painful to add would it?
5 Views